aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2014-08-08 15:46:00 -0400
committerArthur Neves <arthurnn@gmail.com>2014-08-15 16:04:39 -0400
commit2e90fe736de73cfd89eed68b38e03eb6175314bc (patch)
tree8894bfbea8e8ec985eadacc794045869c21dea39 /activerecord/test
parent0002954512364f2f69d28798f7a79aa8e27d7b6b (diff)
downloadrails-2e90fe736de73cfd89eed68b38e03eb6175314bc.tar.gz
rails-2e90fe736de73cfd89eed68b38e03eb6175314bc.tar.bz2
rails-2e90fe736de73cfd89eed68b38e03eb6175314bc.zip
Fix regression on after_commit in nested transactions.
after_commit should not run in nested transactions, however they should run once the outermost transaction gets committed. This patch fixes the problem copying the records from the Savepoint to its parent. So the RealTransaction will have all records that needs to run callbacks on it. [fixes #16425]
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/transaction_callbacks_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb
index 3d64ecb464..a3f39804b7 100644
--- a/activerecord/test/cases/transaction_callbacks_test.rb
+++ b/activerecord/test/cases/transaction_callbacks_test.rb
@@ -129,6 +129,19 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
assert_equal [:commit_on_update], @first.history
end
+ def test_only_call_after_commit_on_top_level_transactions
+ @first.after_commit_block{|r| r.history << :after_commit}
+ assert @first.history.empty?
+
+ @first.transaction do
+ @first.transaction(requires_new: true) do
+ @first.touch
+ end
+ assert @first.history.empty?
+ end
+ assert_equal [:after_commit], @first.history
+ end
+
def test_call_after_rollback_after_transaction_rollsback
@first.after_commit_block{|r| r.history << :after_commit}
@first.after_rollback_block{|r| r.history << :after_rollback}