aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-08-10 00:03:49 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-15 23:10:15 +0100
commit43b99f290a8070196919a68999db87873257b7b8 (patch)
treef383c7062cb73c1bd23f279ad9fc9d5a00ba0c9a /activerecord/test
parent128d006242dae07edc65ad03e0e045adac0bbbf3 (diff)
downloadrails-43b99f290a8070196919a68999db87873257b7b8.tar.gz
rails-43b99f290a8070196919a68999db87873257b7b8.tar.bz2
rails-43b99f290a8070196919a68999db87873257b7b8.zip
Support for multi-table updates with limits, offsets and orders
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relations_test.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 7bd9c44651..97abd67385 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -973,4 +973,34 @@ class RelationTest < ActiveRecord::TestCase
assert_equal count, comments.update_all(:post_id => posts(:thinking).id)
assert_equal posts(:thinking), comments(:greetings).post
end
+
+ def test_update_all_with_joins_and_limit
+ comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id).limit(1)
+ assert_equal 1, comments.update_all(:post_id => posts(:thinking).id)
+ end
+
+ def test_update_all_with_joins_and_limit_and_order
+ comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id).order('comments.id').limit(1)
+ assert_equal 1, comments.update_all(:post_id => posts(:thinking).id)
+ assert_equal posts(:thinking), comments(:greetings).post
+ assert_equal posts(:welcome), comments(:more_greetings).post
+ end
+
+ def test_update_all_with_joins_and_offset
+ all_comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id)
+ count = all_comments.count
+ comments = all_comments.offset(1)
+
+ assert_equal count - 1, comments.update_all(:post_id => posts(:thinking).id)
+ end
+
+ def test_update_all_with_joins_and_offset_and_order
+ all_comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id).order('posts.id')
+ count = all_comments.count
+ comments = all_comments.offset(1)
+
+ assert_equal count - 1, comments.update_all(:post_id => posts(:thinking).id)
+ assert_equal posts(:thinking), comments(:more_greetings).post
+ assert_equal posts(:welcome), comments(:greetings).post
+ end
end