Commit f11ca956 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'basic_spec_after_commit_or_now' into 'master'

Add missing specs for run_after_commit_or_now

See merge request gitlab-org/gitlab!75814
parents 418c4384 7d81e0a7
......@@ -3,15 +3,71 @@
require 'spec_helper'
RSpec.describe AfterCommitQueue do
it 'runs after transaction is committed' do
called = false
test_proc = proc { called = true }
describe '#run_after_commit' do
it 'runs after record is saved' do
called = false
test_proc = proc { called = true }
project = build(:project)
project.run_after_commit(&test_proc)
project = build(:project)
project.run_after_commit(&test_proc)
project.save!
expect(called).to be false
expect(called).to be true
# save! is run in its own transaction
project.save!
expect(called).to be true
end
it 'runs after transaction is committed' do
called = false
test_proc = proc { called = true }
project = build(:project)
Project.transaction do
project.run_after_commit(&test_proc)
project.save!
expect(called).to be false
end
expect(called).to be true
end
end
describe '#run_after_commit_or_now' do
it 'runs immediately if not within a transction' do
called = false
test_proc = proc { called = true }
project = build(:project)
project.run_after_commit_or_now(&test_proc)
expect(called).to be true
end
it 'runs after transaction has completed' do
called = false
test_proc = proc { called = true }
project = build(:project)
Project.transaction do
# Add this record to the current transaction so that after commit hooks
# are called
Project.connection.add_transaction_record(project)
project.run_after_commit_or_now(&test_proc)
project.save!
expect(called).to be false
end
expect(called).to be true
end
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