diff options
author | Xavier Noria <fxn@hashref.com> | 2013-06-18 00:01:22 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2013-06-18 00:01:22 -0700 |
commit | 7324624f748b9717a5f9757ca89d791563ac5f95 (patch) | |
tree | 412e8ea6799916e0ff212b63ec10af3f73c5aeff /activerecord | |
parent | cae9d063fc2c5fcd219e029b0e76ddf1fdcc666c (diff) | |
parent | 394cc6047df090233927fd1eaf21197e84d7aa37 (diff) | |
download | rails-7324624f748b9717a5f9757ca89d791563ac5f95.tar.gz rails-7324624f748b9717a5f9757ca89d791563ac5f95.tar.bz2 rails-7324624f748b9717a5f9757ca89d791563ac5f95.zip |
Merge pull request #10987 from senny/10979_association_include_returns_true
`CollectionProxy#include?` returns `true` and `false` as documented.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/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 e82c195335..7cdb5ba5b3 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -830,7 +830,7 @@ module ActiveRecord # 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 9f64ecd845..168ce13097 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 |