diff options
author | Xavier Noria <fxn@hashref.com> | 2009-02-01 11:13:27 +0100 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2009-02-22 15:31:27 +1300 |
commit | fc09ebc669bd58f415f7d3ef932ef02dab821ab5 (patch) | |
tree | 368512c146b1931f08eeb964fd20b79f26945710 /activerecord/test/cases/transactions_test.rb | |
parent | f4391c362d71efbc6d9cb66ab0aadc0593b7679e (diff) | |
download | rails-fc09ebc669bd58f415f7d3ef932ef02dab821ab5.tar.gz rails-fc09ebc669bd58f415f7d3ef932ef02dab821ab5.tar.bz2 rails-fc09ebc669bd58f415f7d3ef932ef02dab821ab5.zip |
Wrap calls to update_attributes in a transaction.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#922 state:committed]
Diffstat (limited to 'activerecord/test/cases/transactions_test.rb')
-rw-r--r-- | activerecord/test/cases/transactions_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index 40abd935df..bb8b9bb017 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -182,6 +182,40 @@ class TransactionTest < ActiveRecord::TestCase end end + def test_update_attribute_should_rollback_on_failure + Developer.before_save do + false + end + developer = Developer.first + developer.audit_logs.clear + 2.times { developer.audit_logs.create(:message => 'message') } + assert_equal 2, developer.audit_logs.size + status = developer.update_attribute(:audit_log_ids, []) + assert !status + assert_equal 2, developer.audit_logs(true).size + end + + def test_update_attributes_should_rollback_on_failure + developer = Developer.first + developer.audit_logs.clear + 2.times { developer.audit_logs.create(:message => 'message') } + assert_equal 2, developer.audit_logs.size + status = developer.update_attributes(:audit_log_ids => [], :name => nil) + assert !status + assert_equal 2, developer.audit_logs(true).size + end + + def test_update_attributes_should_rollback_on_failure! + developer = Developer.first + developer.audit_logs.clear + 2.times { developer.audit_logs.create(:message => 'message') } + assert_equal 2, developer.audit_logs.size + assert_raise(ActiveRecord::RecordInvalid) do + developer.update_attributes!(:audit_log_ids => [], :name => nil) + end + assert_equal 2, developer.audit_logs(true).size + end + def test_nested_explicit_transactions Topic.transaction do Topic.transaction do |