diff options
author | Michael Koziarski <michael@koziarski.com> | 2008-01-27 02:41:55 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-01-27 02:41:55 +0000 |
commit | 9500ad5fbc337d881dc953631f6d808ad08774c1 (patch) | |
tree | 368267c053dc6d0c18c0c0a04d76bcdd6bcf9292 /activerecord/test/cases/associations | |
parent | f11904ad6d0d9981dfb54b8fe07bfa908607db35 (diff) | |
download | rails-9500ad5fbc337d881dc953631f6d808ad08774c1.tar.gz rails-9500ad5fbc337d881dc953631f6d808ad08774c1.tar.bz2 rails-9500ad5fbc337d881dc953631f6d808ad08774c1.zip |
Make sure count works on has_many :through associations using :group. Closes #10480 [remvee]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8742 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/join_model_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index f59fe70654..8da13d8b1b 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -603,6 +603,21 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end end + def test_group_has_many_through_should_use_group_for_count + using_length = authors(:david).reload.grouped_comments.length # all associated comments are read first + using_count = authors(:david).reload.grouped_comments.count # associated comments are only counted + assert_equal using_count, using_length + + commented_posts = authors(:david).comments.map(&:post).uniq.size # count commented posts manually + assert_equal commented_posts, authors(:david).grouped_comments.count + end + + def test_group_has_many_through_should_not_allow_column_name_for_count + assert_raises ActiveRecord::HasManyThroughCantCountOnColumnForGroupedAssociation do + authors(:david).grouped_comments.count(:id) + end + end + private # create dynamic Post models to allow different dependency options def find_post_with_dependency(post_id, association, association_name, dependency) |