diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-02 08:52:51 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-02 08:52:51 +0000 |
commit | 1ba1779754965da9b0cff73d37905b71928d3598 (patch) | |
tree | cbf41b720b38c412c03415cb3aecbaa60770a023 /activerecord/test | |
parent | c6cc7078544e5954a9ff181a854d77c9b9c94d5a (diff) | |
download | rails-1ba1779754965da9b0cff73d37905b71928d3598.tar.gz rails-1ba1779754965da9b0cff73d37905b71928d3598.tar.bz2 rails-1ba1779754965da9b0cff73d37905b71928d3598.zip |
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
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 20 |
1 files changed, 16 insertions, 4 deletions
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 |