summaryrefslogtreecommitdiff
path: root/spec/models/hooks
diff options
context:
space:
mode:
authorbugagazavr <kirik910@gmail.com>2015-01-24 03:10:43 +0300
committerKirill Zaitsev <kirik910@gmail.com>2015-05-08 16:49:03 +0300
commitacac7889023de96af61d293d855c33996bd780a1 (patch)
tree83d3d7ef3e7a12eca12843bccf92b6bd080b648a /spec/models/hooks
parent0fc6f0b5d406f530e9ad8a35f0188536f6525cb9 (diff)
downloadgitlab-ce-acac7889023de96af61d293d855c33996bd780a1.tar.gz
Added X-GitLab-Event header for web hooks
Diffstat (limited to 'spec/models/hooks')
-rw-r--r--spec/models/hooks/service_hook_spec.rb33
-rw-r--r--spec/models/hooks/system_hook_spec.rb42
-rw-r--r--spec/models/hooks/web_hook_spec.rb14
3 files changed, 74 insertions, 15 deletions
diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb
index 96bf74d45da..d9714596f5d 100644
--- a/spec/models/hooks/service_hook_spec.rb
+++ b/spec/models/hooks/service_hook_spec.rb
@@ -21,4 +21,37 @@ describe ServiceHook do
describe "Associations" do
it { is_expected.to belong_to :service }
end
+
+ describe "execute" do
+ before(:each) do
+ @service_hook = create(:service_hook)
+ @data = { project_id: 1, data: {}}
+
+ WebMock.stub_request(:post, @service_hook.url)
+ end
+
+ it "POSTs to the web hook URL" do
+ @service_hook.execute(@data)
+ expect(WebMock).to have_requested(:post, @service_hook.url).with(
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Service Hook'}
+ ).once
+ end
+
+ it "POSTs the data as JSON" do
+ json = @data.to_json
+
+ @service_hook.execute(@data)
+ expect(WebMock).to have_requested(:post, @service_hook.url).with(
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Service Hook'}
+ ).once
+ end
+
+ it "catches exceptions" do
+ expect(WebHook).to receive(:post).and_raise("Some HTTP Post error")
+
+ expect {
+ @service_hook.execute(@data)
+ }.to raise_error
+ end
+ end
end
diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb
index 810b311a40b..e4b6b886565 100644
--- a/spec/models/hooks/system_hook_spec.rb
+++ b/spec/models/hooks/system_hook_spec.rb
@@ -26,32 +26,47 @@ describe SystemHook do
it "project_create hook" do
Projects::CreateService.new(create(:user), name: 'empty').execute
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_create/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /project_create/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "project_destroy hook" do
user = create(:user)
project = create(:empty_project, namespace: user.namespace)
Projects::DestroyService.new(project, user, {}).execute
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /project_destroy/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "user_create hook" do
create(:user)
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_create/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /user_create/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "user_destroy hook" do
user = create(:user)
user.destroy
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /user_destroy/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "project_create hook" do
user = create(:user)
project = create(:project)
project.team << [user, :master]
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /user_add_to_team/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it "project_destroy hook" do
@@ -59,13 +74,17 @@ describe SystemHook do
project = create(:project)
project.team << [user, :master]
project.project_members.destroy_all
- expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
+ expect(WebMock).to have_requested(:post, @system_hook.url).with(
+ body: /user_remove_from_team/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
+ ).once
end
it 'group create hook' do
create(:group)
expect(WebMock).to have_requested(:post, @system_hook.url).with(
- body: /group_create/
+ body: /group_create/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
).once
end
@@ -73,7 +92,8 @@ describe SystemHook do
group = create(:group)
group.destroy
expect(WebMock).to have_requested(:post, @system_hook.url).with(
- body: /group_destroy/
+ body: /group_destroy/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
).once
end
@@ -82,7 +102,8 @@ describe SystemHook do
user = create(:user)
group.add_user(user, Gitlab::Access::MASTER)
expect(WebMock).to have_requested(:post, @system_hook.url).with(
- body: /user_add_to_group/
+ body: /user_add_to_group/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
).once
end
@@ -92,7 +113,8 @@ describe SystemHook do
group.add_user(user, Gitlab::Access::MASTER)
group.group_members.destroy_all
expect(WebMock).to have_requested(:post, @system_hook.url).with(
- body: /user_remove_from_group/
+ body: /user_remove_from_group/,
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'System Hook'}
).once
end
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb
index 67ec9193ad7..9f5ef3eff70 100644
--- a/spec/models/hooks/web_hook_spec.rb
+++ b/spec/models/hooks/web_hook_spec.rb
@@ -52,22 +52,26 @@ describe ProjectHook do
end
it "POSTs to the web hook URL" do
- @project_hook.execute(@data)
- expect(WebMock).to have_requested(:post, @project_hook.url).once
+ @project_hook.execute(@data, 'push_hooks')
+ expect(WebMock).to have_requested(:post, @project_hook.url).with(
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Push Hook'}
+ ).once
end
it "POSTs the data as JSON" do
json = @data.to_json
- @project_hook.execute(@data)
- expect(WebMock).to have_requested(:post, @project_hook.url).with(body: json).once
+ @project_hook.execute(@data, 'push_hooks')
+ expect(WebMock).to have_requested(:post, @project_hook.url).with(
+ headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Push Hook'}
+ ).once
end
it "catches exceptions" do
expect(WebHook).to receive(:post).and_raise("Some HTTP Post error")
expect {
- @project_hook.execute(@data)
+ @project_hook.execute(@data, 'push_hooks')
}.to raise_error
end
end