aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/transactions_test.rb
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-07-13 15:30:23 -0400
committerJosé Valim <jose.valim@gmail.com>2010-07-13 22:02:00 +0200
commitf4fbc2c1f943ff11776b2c7c34df6bcbe655a4e5 (patch)
treeebea9bbac11869cf70391f4521d052d2145d6c38 /activerecord/test/cases/transactions_test.rb
parente35e6171bb27c26b13469ccf188c25bb324e38ab (diff)
downloadrails-f4fbc2c1f943ff11776b2c7c34df6bcbe655a4e5.tar.gz
rails-f4fbc2c1f943ff11776b2c7c34df6bcbe655a4e5.tar.bz2
rails-f4fbc2c1f943ff11776b2c7c34df6bcbe655a4e5.zip
update_attributes and update_attributes! are now wrapped in a transaction
[#922 state:resovled] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test/cases/transactions_test.rb')
-rw-r--r--activerecord/test/cases/transactions_test.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb
index 958a4e4f94..9255190613 100644
--- a/activerecord/test/cases/transactions_test.rb
+++ b/activerecord/test/cases/transactions_test.rb
@@ -3,10 +3,12 @@ require 'models/topic'
require 'models/reply'
require 'models/developer'
require 'models/book'
+require 'models/author'
+require 'models/post'
class TransactionTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
- fixtures :topics, :developers
+ fixtures :topics, :developers, :authors, :posts
def setup
@first, @second = Topic.find(1, 2).sort_by { |t| t.id }
@@ -103,6 +105,25 @@ class TransactionTest < ActiveRecord::TestCase
end
end
+ def test_update_attributes_should_rollback_on_failure
+ author = Author.find(1)
+ posts_count = author.posts.size
+ assert posts_count > 0
+ status = author.update_attributes(:name => nil, :post_ids => [])
+ assert !status
+ assert_equal posts_count, author.posts(true).size
+ end
+
+ def test_update_attributes_should_rollback_on_failure!
+ author = Author.find(1)
+ posts_count = author.posts.size
+ assert posts_count > 0
+ assert_raise(ActiveRecord::RecordInvalid) do
+ author.update_attributes!(:name => nil, :post_ids => [])
+ end
+ assert_equal posts_count, author.posts(true).size
+ end
+
def test_cancellation_from_before_destroy_rollbacks_in_destroy
add_cancelling_before_destroy_with_db_side_effect_to_topic
begin