diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-21 07:32:44 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-21 07:32:44 +0000 |
commit | 440f2890af5462402d1a77daaf1751a66742b974 (patch) | |
tree | f75574e57ea544ba68e9282a680367a16ec6e4ba /activerecord/test | |
parent | 41fb4904e22859178c3002c2acff342073540a64 (diff) | |
download | rails-440f2890af5462402d1a77daaf1751a66742b974.tar.gz rails-440f2890af5462402d1a77daaf1751a66742b974.tar.bz2 rails-440f2890af5462402d1a77daaf1751a66742b974.zip |
Dynamic finders on association collections respect association :limit. Closes #10227 [Jack Danger Canty]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8178 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 30 | ||||
-rw-r--r-- | activerecord/test/fixtures/author.rb | 1 |
2 files changed, 31 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 4969d65a99..20224cbd42 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -483,6 +483,16 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert_equal [companies(:first_client), companies(:second_client)], companies(:first_firm).clients_sorted_desc.find_all_by_type('Client', :order => 'id') end + def test_dynamic_find_all_should_respect_association_limit + assert_equal 1, companies(:first_firm).limited_clients.find(:all, :conditions => "type = 'Client'").length + assert_equal 1, companies(:first_firm).limited_clients.find_all_by_type('Client').length + end + + def test_dynamic_find_all_limit_should_override_association_limit + assert_equal 2, companies(:first_firm).limited_clients.find(:all, :conditions => "type = 'Client'", :limit => 9_000).length + assert_equal 2, companies(:first_firm).limited_clients.find_all_by_type('Client', :limit => 9_000).length + end + def test_triple_equality assert !(Array === Firm.find(:first).clients) assert Firm.find(:first).clients === Array @@ -1120,6 +1130,16 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert_equal [Comment.find(3), Comment.find(6), Comment.find(7), Comment.find(10)], authors(:david).comments_desc.find_all_by_type('SpecialComment', :order => 'comments.id') end + def test_dynamic_find_all_should_respect_association_limit_for_through + assert_equal 1, authors(:david).limited_comments.find(:all, :conditions => "comments.type = 'SpecialComment'").length + assert_equal 1, authors(:david).limited_comments.find_all_by_type('SpecialComment').length + end + + def test_dynamic_find_all_order_should_override_association_limit_for_through + assert_equal 4, authors(:david).limited_comments.find(:all, :conditions => "comments.type = 'SpecialComment'", :limit => 9_000).length + assert_equal 4, authors(:david).limited_comments.find_all_by_type('SpecialComment', :limit => 9_000).length + end + end class BelongsToAssociationsTest < Test::Unit::TestCase @@ -1864,6 +1884,16 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase assert_equal [low_id_jamis, middle_id_jamis, high_id_jamis], projects(:active_record).developers.find_all_by_name('Jamis', :order => 'id') end + def test_dynamic_find_all_should_respect_association_limit + assert_equal 1, projects(:active_record).limited_developers.find(:all, :conditions => "name = 'Jamis'").length + assert_equal 1, projects(:active_record).limited_developers.find_all_by_name('Jamis').length + end + + def test_dynamic_find_all_order_should_override_association_limit + assert_equal 2, projects(:active_record).limited_developers.find(:all, :conditions => "name = 'Jamis'", :limit => 9_000).length + assert_equal 2, projects(:active_record).limited_developers.find_all_by_name('Jamis', :limit => 9_000).length + end + def test_new_with_values_in_collection jamis = DeveloperForProjectWithAfterCreateHook.find_by_name('Jamis') david = DeveloperForProjectWithAfterCreateHook.find_by_name('David') diff --git a/activerecord/test/fixtures/author.rb b/activerecord/test/fixtures/author.rb index 782a7d608f..d41d8ac439 100644 --- a/activerecord/test/fixtures/author.rb +++ b/activerecord/test/fixtures/author.rb @@ -16,6 +16,7 @@ class Author < ActiveRecord::Base end has_many :comments, :through => :posts has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC' + has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1 has_many :funky_comments, :through => :posts, :source => :comments has_many :special_posts |