aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/transaction_callbacks_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-06-04 02:56:52 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-06-04 08:22:55 +0900
commitae028984d91a346067eac3d7f43d9ff3217bed11 (patch)
tree9c4d3f70bdb4c6e02a450fef775be67bbd23642d /activerecord/test/cases/transaction_callbacks_test.rb
parentf7fd680a6de195d78286332c6021afe068ad6bd6 (diff)
downloadrails-ae028984d91a346067eac3d7f43d9ff3217bed11.tar.gz
rails-ae028984d91a346067eac3d7f43d9ff3217bed11.tar.bz2
rails-ae028984d91a346067eac3d7f43d9ff3217bed11.zip
Fix `save` in `after_create_commit` won't invoke extra `after_create_commit`
Since a record is already persisted in `after_create_commit`, so `save` should invoke only `after_update_commit`. This bug is caused by depending on `@_start_transaction_state` for rollback to consider whether it was `new_record` before being committed. If after commit callbacks caused another commit, the state before last commit is no longer `new_record`. Fixes #32831. Closes #18367. Closes #31106.
Diffstat (limited to 'activerecord/test/cases/transaction_callbacks_test.rb')
-rw-r--r--activerecord/test/cases/transaction_callbacks_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb
index 7c87030801..c0be45eee7 100644
--- a/activerecord/test/cases/transaction_callbacks_test.rb
+++ b/activerecord/test/cases/transaction_callbacks_test.rb
@@ -147,6 +147,15 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
assert_equal [:commit_on_destroy], new_record.history
end
+ def test_save_in_after_create_commit_wont_invoke_extra_after_create_commit
+ new_record = TopicWithCallbacks.new(title: "New topic", written_on: Date.today)
+ add_transaction_execution_blocks new_record
+ new_record.after_commit_block(:create) { |r| r.save! }
+
+ new_record.save!
+ assert_equal [:commit_on_create, :commit_on_update], new_record.history
+ end
+
def test_only_call_after_commit_on_create_and_doesnt_leaky
r = ReplyWithCallbacks.new(content: "foo")
r.save_on_after_create = true