diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-11-07 23:25:07 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-07 23:25:07 +0900 |
commit | d84bc2b169cc0b67abe9e7efe7aa301fca570aa7 (patch) | |
tree | 55d8ae14eac6938c4ffc97f88c75dba4b7125f30 | |
parent | 8eaffe7e89719ac62ff29c2e4208cfbeb1cd1c38 (diff) | |
parent | 9030b7c7751ba8375697baaee461b1a6435ad5fe (diff) | |
download | rails-d84bc2b169cc0b67abe9e7efe7aa301fca570aa7.tar.gz rails-d84bc2b169cc0b67abe9e7efe7aa301fca570aa7.tar.bz2 rails-d84bc2b169cc0b67abe9e7efe7aa301fca570aa7.zip |
Merge pull request #34393 from eugeneius/always_add_to_parent_transaction
Always add records to parent of nested transaction
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/transaction.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/transaction_callbacks_test.rb | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb index 564b226b39..0f2b1e85ff 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb @@ -137,7 +137,7 @@ module ActiveRecord record.committed! else # if not running callbacks, only adds the record to the parent transaction - record.add_to_transaction + connection.add_transaction_record(record) end end ensure 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" |