debian-mirror-gitlab/spec/models/hooks/system_hook_spec.rb

124 lines
3.9 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
# == Schema Information
#
# Table name: web_hooks
#
# id :integer not null, primary key
# url :string(255)
# project_id :integer
# created_at :datetime
# updated_at :datetime
# 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
# tag_push_events :boolean default(FALSE)
2015-09-11 14:41:01 +05:30
# note_events :boolean default(FALSE), not null
2015-04-26 12:48:37 +05:30
#
require "spec_helper"
2015-12-23 02:04:40 +05:30
describe SystemHook, models: true do
2015-04-26 12:48:37 +05:30
describe "execute" do
2016-06-02 11:05:42 +05:30
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)
2015-04-26 12:48:37 +05:30
end
it "project_create hook" do
2016-06-02 11:05:42 +05:30
Projects::CreateService.new(user, name: 'empty').execute
expect(WebMock).to have_requested(:post, system_hook.url).with(
2015-09-11 14:41:01 +05:30
body: /project_create/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-09-11 14:41:01 +05:30
).once
2015-04-26 12:48:37 +05:30
end
it "project_destroy hook" do
2016-04-02 18:10:28 +05:30
Projects::DestroyService.new(project, user, {}).pending_delete!
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2015-09-11 14:41:01 +05:30
body: /project_destroy/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-09-11 14:41:01 +05:30
).once
2015-04-26 12:48:37 +05:30
end
it "user_create hook" do
create(:user)
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2015-09-11 14:41:01 +05:30
body: /user_create/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-09-11 14:41:01 +05:30
).once
2015-04-26 12:48:37 +05:30
end
it "user_destroy hook" do
user.destroy
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2015-09-11 14:41:01 +05:30
body: /user_destroy/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-09-11 14:41:01 +05:30
).once
2015-04-26 12:48:37 +05:30
end
it "project_create hook" do
project.team << [user, :master]
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2016-04-02 18:10:28 +05:30
body: /user_add_to_team/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-09-11 14:41:01 +05:30
).once
2015-04-26 12:48:37 +05:30
end
it "project_destroy hook" do
project.team << [user, :master]
project.project_members.destroy_all
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2016-04-02 18:10:28 +05:30
body: /user_remove_from_team/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-09-11 14:41:01 +05:30
).once
2015-04-26 12:48:37 +05:30
end
it 'group create hook' do
create(:group)
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2015-09-11 14:41:01 +05:30
body: /group_create/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-04-26 12:48:37 +05:30
).once
end
it 'group destroy hook' do
group.destroy
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2015-09-11 14:41:01 +05:30
body: /group_destroy/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-04-26 12:48:37 +05:30
).once
end
it 'group member create hook' do
2015-09-11 14:41:01 +05:30
group.add_master(user)
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2015-09-11 14:41:01 +05:30
body: /user_add_to_group/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-04-26 12:48:37 +05:30
).once
end
it 'group member destroy hook' do
2015-09-11 14:41:01 +05:30
group.add_master(user)
2015-04-26 12:48:37 +05:30
group.group_members.destroy_all
2016-06-02 11:05:42 +05:30
expect(WebMock).to have_requested(:post, system_hook.url).with(
2015-09-11 14:41:01 +05:30
body: /user_remove_from_group/,
2016-06-02 11:05:42 +05:30
headers: { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
2015-04-26 12:48:37 +05:30
).once
end
end
end