Permalink
Browse files

frozen state should be restored after txn is aborted

  • Loading branch information...
1 parent 78adc45 commit 40496430d5825f55d1b8aa063f6642b82f6c65d5 @tenderlove tenderlove committed Oct 22, 2012
Showing with 18 additions and 2 deletions.
  1. +3 −2 activerecord/lib/active_record/transactions.rb
  2. +15 −0 activerecord/test/cases/transactions_test.rb
@@ -328,6 +328,7 @@ def remember_transaction_record_state #:nodoc:
@_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 @@ def restore_transaction_record_state(force = false) #:nodoc:
@_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)
@@ -14,6 +14,21 @@ def setup
@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

0 comments on commit 4049643

Please sign in to comment.