提交 40496430 编写于 作者: A Aaron Patterson

frozen state should be restored after txn is aborted

上级 78adc452
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册