Skip to content

Commit

Permalink
Added back support for destroying an association's object by id. [#2306
Browse files Browse the repository at this point in the history
… status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
technicalpickles authored and lifo committed Aug 9, 2009
1 parent ae47f75 commit 0ec64be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Expand Up @@ -208,6 +208,7 @@ def delete(*records)
# Note that this method will _always_ remove records from the database
# ignoring the +:dependent+ option.
def destroy(*records)
records = find(records) if records.any? {|record| record.kind_of?(Fixnum) || record.kind_of?(String)}
remove_records(records) do |records, old_records|
old_records.each { |record| record.destroy }
end
Expand Down
22 changes: 22 additions & 0 deletions activerecord/test/cases/associations/has_many_associations_test.rb
Expand Up @@ -699,6 +699,28 @@ def test_destroying
assert_equal 0, companies(:first_firm).clients_of_firm(true).size
end

def test_destroying_by_fixnum_id
force_signal37_to_load_all_clients_of_firm

assert_difference "Client.count", -1 do
companies(:first_firm).clients_of_firm.destroy(companies(:first_firm).clients_of_firm.first.id)
end

assert_equal 0, companies(:first_firm).reload.clients_of_firm.size
assert_equal 0, companies(:first_firm).clients_of_firm(true).size
end

def test_destroying_by_string_id
force_signal37_to_load_all_clients_of_firm

assert_difference "Client.count", -1 do
companies(:first_firm).clients_of_firm.destroy(companies(:first_firm).clients_of_firm.first.id.to_s)
end

assert_equal 0, companies(:first_firm).reload.clients_of_firm.size
assert_equal 0, companies(:first_firm).clients_of_firm(true).size
end

def test_destroying_a_collection
force_signal37_to_load_all_clients_of_firm
companies(:first_firm).clients_of_firm.create("name" => "Another Client")
Expand Down

0 comments on commit 0ec64be

Please sign in to comment.