Skip to content

Commit

Permalink
CollectionProxy#include? returns true and false as documented.
Browse files Browse the repository at this point in the history
  • Loading branch information
senny committed Jun 18, 2013
1 parent 0051998 commit 394cc60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions activerecord/test/cases/associations/has_many_associations_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 394cc60

Please sign in to comment.