aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2006-02-09 09:17:40 +0000
committerMichael Koziarski <michael@koziarski.com>2006-02-09 09:17:40 +0000
commitd49a5fcb4cfe90824337dc3756bae7161cea768b (patch)
tree48af0b2f4c9301be8e0816e5ac759516862db2ef /activerecord/test
parent803b9a41af46210da842afdba032c34109514942 (diff)
downloadrails-d49a5fcb4cfe90824337dc3756bae7161cea768b.tar.gz
rails-d49a5fcb4cfe90824337dc3756bae7161cea768b.tar.bz2
rails-d49a5fcb4cfe90824337dc3756bae7161cea768b.zip
* 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
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/associations_go_eager_test.rb28
-rwxr-xr-xactiverecord/test/base_test.rb7
2 files changed, 25 insertions, 10 deletions
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