1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make sure transaction state resets after commit

[fixes #12566]
This commit is contained in:
Arthur Neves 2014-02-03 15:29:26 -05:00
parent 28abd967fc
commit 9b66d6d47f
2 changed files with 16 additions and 1 deletions

View file

@ -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

View file

@ -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