diff options
author | Chris Kampmeier <chris@kampers.net> | 2009-03-16 05:56:32 -0700 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-05-17 18:56:06 +0200 |
commit | 4e8c36a7417e5d447c9b15d5c61df0c014ee6d3b (patch) | |
tree | caae94182a0f64901da53364057798545119829e /activerecord/test/cases/associations | |
parent | 11bac700784efe232083f94e3d28d171957e667e (diff) | |
download | rails-4e8c36a7417e5d447c9b15d5c61df0c014ee6d3b.tar.gz rails-4e8c36a7417e5d447c9b15d5c61df0c014ee6d3b.tar.bz2 rails-4e8c36a7417e5d447c9b15d5c61df0c014ee6d3b.zip |
Implement #many? for NamedScope and AssociationCollection using #size [#1500 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 5df74fcdcd..d99424f9cd 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1023,6 +1023,45 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert firm.clients.loaded? end + def test_calling_many_should_count_instead_of_loading_association + firm = companies(:first_firm) + assert_queries(1) do + firm.clients.many? # use count query + end + assert !firm.clients.loaded? + end + + def test_calling_many_on_loaded_association_should_not_use_query + firm = companies(:first_firm) + firm.clients.collect # force load + assert_no_queries { assert firm.clients.many? } + end + + def test_calling_many_should_defer_to_collection_if_using_a_block + firm = companies(:first_firm) + assert_queries(1) do + firm.clients.expects(:size).never + firm.clients.many? { true } + end + assert firm.clients.loaded? + end + + def test_calling_many_should_return_false_if_none_or_one + firm = companies(:another_firm) + assert !firm.clients_like_ms.many? + assert_equal 0, firm.clients_like_ms.size + + firm = companies(:first_firm) + assert !firm.limited_clients.many? + assert_equal 1, firm.limited_clients.size + end + + def test_calling_many_should_return_true_if_more_than_one + firm = companies(:first_firm) + assert firm.clients.many? + assert_equal 2, firm.clients.size + end + def test_joins_with_namespaced_model_should_use_correct_type old = ActiveRecord::Base.store_full_sti_class ActiveRecord::Base.store_full_sti_class = true |