aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-12-30 01:12:38 +0530
committerPratik Naik <pratiknaik@gmail.com>2009-12-30 01:12:38 +0530
commit00cd3789f6d53163229669ad82a5d87fcdcb49ba (patch)
treebb5bba7ee8ce3f492c169da56f112c8767b9acf8 /activerecord/test/cases/relations_test.rb
parentaa1b32ae9774e3f2a95faa0ec9efdf295958106d (diff)
downloadrails-00cd3789f6d53163229669ad82a5d87fcdcb49ba.tar.gz
rails-00cd3789f6d53163229669ad82a5d87fcdcb49ba.tar.bz2
rails-00cd3789f6d53163229669ad82a5d87fcdcb49ba.zip
Relation#count should look for projections in chained relations and perform the count on the given column
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 8c1ce07e75..f0ef3e22c5 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -376,7 +376,7 @@ class RelationTest < ActiveRecord::TestCase
relations = []
relations << (Post.order('comments.id DESC') & Post.eager_load(:last_comment) & Post.scoped)
relations << (Post.eager_load(:last_comment) & Post.order('comments.id DESC') & Post.scoped)
-
+
relations.each do |posts|
post = posts.find { |p| p.id == 1 }
assert_equal Post.find(1).last_comment, post.last_comment
@@ -418,6 +418,9 @@ class RelationTest < ActiveRecord::TestCase
Post.update_all(:comments_count => nil)
posts = Post.scoped
+ assert_equal 0, posts.select('comments_count').where('id is not null').order('id').count
+ assert_equal 0, posts.where('id is not null').select('comments_count').count
+
assert_equal 7, posts.select('comments_count').count('id')
assert_equal 0, posts.select('comments_count').count
assert_equal 0, posts.count(:comments_count)
@@ -435,4 +438,11 @@ class RelationTest < ActiveRecord::TestCase
assert_no_queries { assert_equal 5, best_posts.size }
end
+ def test_count_complex_chained_relations
+ posts = Post.select('comments_count').where('id is not null').group("author_id").where("comments_count > 0")
+
+ expected = { 1 => 2 }
+ assert_equal expected, posts.count
+ end
+
end