aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2005-09-28 18:53:22 +0000
committerNicholas Seckar <nseckar@gmail.com>2005-09-28 18:53:22 +0000
commitfc83920383b5f839cd6badbc5c962be9383fe150 (patch)
tree6372da579fa303aa5f15cdd0908d8e9197e8435a /activerecord/test
parent0d07152aab40da70ad87e0e652931812a80d7bcc (diff)
downloadrails-fc83920383b5f839cd6badbc5c962be9383fe150.tar.gz
rails-fc83920383b5f839cd6badbc5c962be9383fe150.tar.bz2
rails-fc83920383b5f839cd6badbc5c962be9383fe150.zip
Fix transactions so that calling return while inside a transaction will not leave an open transaction on the connection.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2398 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/transactions_test.rb33
1 files changed, 32 insertions, 1 deletions
diff --git a/activerecord/test/transactions_test.rb b/activerecord/test/transactions_test.rb
index ea3b6ec5c5..42ed57fad5 100644
--- a/activerecord/test/transactions_test.rb
+++ b/activerecord/test/transactions_test.rb
@@ -25,6 +25,37 @@ class TransactionTest < Test::Unit::TestCase
assert !Topic.find(2).approved?, "Second should have been unapproved"
end
+ def transaction_with_return
+ Topic.transaction do
+ @first.approved = 1
+ @second.approved = 0
+ @first.save
+ @second.save
+ return
+ end
+ end
+
+ def test_successful_with_return
+ class << Topic.connection
+ alias :real_commit_db_transaction :commit_db_transaction
+ def commit_db_transaction
+ $committed = true
+ :real_commit_db_transaction
+ end
+ end
+
+ $committed = false
+ transaction_with_return
+ assert $committed
+
+ assert Topic.find(1).approved?, "First should have been approved"
+ assert !Topic.find(2).approved?, "Second should have been unapproved"
+ ensure
+ class << Topic.connection
+ alias :commit_db_transaction :real_commit_db_transaction rescue nil
+ end
+ end
+
def test_successful_with_instance_method
@first.transaction do
@first.approved = 1
@@ -36,7 +67,7 @@ class TransactionTest < Test::Unit::TestCase
assert Topic.find(1).approved?, "First should have been approved"
assert !Topic.find(2).approved?, "Second should have been unapproved"
end
-
+
def test_failing_on_exception
begin
Topic.transaction do