aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/transactions_test.rb
diff options
context:
space:
mode:
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 }