From d49a5fcb4cfe90824337dc3756bae7161cea768b Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Thu, 9 Feb 2006 09:17:40 +0000 Subject: * Fix pagination problems when using include * Introduce Unit Tests for pagination * Allow count to work with :include by using count distinct. [Kevin Clark & Jeremy Hopple] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3553 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_go_eager_test.rb | 28 ++++++++++++++++--------- activerecord/test/base_test.rb | 7 +++++++ 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index f345656cc2..a03c201d76 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -120,9 +120,11 @@ class EagerAssociationTest < Test::Unit::TestCase end def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers - assert_raises(ArgumentError) do - posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ]) - end + posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ]) + assert_equal 2, posts.size + + count = Post.count(:include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ]) + assert_equal count, posts.size end def test_eager_with_has_many_and_limit_with_no_results @@ -141,13 +143,19 @@ class EagerAssociationTest < Test::Unit::TestCase end def test_eager_with_has_many_and_limit_and_conditions_on_the_eagers - assert_raises(ArgumentError) do - posts = authors(:david).posts.find(:all, - :include => :comments, - :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'", - :limit => 2 - ) - end + 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 def test_eager_association_loading_with_habtm diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index d2f347e0cb..475e31028a 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1056,6 +1056,13 @@ class BasicsTest < Test::Unit::TestCase "LEFT JOIN comments ON posts.id=comments.post_id") end assert_equal res, res2 + + res3 = res + 1 + assert_nothing_raised do + res3 = Post.count(:conditions => "posts.#{QUOTED_TYPE} = 'Post'", + :joins => "LEFT JOIN comments ON posts.id=comments.post_id") + end + assert_equal res, res3 end def test_clear_association_cache_stored -- cgit v1.2.3