diff options
author | Arthur Neves <arthurnn@gmail.com> | 2014-02-03 15:29:26 -0500 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2014-02-03 15:49:48 -0500 |
commit | 9b66d6d47f87d31fb360f48542520d9216e77dc9 (patch) | |
tree | 2d52fa53b21a755cf58a82688f3de9c128c11156 /activerecord | |
parent | 28abd967fcc8544650c73910a8a0cbaa6dafc1f5 (diff) | |
download | rails-9b66d6d47f87d31fb360f48542520d9216e77dc9.tar.gz rails-9b66d6d47f87d31fb360f48542520d9216e77dc9.tar.bz2 rails-9b66d6d47f87d31fb360f48542520d9216e77dc9.zip |
Make sure transaction state resets after commit
[fixes #12566]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/transaction_callbacks_test.rb | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index c33ffeece0..ec3e8f281b 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -295,7 +295,7 @@ module ActiveRecord def committed! #:nodoc: run_callbacks :commit if destroyed? || persisted? ensure - clear_transaction_record_state + @_start_transaction_state.clear end # Call the +after_rollback+ callbacks. The +force_restore_state+ argument indicates if the record diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb index 7e7d95841b..3d64ecb464 100644 --- a/activerecord/test/cases/transaction_callbacks_test.rb +++ b/activerecord/test/cases/transaction_callbacks_test.rb @@ -16,6 +16,11 @@ class TransactionCallbacksTest < ActiveRecord::TestCase after_commit :do_after_commit, on: :create + attr_accessor :save_on_after_create + after_create do + self.save! if save_on_after_create + end + def history @history ||= [] end @@ -107,6 +112,16 @@ class TransactionCallbacksTest < ActiveRecord::TestCase assert_equal [], reply.history end + def test_only_call_after_commit_on_create_and_doesnt_leaky + r = ReplyWithCallbacks.new(content: 'foo') + r.save_on_after_create = true + r.save! + r.content = 'bar' + r.save! + r.save! + assert_equal [:commit_on_create], r.history + end + def test_only_call_after_commit_on_update_after_transaction_commits_for_existing_record_on_touch add_transaction_execution_blocks @first |