summaryrefslogtreecommitdiff
path: root/spec/models/system_hook_spec.rb
blob: 56d76ed08cf59d9f69190638a012dacbe08ee6c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require "spec_helper"

describe SystemHook do
  describe "execute" do
    before(:each) { ActiveRecord::Base.observers.enable(:all) }

    before(:each) do
      @system_hook = Factory :system_hook
      WebMock.stub_request(:post, @system_hook.url)
    end

    it "project_create hook" do
      user = Factory :user
      with_resque do
        project = Factory :project_without_owner, owner: user
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
    end
    
    it "project_destroy hook" do
      project = Factory :project
      with_resque do
        project.destroy
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
    end

    it "user_create hook" do
      with_resque do
        Factory :user
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
    end
    
    it "user_destroy hook" do
      user = Factory :user
      with_resque do
        user.destroy
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
    end
    
    it "project_create hook" do
      user = Factory :user
      project = Factory :project
      with_resque do
        project.users << user
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
    end
    
    it "project_destroy hook" do
      user = Factory :user
      project = Factory :project
      project.users << user
      with_resque do
        project.users_projects.clear
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
    end
  end

end