aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-10-22 16:48:09 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-10-22 16:48:09 -0700
commit40496430d5825f55d1b8aa063f6642b82f6c65d5 (patch)
tree5c717dc574be37c6cbd073cf031fb020672c64b9 /activerecord
parent78adc4529a0447a685be59534c1e627a0a1077d0 (diff)
downloadrails-40496430d5825f55d1b8aa063f6642b82f6c65d5.tar.gz
rails-40496430d5825f55d1b8aa063f6642b82f6c65d5.tar.bz2
rails-40496430d5825f55d1b8aa063f6642b82f6c65d5.zip
frozen state should be restored after txn is aborted
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/transactions.rb5
-rw-r--r--activerecord/test/cases/transactions_test.rb15
2 files changed, 18 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb
index 934393b4e7..f91abfbd19 100644
--- a/activerecord/lib/active_record/transactions.rb
+++ b/activerecord/lib/active_record/transactions.rb
@@ -328,6 +328,7 @@ module ActiveRecord
@_start_transaction_state[:new_record] = @new_record
@_start_transaction_state[:destroyed] = @destroyed
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1
+ @_start_transaction_state[:frozen?] = @attributes.frozen?
end
# Clear the new record state and id of a record.
@@ -342,8 +343,8 @@ module ActiveRecord
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1
if @_start_transaction_state[:level] < 1 || force
restore_state = @_start_transaction_state
- was_frozen = @attributes.frozen?
- @attributes = @attributes.dup if was_frozen
+ was_frozen = restore_state[:frozen?]
+ @attributes = @attributes.dup if @attributes.frozen?
@new_record = restore_state[:new_record]
@destroyed = restore_state[:destroyed]
if restore_state.has_key?(:id)
diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb
index bb4f2c8064..fdca10f4fb 100644
--- a/activerecord/test/cases/transactions_test.rb
+++ b/activerecord/test/cases/transactions_test.rb
@@ -14,6 +14,21 @@ class TransactionTest < ActiveRecord::TestCase
@first, @second = Topic.find(1, 2).sort_by { |t| t.id }
end
+ def test_raise_after_destroy
+ refute @first.frozen?
+
+ assert_raises(RuntimeError) {
+ Topic.transaction do
+ @first.destroy
+ assert @first.frozen?
+ raise
+ end
+ }
+
+ assert @first.reload
+ refute @first.frozen?
+ end
+
def test_successful
Topic.transaction do
@first.approved = true