diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-26 13:11:18 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-26 13:13:27 -0700 |
commit | f5e6bafe6a7832ff20ebc3397e3b212ded2e6f63 (patch) | |
tree | 160c7207257aeb6fd18621551018001bbfdcab08 | |
parent | a983e1e89c6f55cd08feb394db33ca0620fadfd1 (diff) | |
parent | c6fd24643604b5779a76527e6364f21ee5cc3ce0 (diff) | |
download | rails-f5e6bafe6a7832ff20ebc3397e3b212ded2e6f63.tar.gz rails-f5e6bafe6a7832ff20ebc3397e3b212ded2e6f63.tar.bz2 rails-f5e6bafe6a7832ff20ebc3397e3b212ded2e6f63.zip |
Merge branch 'brainopia-remember_frozen_state_in_transaction'
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 12 | ||||
-rw-r--r-- | activerecord/test/cases/transactions_test.rb | 15 |
2 files changed, 20 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index c4a97db582..de701edca0 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -360,14 +360,12 @@ module ActiveRecord # Save the new record state and id of a record so it can be restored later if a transaction fails. def remember_transaction_record_state #:nodoc: @_start_transaction_state[:id] = id - unless @_start_transaction_state.include?(:new_record) - @_start_transaction_state[:new_record] = @new_record - end - unless @_start_transaction_state.include?(:destroyed) - @_start_transaction_state[:destroyed] = @destroyed - end + @_start_transaction_state.reverse_merge!( + new_record: @new_record, + destroyed: @destroyed, + frozen?: frozen?, + ) @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1 - @_start_transaction_state[:frozen?] = frozen? end # Clear the new record state and id of a record. diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index cf50bd4ddb..0bbb4bb79e 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -562,6 +562,21 @@ class TransactionTest < ActiveRecord::TestCase assert !@second.destroyed?, 'not destroyed' end + def test_restore_frozen_state_after_double_destroy + topic = Topic.create + reply = topic.replies.create + + Topic.transaction do + topic.destroy # calls #destroy on reply (since dependent: destroy) + reply.destroy + + raise ActiveRecord::Rollback + end + + assert_not reply.frozen? + assert_not topic.frozen? + end + def test_sqlite_add_column_in_transaction return true unless current_adapter?(:SQLite3Adapter) |