aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/transactions_test.rb
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2014-05-15 15:38:05 -0400
committerArthur Neves <arthurnn@gmail.com>2014-05-15 16:29:16 -0400
commit535f299df9b8228c854d3ed0554feeaf1946812f (patch)
tree841dc7d722496be86e07a8fff0a3163fe45bcfcf /activerecord/test/cases/transactions_test.rb
parente3d223bcce28c3ac70b84399f9b211ae11542233 (diff)
downloadrails-535f299df9b8228c854d3ed0554feeaf1946812f.tar.gz
rails-535f299df9b8228c854d3ed0554feeaf1946812f.tar.bz2
rails-535f299df9b8228c854d3ed0554feeaf1946812f.zip
Clear transaction state if callback raise rollback
Diffstat (limited to 'activerecord/test/cases/transactions_test.rb')
-rw-r--r--activerecord/test/cases/transactions_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb
index e6ed85394b..de1f624191 100644
--- a/activerecord/test/cases/transactions_test.rb
+++ b/activerecord/test/cases/transactions_test.rb
@@ -123,6 +123,19 @@ class TransactionTest < ActiveRecord::TestCase
assert !Topic.find(1).approved?
end
+ def test_rolling_back_in_a_callback_rollbacks_before_save
+ def @first.before_save_for_transaction
+ raise ActiveRecord::Rollback
+ end
+ assert !@first.approved
+
+ Topic.transaction do
+ @first.approved = true
+ @first.save!
+ end
+ assert !Topic.find(@first.id).approved?, "Should not commit the approved flag"
+ end
+
def test_raising_exception_in_nested_transaction_restore_state_in_save
topic = Topic.new