From 2a2afca0955fa43a0796d727399f30a2c09bfc5d Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 19 Apr 2006 14:50:10 +0000 Subject: 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 --- activerecord/test/associations_go_eager_test.rb | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'activerecord/test/associations_go_eager_test.rb') 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 -- cgit v1.2.3