diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/transactions_test.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index e6ed85394b..7f2e830083 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -274,6 +274,48 @@ class TransactionTest < ActiveRecord::TestCase end end + def test_rollback_when_changing_inside_transaction + assert !@first.approved? + Topic.transaction do + @first.approved = true + @first.save! + raise ActiveRecord::Rollback + end + assert @first.approved + assert @first.changes["approved"] + @first.save! + assert @first.reload.approved + end + + def test_rollback_when_changing_outside_transaction + assert !@first.approved? + @first.approved = true + Topic.transaction do + @first.save! + raise ActiveRecord::Rollback + end + assert @first.changes["approved"] + assert @first.approved + @first.save! + assert @first.reload.approved + end + + def test_rollback_when_changing_back_to_prev_stage + assert !@first.approved? + Topic.transaction do + @first.approved = true + @first.save! + @first.approved = false + @first.save! + raise ActiveRecord::Rollback + end + assert !@first.approved + assert !@first.changes["approved"] + @first.save! + assert !@first.reload.approved + end + + def test_force_savepoint_in_nested_transaction Topic.transaction do @first.approved = true |