diff options
author | miloops <miloops@gmail.com> | 2008-09-11 17:41:55 -0300 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-09-11 22:51:57 +0200 |
commit | a37c5ae961366e3d693991b51d0830d40ae37e08 (patch) | |
tree | 0fa9d5de486f5d2fc317676df182d34040a8da1a /activerecord/test/cases/associations | |
parent | 095ad690f3fb6df4e89446dd40e03cf2c204e42a (diff) | |
download | rails-a37c5ae961366e3d693991b51d0830d40ae37e08.tar.gz rails-a37c5ae961366e3d693991b51d0830d40ae37e08.tar.bz2 rails-a37c5ae961366e3d693991b51d0830d40ae37e08.zip |
Improve test coverage when using the group option in find, has_many or has_and_belongs_to_many.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 5 |
2 files changed, 17 insertions, 0 deletions
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 diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index feac4b002b..5bcbc5eb5b 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -248,6 +248,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 1, grouped_clients_of_firm1.size end + def test_find_scoped_grouped + assert_equal 1, companies(:first_firm).clients_grouped_by_firm_id.length + assert_equal 2, companies(:first_firm).clients_grouped_by_name.length + end + def test_adding force_signal37_to_load_all_clients_of_firm natural = Client.new("name" => "Natural Company") |