Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuana Saskia <starkcoffee@users.noreply.github.com>2018-06-07 00:08:29 +0300
committerDuana Saskia <starkcoffee@users.noreply.github.com>2018-08-13 14:20:58 +0300
commit07356866b2ce85f4d724c96f14e129fbe6a56963 (patch)
tree8ccfcff6309345ee12935d5168338d4785d83550 /spec/models
parentd7c521012f8486c735c7832b58c7d8649b4d6e83 (diff)
Refactor tests for executing project hooks
So that they test the negative case of hooks that don't have the specified hook scope
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/project_spec.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 076de06cf99..2ec030daa67 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -3670,21 +3670,30 @@ describe Project do
end
describe '#execute_hooks' do
+ let(:data) { { ref: 'refs/heads/master', data: 'data' } }
it 'executes the projects hooks with the specified scope' do
- hook1 = create(:project_hook, merge_requests_events: true, tag_push_events: false)
- hook2 = create(:project_hook, merge_requests_events: false, tag_push_events: true)
- project = create(:project, hooks: [hook1, hook2])
+ hook = create(:project_hook, merge_requests_events: false, tag_push_events: true)
+ project = create(:project, hooks: [hook])
expect_any_instance_of(ProjectHook).to receive(:async_execute).once
- project.execute_hooks({}, :tag_push_hooks)
+ project.execute_hooks(data, :tag_push_hooks)
+ end
+
+ it 'does not execute project hooks that dont match the specified scope' do
+ hook = create(:project_hook, merge_requests_events: true, tag_push_events: false)
+ project = create(:project, hooks: [hook])
+
+ expect_any_instance_of(ProjectHook).not_to receive(:async_execute).once
+
+ project.execute_hooks(data, :tag_push_hooks)
end
it 'executes the system hooks with the specified scope' do
- expect_any_instance_of(SystemHooksService).to receive(:execute_hooks).with({ data: 'data' }, :merge_request_hooks)
+ expect_any_instance_of(SystemHooksService).to receive(:execute_hooks).with(data, :merge_request_hooks)
project = build(:project)
- project.execute_hooks({ data: 'data' }, :merge_request_hooks)
+ project.execute_hooks(data, :merge_request_hooks)
end
it 'executes the system hooks when inside a transaction' do
@@ -3699,7 +3708,7 @@ describe Project do
# actually get to the `after_commit` hook that queues these jobs.
expect do
project.transaction do
- project.execute_hooks({ data: 'data' }, :merge_request_hooks)
+ project.execute_hooks(data, :merge_request_hooks)
end
end.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end