aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_go_eager_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-04-19 14:50:10 +0000
committerRick Olson <technoweenie@gmail.com>2006-04-19 14:50:10 +0000
commit2a2afca0955fa43a0796d727399f30a2c09bfc5d (patch)
treecbf50437047a0ae857a9a88681d7470bd5b0f90f /activerecord/test/associations_go_eager_test.rb
parent5ea76fab87f0374e5fe8ea65f8c1cfe42fa2c74e (diff)
downloadrails-2a2afca0955fa43a0796d727399f30a2c09bfc5d.tar.gz
rails-2a2afca0955fa43a0796d727399f30a2c09bfc5d.tar.bz2
rails-2a2afca0955fa43a0796d727399f30a2c09bfc5d.zip
Ensure that Associations#include_eager_conditions? checks both scoped and explicit conditions [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4232 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_go_eager_test.rb')
-rw-r--r--activerecord/test/associations_go_eager_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb
index 324e8eb231..d2ae4e0dd9 100644
--- a/activerecord/test/associations_go_eager_test.rb
+++ b/activerecord/test/associations_go_eager_test.rb
@@ -179,6 +179,42 @@ class EagerAssociationTest < Test::Unit::TestCase
assert_equal count, posts.size
end
+ def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
+ posts = nil
+ Post.with_scope(:find => {
+ :include => :comments,
+ :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'"
+ }) do
+ posts = authors(:david).posts.find(:all, :limit => 2)
+ assert_equal 2, posts.size
+ end
+
+ Post.with_scope(:find => {
+ :include => [ :comments, :author ],
+ :conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')"
+ }) do
+ count = Post.count(:limit => 2)
+ assert_equal count, posts.size
+ end
+ end
+
+ def test_eager_with_has_many_and_limit_and_scoped_and_explicit_conditions_on_the_eagers
+ Post.with_scope(:find => { :conditions => "1=1" }) do
+ posts = authors(:david).posts.find(:all,
+ :include => :comments,
+ :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'",
+ :limit => 2
+ )
+ assert_equal 2, posts.size
+
+ count = Post.count(
+ :include => [ :comments, :author ],
+ :conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')",
+ :limit => 2
+ )
+ assert_equal count, posts.size
+ end
+ end
def test_eager_association_loading_with_habtm
posts = Post.find(:all, :include => :categories, :order => "posts.id")
assert_equal 2, posts[0].categories.size