mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fix broken testcase for transactions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2409 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -39,20 +39,24 @@ module ActiveRecord
|
||||
|
||||
# Wrap a block in a transaction. Returns result of block.
|
||||
def transaction(start_db_transaction = true)
|
||||
needs_commit = false
|
||||
transaction_open = false
|
||||
begin
|
||||
if block_given?
|
||||
begin_db_transaction if start_db_transaction
|
||||
needs_commit = start_db_transaction
|
||||
if start_db_transaction
|
||||
begin_db_transaction
|
||||
transaction_open = true
|
||||
end
|
||||
yield
|
||||
end
|
||||
rescue Exception => database_transaction_rollback
|
||||
rollback_db_transaction if start_db_transaction
|
||||
needs_commit = false
|
||||
if transaction_open
|
||||
transaction_open = false
|
||||
rollback_db_transaction
|
||||
end
|
||||
raise
|
||||
end
|
||||
ensure
|
||||
commit_db_transaction if needs_commit
|
||||
commit_db_transaction if transaction_open
|
||||
end
|
||||
|
||||
# Begins the transaction (and turns off auto-committing).
|
||||
|
||||
@@ -40,7 +40,7 @@ class TransactionTest < Test::Unit::TestCase
|
||||
alias :real_commit_db_transaction :commit_db_transaction
|
||||
def commit_db_transaction
|
||||
$committed = true
|
||||
:real_commit_db_transaction
|
||||
real_commit_db_transaction
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user