mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
frozen state should be restored after txn is aborted
This commit is contained in:
@@ -329,6 +329,7 @@ module ActiveRecord
|
||||
@_start_transaction_state[:destroyed] = @destroyed
|
||||
end
|
||||
@_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.
|
||||
@@ -345,8 +346,8 @@ module ActiveRecord
|
||||
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1
|
||||
if @_start_transaction_state[:level] < 1 || force
|
||||
restore_state = remove_instance_variable(:@_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 @@ class TransactionTest < ActiveRecord::TestCase
|
||||
@first, @second = Topic.find(1, 2).sort_by { |t| t.id }
|
||||
end
|
||||
|
||||
def test_raise_after_destroy
|
||||
assert !@first.frozen?
|
||||
|
||||
assert_raises(RuntimeError) {
|
||||
Topic.transaction do
|
||||
@first.destroy
|
||||
assert @first.frozen?
|
||||
raise
|
||||
end
|
||||
}
|
||||
|
||||
assert @first.reload
|
||||
assert !@first.frozen?
|
||||
end
|
||||
|
||||
def test_successful
|
||||
Topic.transaction do
|
||||
@first.approved = true
|
||||
|
||||
Reference in New Issue
Block a user