From 394cc6047df090233927fd1eaf21197e84d7aa37 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 18 Jun 2013 08:37:00 +0200 Subject: [PATCH] `CollectionProxy#include?` returns `true` and `false` as documented. --- .../associations/collection_proxy.rb | 2 +- .../has_many_associations_test.rb | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index e82c195335f50..7cdb5ba5b3fc9 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -830,7 +830,7 @@ def many?(&block) # person.pets.include?(Pet.find(20)) # => true # person.pets.include?(Pet.find(21)) # => false def include?(record) - @association.include?(record) + !!@association.include?(record) end def proxy_association diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 9f64ecd8459c3..168ce130971f6 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -418,7 +418,7 @@ def test_find_string_ids_when_using_finder_sql client_ary = firm.clients_using_finder_sql.find("2", "3") assert_kind_of Array, client_ary assert_equal 2, client_ary.size - assert client_ary.include?(client) + assert_equal true, client_ary.include?(client) end def test_find_all @@ -1220,14 +1220,14 @@ def test_restrict_with_error end def test_included_in_collection - assert companies(:first_firm).clients.include?(Client.find(2)) + assert_equal true, companies(:first_firm).clients.include?(Client.find(2)) end def test_included_in_collection_for_new_records client = Client.create(:name => 'Persisted') assert_nil client.client_of - assert !Firm.new.clients_of_firm.include?(client), - 'includes a client that does not belong to any firm' + assert_equal false, Firm.new.clients_of_firm.include?(client), + 'includes a client that does not belong to any firm' end def test_adding_array_and_collection @@ -1254,7 +1254,7 @@ def test_replace_with_new firm.save firm.reload assert_equal 2, firm.clients.length - assert !firm.clients.include?(:first_client) + assert_equal false, firm.clients.include?(:first_client) end def test_replace_failure @@ -1332,7 +1332,7 @@ def test_assign_ids_ignoring_blanks firm.save! assert_equal 2, firm.clients(true).size - assert firm.clients.include?(companies(:second_client)) + assert_equal true, firm.clients.include?(companies(:second_client)) end def test_get_ids_for_through @@ -1366,7 +1366,7 @@ def test_include_uses_array_include_after_loaded assert_no_queries do assert firm.clients.loaded? - assert firm.clients.include?(client) + assert_equal true, firm.clients.include?(client) end end @@ -1377,7 +1377,7 @@ def test_include_checks_if_record_exists_if_target_not_loaded firm.reload assert ! firm.clients.loaded? assert_queries(1) do - assert firm.clients.include?(client) + assert_equal true, firm.clients.include?(client) end assert ! firm.clients.loaded? end @@ -1388,7 +1388,7 @@ def test_include_loads_collection_if_target_uses_finder_sql firm.reload assert ! firm.clients_using_sql.loaded? - assert firm.clients_using_sql.include?(client) + assert_equal true, firm.clients_using_sql.include?(client) assert firm.clients_using_sql.loaded? end @@ -1398,7 +1398,7 @@ def test_include_returns_false_for_non_matching_record_to_verify_scoping client = Client.create!(:name => 'Not Associated') assert ! firm.clients.loaded? - assert ! firm.clients.include?(client) + assert_equal false, firm.clients.include?(client) end def test_calling_first_or_last_on_association_should_not_load_association @@ -1613,7 +1613,7 @@ def test_attributes_are_being_set_when_initialized_from_has_many_association_wit def test_include_method_in_has_many_association_should_return_true_for_instance_added_with_build post = Post.new comment = post.comments.build - assert post.comments.include?(comment) + assert_equal true, post.comments.include?(comment) end def test_load_target_respects_protected_attributes