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

Valeriy Sizov's avatar
Valeriy Sizov committed
18 19 20 21
require "spec_helper"

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

Valeriy Sizov's avatar
Valeriy Sizov committed
24
    before(:each) do
25
      @system_hook = create(:system_hook)
Valeriy Sizov's avatar
Valeriy Sizov committed
26 27 28 29
      WebMock.stub_request(:post, @system_hook.url)
    end

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

Valeriy Sizov's avatar
Valeriy Sizov committed
34
    it "project_destroy hook" do
35
      project = create(:project)
36
      project.destroy
Valeriy Sizov's avatar
Valeriy Sizov committed
37 38 39 40
      WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
    end

    it "user_create hook" do
41
      create(:user)
Valeriy Sizov's avatar
Valeriy Sizov committed
42 43
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
    end
44

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

Valeriy Sizov's avatar
Valeriy Sizov committed
51
    it "project_create hook" do
52 53
      user = create(:user)
      project = create(:project)
54
      project.team << [user, :master]
Valeriy Sizov's avatar
Valeriy Sizov committed
55 56
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
    end
57

Valeriy Sizov's avatar
Valeriy Sizov committed
58
    it "project_destroy hook" do
59 60
      user = create(:user)
      project = create(:project)
61
      project.team << [user, :master]
62
      project.users_projects.clear
Valeriy Sizov's avatar
Valeriy Sizov committed
63 64 65 66
      WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
    end
  end
end