Commit c6afc49b authored by Robert Speicher's avatar Robert Speicher

Merge branch 'dm-issue-move-transaction-error-ee' into 'master'

Execute group hooks after-commit when moving an issue

Closes gitlab-ce#42294

See merge request gitlab-org/gitlab-ee!4229
parents 17705a1f 123bdad1
---
title: Execute group hooks after-commit when moving an issue
merge_request:
author:
type: fixed
......@@ -268,8 +268,10 @@ module EE
super
if group && feature_available?(:group_webhooks)
group.hooks.__send__(hooks_scope).each do |hook| # rubocop:disable GitlabSecurity/PublicSend
hook.async_execute(data, hooks_scope.to_s)
run_after_commit_or_now do
group.hooks.hooks_for(hooks_scope).each do |hook|
hook.async_execute(data, hooks_scope.to_s)
end
end
end
end
......
......@@ -6,7 +6,7 @@ describe Issues::MoveService do
let(:title) { 'Some issue' }
let(:description) { 'Some issue description' }
let(:old_project) { create(:project) }
let(:new_project) { create(:project) }
let(:new_project) { create(:project, group: create(:group)) }
let(:milestone1) { create(:milestone, project_id: old_project.id, title: 'v9.0') }
let(:old_issue) do
......@@ -297,9 +297,25 @@ describe Issues::MoveService do
end
context 'project issue hooks' do
let(:hook) { create(:project_hook, project: old_project, issues_events: true) }
let!(:hook) { create(:project_hook, project: old_project, issues_events: true) }
it 'executes project issue hooks' do
allow_any_instance_of(WebHookService).to receive(:execute)
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never
# actually get to the `after_commit` hook that queues these jobs.
expect { move_service.execute(old_issue, new_project) }
.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end
end
context 'group issue hooks' do
let!(:hook) { create(:group_hook, group: new_project.group, issues_events: true) }
it 'executes group issue hooks' do
allow_any_instance_of(WebHookService).to receive(:execute)
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never
# actually get to the `after_commit` hook that queues these jobs.
......
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