system_hook_spec.rb 1.94 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1 2 3 4
# == Schema Information
#
# Table name: web_hooks
#
5
#  id         :integer          not null, primary key
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
6 7
#  url        :string(255)
#  project_id :integer
8 9 10
#  created_at :datetime         not null
#  updated_at :datetime         not null
#  type       :string(255)      default("ProjectHook")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
11
#  service_id :integer
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
12 13
#

Valeriy Sizov's avatar
Valeriy Sizov committed
14 15 16 17
require "spec_helper"

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

Valeriy Sizov's avatar
Valeriy Sizov committed
20
    before(:each) do
21
      @system_hook = create(:system_hook)
Valeriy Sizov's avatar
Valeriy Sizov committed
22 23 24 25 26
      WebMock.stub_request(:post, @system_hook.url)
    end

    it "project_create hook" do
      with_resque do
27
        project = create(:project)
Valeriy Sizov's avatar
Valeriy Sizov committed
28 29 30
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
    end
31

Valeriy Sizov's avatar
Valeriy Sizov committed
32
    it "project_destroy hook" do
33
      project = create(:project)
Valeriy Sizov's avatar
Valeriy Sizov committed
34 35 36 37 38 39 40 41
      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
42
        create(:user)
Valeriy Sizov's avatar
Valeriy Sizov committed
43 44 45
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
    end
46

Valeriy Sizov's avatar
Valeriy Sizov committed
47
    it "user_destroy hook" do
48
      user = create(:user)
Valeriy Sizov's avatar
Valeriy Sizov committed
49 50 51 52 53
      with_resque do
        user.destroy
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
    end
54

Valeriy Sizov's avatar
Valeriy Sizov committed
55
    it "project_create hook" do
56 57
      user = create(:user)
      project = create(:project)
Valeriy Sizov's avatar
Valeriy Sizov committed
58
      with_resque do
59
        project.add_access(user, :admin)
Valeriy Sizov's avatar
Valeriy Sizov committed
60 61 62
      end
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
    end
63

Valeriy Sizov's avatar
Valeriy Sizov committed
64
    it "project_destroy hook" do
65 66
      user = create(:user)
      project = create(:project)
67
      project.add_access(user, :admin)
Valeriy Sizov's avatar
Valeriy Sizov committed
68 69 70 71 72 73 74 75
      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