From a37c5ae961366e3d693991b51d0830d40ae37e08 Mon Sep 17 00:00:00 2001 From: miloops Date: Thu, 11 Sep 2008 17:41:55 -0300 Subject: Improve test coverage when using the group option in find, has_many or has_and_belongs_to_many. Signed-off-by: Michael Koziarski --- .../has_and_belongs_to_many_associations_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb') diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index edca3c622b..9981f4c5d5 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -636,6 +636,18 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert_equal 3, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL', :group => group.join(",")).size end + def test_find_grouped + all_posts_from_category1 = Post.find(:all, :conditions => "category_id = 1", :joins => :categories) + grouped_posts_of_category1 = Post.find(:all, :conditions => "category_id = 1", :group => "author_id", :select => 'count(posts.id) as posts_count', :joins => :categories) + assert_equal 4, all_posts_from_category1.size + assert_equal 1, grouped_posts_of_category1.size + end + + def test_find_scoped_grouped + assert_equal 4, categories(:general).posts_gruoped_by_title.size + assert_equal 1, categories(:technology).posts_gruoped_by_title.size + end + def test_get_ids assert_equal projects(:active_record, :action_controller).map(&:id).sort, developers(:david).project_ids.sort assert_equal [projects(:active_record).id], developers(:jamis).project_ids -- cgit v1.2.3