From ac715b2bcbc1dee525339edec86362261e017bbe Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 2 Nov 2006 09:45:17 +0000 Subject: has_one :dependent => :nullify ignores nil associates. Closes #6528. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5401 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_test.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'activerecord/test/associations_test.rb') diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 0be63fccbf..f1b02cfda5 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -184,11 +184,13 @@ class HasOneAssociationsTest < Test::Unit::TestCase def test_dependence num_accounts = Account.count + firm = Firm.find(1) assert !firm.account.nil? account_id = firm.account.id assert_equal [], Account.destroyed_account_ids[firm.id] - firm.destroy + + firm.destroy assert_equal num_accounts - 1, Account.count assert_equal [account_id], Account.destroyed_account_ids[firm.id] end @@ -201,15 +203,23 @@ class HasOneAssociationsTest < Test::Unit::TestCase def test_exclusive_dependence num_accounts = Account.count + firm = ExclusivelyDependentFirm.find(9) assert !firm.account.nil? account_id = firm.account.id assert_equal [], Account.destroyed_account_ids[firm.id] + firm.destroy assert_equal num_accounts - 1, Account.count assert_equal [], Account.destroyed_account_ids[firm.id] end + def test_dependence_with_nil_associate + firm = DependentFirm.new(:name => 'nullify') + firm.save! + assert_nothing_raised { firm.destroy } + end + def test_succesful_build_association firm = Firm.new("name" => "GlobalMegaCorp") firm.save -- cgit v1.2.3