aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorSteven Fenigstein <steve@navigatingcancer.com>2011-02-11 00:39:58 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-16 09:54:09 -0800
commit9b188c5bfe04349aa8ee0eeb2b53456601b8c3fc (patch)
tree97c30d3f5a577dea783c5b527c75449059b01348 /activerecord/test/cases/relations_test.rb
parentc6fac7b449ad88a623d99487d2731dddc6555636 (diff)
downloadrails-9b188c5bfe04349aa8ee0eeb2b53456601b8c3fc.tar.gz
rails-9b188c5bfe04349aa8ee0eeb2b53456601b8c3fc.tar.bz2
rails-9b188c5bfe04349aa8ee0eeb2b53456601b8c3fc.zip
removed an unnecessary second query when passing an ActiveRecord::Relation to a where clause. And added ability to use subselects in where clauses.
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 184e7a2b9e..843c3d2d96 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -467,7 +467,7 @@ class RelationTest < ActiveRecord::TestCase
authors = Author.find_by_id([author])
assert_equal author, authors
end
-
+
def test_find_all_using_where_twice_should_or_the_relation
david = authors(:david)
relation = Author.unscoped
@@ -488,6 +488,33 @@ class RelationTest < ActiveRecord::TestCase
end
assert_equal [david], relation.all
end
+
+ def test_find_all_using_where_with_relation
+ david = authors(:david)
+ # switching the lines below would succeed in current rails
+ # assert_queries(2) {
+ assert_queries(1) {
+ relation = Author.where(:id => Author.where(:id => david.id))
+ assert_equal [david], relation.all
+ }
+ end
+
+ def test_find_all_using_where_with_relation_with_joins
+ david = authors(:david)
+ assert_queries(1) {
+ relation = Author.where(:id => Author.joins(:posts).where(:id => david.id))
+ assert_equal [david], relation.all
+ }
+ end
+
+
+ def test_find_all_using_where_with_relation_with_select_to_build_subquery
+ david = authors(:david)
+ assert_queries(1) {
+ relation = Author.where(:name => Author.where(:id => david.id).select(:name))
+ assert_equal [david], relation.all
+ }
+ end
def test_exists
davids = Author.where(:name => 'David')