2012-10-09 04:14:17 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: web_hooks
|
|
|
|
#
|
2013-12-03 12:11:10 -05:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# url :string(255)
|
|
|
|
# project_id :integer
|
2014-04-09 08:05:03 -04:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2013-12-03 12:11:10 -05:00
|
|
|
# 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
|
2014-04-09 08:05:03 -04:00
|
|
|
# tag_push_events :boolean default(FALSE)
|
2015-05-16 02:33:31 -04:00
|
|
|
# note_events :boolean default(FALSE), not null
|
2012-10-09 04:14:17 -04:00
|
|
|
#
|
|
|
|
|
2012-07-18 17:24:37 -04:00
|
|
|
require "spec_helper"
|
|
|
|
|
2015-12-09 04:50:51 -05:00
|
|
|
describe SystemHook, models: true do
|
2012-07-18 17:24:37 -04:00
|
|
|
describe "execute" do
|
2016-03-30 14:00:57 -04:00
|
|
|
let(:system_hook) { create(:system_hook) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, namespace: user.namespace) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
WebMock.stub_request(:post, system_hook.url)
|
2012-07-18 17:24:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "project_create hook" do
|
2016-03-30 14:00:57 -04:00
|
|
|
Projects::CreateService.new(user, name: 'empty').execute
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2015-01-23 19:10:43 -05:00
|
|
|
body: /project_create/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2015-01-23 19:10:43 -05:00
|
|
|
).once
|
2012-07-18 17:24:37 -04:00
|
|
|
end
|
2012-08-28 01:42:28 -04:00
|
|
|
|
2012-07-18 17:24:37 -04:00
|
|
|
it "project_destroy hook" do
|
2016-08-06 10:25:51 -04:00
|
|
|
Projects::DestroyService.new(project, user, {}).async_execute
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2015-01-23 19:10:43 -05:00
|
|
|
body: /project_destroy/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2015-01-23 19:10:43 -05:00
|
|
|
).once
|
2012-07-18 17:24:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "user_create hook" do
|
2013-01-09 01:14:05 -05:00
|
|
|
create(:user)
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2015-01-23 19:10:43 -05:00
|
|
|
body: /user_create/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2015-01-23 19:10:43 -05:00
|
|
|
).once
|
2012-07-18 17:24:37 -04:00
|
|
|
end
|
2012-08-28 01:42:28 -04:00
|
|
|
|
2012-07-18 17:24:37 -04:00
|
|
|
it "user_destroy hook" do
|
2013-01-09 01:14:05 -05:00
|
|
|
user.destroy
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2015-01-23 19:10:43 -05:00
|
|
|
body: /user_destroy/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2015-01-23 19:10:43 -05:00
|
|
|
).once
|
2012-07-18 17:24:37 -04:00
|
|
|
end
|
2012-08-28 01:42:28 -04:00
|
|
|
|
2012-07-18 17:24:37 -04:00
|
|
|
it "project_create hook" do
|
2013-01-09 01:14:05 -05:00
|
|
|
project.team << [user, :master]
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2016-01-22 14:13:37 -05:00
|
|
|
body: /user_add_to_team/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2015-01-23 19:10:43 -05:00
|
|
|
).once
|
2012-07-18 17:24:37 -04:00
|
|
|
end
|
2012-08-28 01:42:28 -04:00
|
|
|
|
2012-07-18 17:24:37 -04:00
|
|
|
it "project_destroy hook" do
|
2013-01-04 01:43:25 -05:00
|
|
|
project.team << [user, :master]
|
2014-09-14 12:32:51 -04:00
|
|
|
project.project_members.destroy_all
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2016-01-22 14:13:37 -05:00
|
|
|
body: /user_remove_from_team/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2015-01-23 19:10:43 -05:00
|
|
|
).once
|
2012-07-18 17:24:37 -04:00
|
|
|
end
|
2014-08-21 06:53:32 -04:00
|
|
|
|
|
|
|
it 'group create hook' do
|
|
|
|
create(:group)
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2015-01-23 19:10:43 -05:00
|
|
|
body: /group_create/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2014-08-21 06:53:32 -04:00
|
|
|
).once
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'group destroy hook' do
|
|
|
|
group.destroy
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2015-01-23 19:10:43 -05:00
|
|
|
body: /group_destroy/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2014-08-21 06:53:32 -04:00
|
|
|
).once
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'group member create hook' do
|
2015-08-07 00:20:02 -04:00
|
|
|
group.add_master(user)
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2015-01-23 19:10:43 -05:00
|
|
|
body: /user_add_to_group/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2014-08-21 06:53:32 -04:00
|
|
|
).once
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'group member destroy hook' do
|
2015-08-07 00:20:02 -04:00
|
|
|
group.add_master(user)
|
2014-08-21 06:53:32 -04:00
|
|
|
group.group_members.destroy_all
|
2016-03-30 14:00:57 -04:00
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, system_hook.url).with(
|
2015-01-23 19:10:43 -05:00
|
|
|
body: /user_remove_from_group/,
|
2016-05-10 22:58:06 -04:00
|
|
|
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
|
2014-08-21 06:53:32 -04:00
|
|
|
).once
|
|
|
|
end
|
2012-07-18 17:24:37 -04:00
|
|
|
end
|
|
|
|
end
|