未验证 提交 8cfa3462 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #32862 from eugeneius/callback_rollback

Don't clear transaction state after manual rollback
......@@ -382,13 +382,7 @@ def with_transaction_returning_status
status = nil
self.class.transaction do
add_to_transaction
begin
status = yield
rescue ActiveRecord::Rollback
clear_transaction_record_state
status = nil
end
status = yield
raise ActiveRecord::Rollback unless status
end
status
......
......@@ -292,6 +292,18 @@ def after_create_for_transaction
assert_nil new_topic.id, "The topic should not have an ID"
end
def test_callback_rollback_in_create_with_rollback_exception
topic = Class.new(Topic) {
def after_create_for_transaction
raise ActiveRecord::Rollback
end
}
new_topic = topic.create(title: "A new topic")
assert !new_topic.persisted?, "The topic should not be persisted"
assert_nil new_topic.id, "The topic should not have an ID"
end
def test_nested_explicit_transactions
Topic.transaction do
Topic.transaction do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册