gitlabhq/spec/models/system_hook_spec.rb

63 lines
1.7 KiB
Ruby
Raw Normal View History

2012-10-09 10:14:17 +02:00
# == Schema Information
#
# Table name: web_hooks
#
2012-11-19 19:24:05 +01:00
# id :integer not null, primary key
2012-10-09 10:14:17 +02:00
# url :string(255)
# project_id :integer
2012-11-19 19:24:05 +01:00
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255) default("ProjectHook")
2012-11-20 13:19:55 +01:00
# service_id :integer
2012-10-09 10:14:17 +02:00
#
2012-07-18 23:24:37 +02:00
require "spec_helper"
describe SystemHook do
describe "execute" do
2012-07-20 11:08:59 +02:00
before(:each) { ActiveRecord::Base.observers.enable(:all) }
2012-07-18 23:24:37 +02:00
before(:each) do
@system_hook = create(:system_hook)
2012-07-18 23:24:37 +02:00
WebMock.stub_request(:post, @system_hook.url)
end
it "project_create hook" do
2013-01-09 07:14:05 +01:00
project = create(:project)
2012-07-18 23:24:37 +02:00
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
end
2012-07-18 23:24:37 +02:00
it "project_destroy hook" do
project = create(:project)
2013-01-09 07:14:05 +01:00
project.destroy
2012-07-18 23:24:37 +02:00
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
end
it "user_create hook" do
2013-01-09 07:14:05 +01:00
create(:user)
2012-07-18 23:24:37 +02:00
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
end
2012-07-18 23:24:37 +02:00
it "user_destroy hook" do
user = create(:user)
2013-01-09 07:14:05 +01:00
user.destroy
2012-07-18 23:24:37 +02:00
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
end
2012-07-18 23:24:37 +02:00
it "project_create hook" do
user = create(:user)
project = create(:project)
2013-01-09 07:14:05 +01:00
project.team << [user, :master]
2012-07-18 23:24:37 +02:00
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end
2012-07-18 23:24:37 +02:00
it "project_destroy hook" do
user = create(:user)
project = create(:project)
project.team << [user, :master]
2013-01-09 07:14:05 +01:00
project.users_projects.clear
2012-07-18 23:24:37 +02:00
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
end
end
end