Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f79477f1
Commit
f79477f1
authored
Dec 08, 2021
by
Thong Kuah
Committed by
Dylan Griffith
Dec 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix run_after_commit_or_now to use model's connection
parent
3a313b9c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
2 deletions
+57
-2
app/models/concerns/after_commit_queue.rb
app/models/concerns/after_commit_queue.rb
+2
-2
spec/models/concerns/after_commit_queue_spec.rb
spec/models/concerns/after_commit_queue_spec.rb
+55
-0
No files found.
app/models/concerns/after_commit_queue.rb
View file @
f79477f1
...
...
@@ -15,8 +15,8 @@ module AfterCommitQueue
end
def
run_after_commit_or_now
(
&
block
)
if
ApplicationRecord
.
inside_transaction?
if
ActiveRecord
::
Base
.
connection
.
current_transaction
.
records
&
.
include?
(
self
)
# rubocop: disable Database/MultipleDatabases
if
self
.
class
.
inside_transaction?
if
connection
.
current_transaction
.
records
&
.
include?
(
self
)
run_after_commit
(
&
block
)
else
# If the current transaction does not include this record, we can run
...
...
spec/models/concerns/after_commit_queue_spec.rb
View file @
f79477f1
...
...
@@ -69,5 +69,60 @@ RSpec.describe AfterCommitQueue do
expect
(
called
).
to
be
true
end
context
'multiple databases - Ci::ApplicationRecord models'
do
before
do
skip_if_multiple_databases_not_setup
table_sql
=
<<~
SQL
CREATE TABLE _test_ci_after_commit_queue (
id serial NOT NULL PRIMARY KEY);
SQL
::
Ci
::
ApplicationRecord
.
connection
.
execute
(
table_sql
)
end
let
(
:ci_klass
)
do
Class
.
new
(
Ci
::
ApplicationRecord
)
do
self
.
table_name
=
'_test_ci_after_commit_queue'
include
AfterCommitQueue
def
self
.
name
'TestCiAfterCommitQueue'
end
end
end
let
(
:ci_record
)
{
ci_klass
.
new
}
it
'runs immediately if not within a transaction'
do
called
=
false
test_proc
=
proc
{
called
=
true
}
ci_record
.
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
}
Ci
::
ApplicationRecord
.
transaction
do
# Add this record to the current transaction so that after commit hooks
# are called
Ci
::
ApplicationRecord
.
connection
.
add_transaction_record
(
ci_record
)
ci_record
.
run_after_commit_or_now
(
&
test_proc
)
ci_record
.
save!
expect
(
called
).
to
be
false
end
expect
(
called
).
to
be
true
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment