Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #10987 from senny/10979_association_include_return…

…s_true

`CollectionProxy#include?` returns `true` and `false` as documented.
  • Loading branch information...
commit 7324624f748b9717a5f9757ca89d791563ac5f95 2 parents cae9d06 + 394cc60
@fxn fxn authored
View
2  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
View
22 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
Please sign in to comment.
Something went wrong with that request. Please try again.