diff options
author | Duana Saskia <starkcoffee@users.noreply.github.com> | 2018-06-06 23:08:29 +0200 |
---|---|---|
committer | Duana Saskia <starkcoffee@users.noreply.github.com> | 2018-08-13 13:20:58 +0200 |
commit | 07356866b2ce85f4d724c96f14e129fbe6a56963 (patch) | |
tree | 8ccfcff6309345ee12935d5168338d4785d83550 /spec/models | |
parent | d7c521012f8486c735c7832b58c7d8649b4d6e83 (diff) | |
download | gitlab-ce-07356866b2ce85f4d724c96f14e129fbe6a56963.tar.gz |
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.rb | 23 |
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 |