aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/transactions_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-02-21 22:13:39 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-02-21 22:13:39 +0000
commit25bb98e42daa98c4207ea19bb80525d2b7cf8962 (patch)
tree72987b98040a64fe355540b780da0209ab2af0ae /activerecord/test/transactions_test.rb
parent7842caed942d5a410dcc0c22f2d3dfd808fa0cfa (diff)
downloadrails-25bb98e42daa98c4207ea19bb80525d2b7cf8962.tar.gz
rails-25bb98e42daa98c4207ea19bb80525d2b7cf8962.tar.bz2
rails-25bb98e42daa98c4207ea19bb80525d2b7cf8962.zip
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
Diffstat (limited to 'activerecord/test/transactions_test.rb')
-rw-r--r--activerecord/test/transactions_test.rb20
1 files changed, 19 insertions, 1 deletions
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 }