Commit 07356866 authored by Duana Saskia's avatar Duana Saskia

Refactor tests for executing project hooks

So that they test the negative case of hooks that don't have the
specified hook scope
parent d7c52101
...@@ -3670,21 +3670,30 @@ describe Project do ...@@ -3670,21 +3670,30 @@ describe Project do
end end
describe '#execute_hooks' do describe '#execute_hooks' do
let(:data) { { ref: 'refs/heads/master', data: 'data' } }
it 'executes the projects hooks with the specified scope' do it 'executes the projects hooks with the specified scope' do
hook1 = create(:project_hook, merge_requests_events: true, tag_push_events: false) hook = create(:project_hook, merge_requests_events: false, tag_push_events: true)
hook2 = create(:project_hook, merge_requests_events: false, tag_push_events: true) project = create(:project, hooks: [hook])
project = create(:project, hooks: [hook1, hook2])
expect_any_instance_of(ProjectHook).to receive(:async_execute).once 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 end
it 'executes the system hooks with the specified scope' do 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 = build(:project)
project.execute_hooks({ data: 'data' }, :merge_request_hooks) project.execute_hooks(data, :merge_request_hooks)
end end
it 'executes the system hooks when inside a transaction' do it 'executes the system hooks when inside a transaction' do
...@@ -3699,7 +3708,7 @@ describe Project do ...@@ -3699,7 +3708,7 @@ describe Project do
# actually get to the `after_commit` hook that queues these jobs. # actually get to the `after_commit` hook that queues these jobs.
expect do expect do
project.transaction do project.transaction do
project.execute_hooks({ data: 'data' }, :merge_request_hooks) project.execute_hooks(data, :merge_request_hooks)
end end
end.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError end.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment