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 ...@@ -268,8 +268,10 @@ module EE
super super
if group && feature_available?(:group_webhooks) if group && feature_available?(:group_webhooks)
group.hooks.__send__(hooks_scope).each do |hook| # rubocop:disable GitlabSecurity/PublicSend run_after_commit_or_now do
hook.async_execute(data, hooks_scope.to_s) group.hooks.hooks_for(hooks_scope).each do |hook|
hook.async_execute(data, hooks_scope.to_s)
end
end end
end end
end end
......
...@@ -6,7 +6,7 @@ describe Issues::MoveService do ...@@ -6,7 +6,7 @@ describe Issues::MoveService do
let(:title) { 'Some issue' } let(:title) { 'Some issue' }
let(:description) { 'Some issue description' } let(:description) { 'Some issue description' }
let(:old_project) { create(:project) } 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(:milestone1) { create(:milestone, project_id: old_project.id, title: 'v9.0') }
let(:old_issue) do let(:old_issue) do
...@@ -297,9 +297,25 @@ describe Issues::MoveService do ...@@ -297,9 +297,25 @@ describe Issues::MoveService do
end end
context 'project issue hooks' do 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 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, # Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never # but since the entire spec run takes place in a transaction, we never
# actually get to the `after_commit` hook that queues these jobs. # 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