summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-01-24 19:22:23 +0000
committerRobert Speicher <robert@gitlab.com>2018-01-24 19:22:23 +0000
commit956c55e2abf9c9780f37d14d69eb4b53fec4621e (patch)
treec38a06c0d2212d066b2d654d0164741b506f4d94 /spec
parenta403011e4f7adae339a3a8584e22a75f4872c3c5 (diff)
parent4564795195f4dafa3ff0578565fc13234b164a97 (diff)
downloadgitlab-ce-956c55e2abf9c9780f37d14d69eb4b53fec4621e.tar.gz
Merge branch 'dm-project-system-hooks-in-transaction' into 'master'
Execute system hooks after-commit when executing project hooks See merge request gitlab-org/gitlab-ce!16673
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_spec.rb17
-rw-r--r--spec/services/issues/move_service_spec.rb4
2 files changed, 20 insertions, 1 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 4d10df410ab..31dcb543cbd 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -3228,5 +3228,22 @@ describe Project do
project = build(:project)
project.execute_hooks({ data: 'data' }, :merge_request_hooks)
end
+
+ it 'executes the system hooks when inside a transaction' do
+ allow_any_instance_of(WebHookService).to receive(:execute)
+
+ create(:system_hook, merge_requests_events: true)
+
+ project = build(:project)
+
+ # 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 do
+ project.transaction do
+ project.execute_hooks({ data: 'data' }, :merge_request_hooks)
+ end
+ end.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
+ end
end
end
diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb
index f3c98fa5416..388c9d63c7b 100644
--- a/spec/services/issues/move_service_spec.rb
+++ b/spec/services/issues/move_service_spec.rb
@@ -297,9 +297,11 @@ 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.