From 1ba1779754965da9b0cff73d37905b71928d3598 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 2 Apr 2005 08:52:51 +0000 Subject: Added that model.items.delete(child) will delete the child, not just set the foreign key to nil, if the child is dependent on the model #978 [bitsweat] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1064 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_test.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index b35aadf4ff..c4f1022076 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -481,9 +481,21 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_dependence - assert_equal 2, Client.find_all.length + assert_equal 2, Client.find_all.size Firm.find_first.destroy - assert_equal 0, Client.find_all.length + assert Client.find_all.empty? + end + + def test_destroy_dependent_when_deleted_from_association + firm = Firm.find_first + assert_equal 2, firm.clients.size + + client = firm.clients.first + firm.clients.delete(client) + + assert_raise(ActiveRecord::RecordNotFound) { Client.find(client.id) } + assert_raise(ActiveRecord::RecordNotFound) { firm.clients.find(client.id) } + assert_equal 1, firm.clients.size end def test_three_levels_of_dependence @@ -615,7 +627,7 @@ class BelongsToAssociationsTest < Test::Unit::TestCase def test_new_record_with_foreign_key_but_no_object c = Client.new("firm_id" => 1) - assert_equal @first_firm, c.firm_with_basic_id + assert_equal Firm.find_first, c.firm_with_basic_id end def test_forgetting_the_load_when_foreign_key_enters_late @@ -623,7 +635,7 @@ class BelongsToAssociationsTest < Test::Unit::TestCase assert_nil c.firm_with_basic_id c.firm_id = 1 - assert_equal @first_firm, c.firm_with_basic_id + assert_equal Firm.find_first, c.firm_with_basic_id end def test_field_name_same_as_foreign_key -- cgit v1.2.3