Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #13935 from arthurnn/fix_12566

Make sure transaction state resets after commit
  • Loading branch information...
commit f1a6307a941a6f9c50cf7d196ba4a7bc1252501d 2 parents 75510a6 + 9b66d6d
@rafaelfranca rafaelfranca authored
View
2  activerecord/lib/active_record/transactions.rb
@@ -295,7 +295,7 @@ def rollback_active_record_state!
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
15 activerecord/test/cases/transaction_callbacks_test.rb
@@ -16,6 +16,11 @@ class ReplyWithCallbacks < ActiveRecord::Base
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 @@ def test_only_call_after_commit_on_create_after_transaction_commits_for_new_reco
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

0 comments on commit f1a6307

Please sign in to comment.
Something went wrong with that request. Please try again.