From 25bb98e42daa98c4207ea19bb80525d2b7cf8962 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 21 Feb 2007 22:13:39 +0000 Subject: Added database connection as a yield parameter to ActiveRecord::Base.transaction so you can manually rollback [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6196 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/transactions_test.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'activerecord/test/transactions_test.rb') diff --git a/activerecord/test/transactions_test.rb b/activerecord/test/transactions_test.rb index 3f3ee1adb7..f20c763268 100644 --- a/activerecord/test/transactions_test.rb +++ b/activerecord/test/transactions_test.rb @@ -88,7 +88,7 @@ class TransactionTest < Test::Unit::TestCase def test_failing_with_object_rollback assert !@first.approved?, "First should be unapproved initially" - + begin assert_deprecated /Object transactions/ do Topic.transaction(@first, @second) do @@ -168,6 +168,24 @@ class TransactionTest < Test::Unit::TestCase assert !Topic.find(2).approved?, "Second should have been unapproved" end + def test_manually_rolling_back_a_transaction + Topic.transaction do |transaction| + @first.approved = true + @second.approved = false + @first.save + @second.save + + transaction.rollback! + end + + assert @first.approved?, "First should still be changed in the objects" + assert !@second.approved?, "Second should still be changed in the objects" + + assert !Topic.find(1).approved?, "First shouldn't have been approved" + assert Topic.find(2).approved?, "Second should still be approved" + end + + private def add_exception_raising_after_save_callback_to_topic Topic.class_eval { def after_save() raise "Make the transaction rollback" end } -- cgit v1.2.3