diff options
author | Eugene Kenny <elkenny@gmail.com> | 2018-11-07 01:11:53 +0000 |
---|---|---|
committer | Eugene Kenny <elkenny@gmail.com> | 2018-11-07 13:32:49 +0000 |
commit | 9030b7c7751ba8375697baaee461b1a6435ad5fe (patch) | |
tree | 88b7248c79b17a208839e5eaaa1c69c9116e2a25 /activerecord/test | |
parent | 133e0ba33db5887b047c9ac8233e5b414657bca5 (diff) | |
download | rails-9030b7c7751ba8375697baaee461b1a6435ad5fe.tar.gz rails-9030b7c7751ba8375697baaee461b1a6435ad5fe.tar.bz2 rails-9030b7c7751ba8375697baaee461b1a6435ad5fe.zip |
Always add records to parent of nested transaction
When a record with transactional callbacks is saved, it's attached to
the current transaction so that the callbacks can be run when the
transaction is committed. Records can also be added manually with
`add_transaction_record`, even if they have no transactional callbacks.
When a nested transaction is committed, its records are transferred to
the parent transaction, as transactional callbacks should only be run
when the outermost transaction is committed (the "real" transaction).
However, this currently only happens when the record has transactional
callbacks, and not when added manually with `add_transaction_record`.
If a record is added to a nested transaction, we should always attach it
to the parent transaction when the nested transaction is committed,
regardless of whether it has any transactional callbacks.
[Eugene Kenny & Ryuta Kamizono]
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/transaction_callbacks_test.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index c0be45eee7..aa6b7915a2 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -591,6 +591,17 @@ class TransactionEnrollmentCallbacksTest < ActiveRecord::TestCase assert_equal [:before_commit, :after_commit], @topic.history end + def test_commit_run_transactions_callbacks_with_nested_transactions + @topic.transaction do + @topic.transaction(requires_new: true) do + @topic.content = "foo" + @topic.save! + @topic.class.connection.add_transaction_record(@topic) + end + end + assert_equal [:before_commit, :after_commit], @topic.history + end + def test_rollback_does_not_run_transactions_callbacks_without_enrollment @topic.transaction do @topic.content = "foo" |