diff options
author | Tobias Lütke <tobias.luetke@gmail.com> | 2005-10-15 00:46:55 +0000 |
---|---|---|
committer | Tobias Lütke <tobias.luetke@gmail.com> | 2005-10-15 00:46:55 +0000 |
commit | 70869931611667d5b732ae91704313115e4baa10 (patch) | |
tree | 27e1df63f6953b9a8484aaa1859152fa0fb2490e /activerecord/test/associations_test.rb | |
parent | 64fcb752f2c2f337918f74cd0cc6049a4cafb7a6 (diff) | |
download | rails-70869931611667d5b732ae91704313115e4baa10.tar.gz rails-70869931611667d5b732ae91704313115e4baa10.tar.bz2 rails-70869931611667d5b732ae91704313115e4baa10.zip |
Adds :nullify option to :depends. Closes #2015 (Robby Russell)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2595 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_test.rb')
-rwxr-xr-x | activerecord/test/associations_test.rb | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 5cafa010f9..bfe797b167 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -132,10 +132,11 @@ class HasOneAssociationsTest < Test::Unit::TestCase end def test_dependence + num_accounts = Account.count firm = Firm.find(1) assert !firm.account.nil? - firm.destroy - assert_equal 1, Account.count + firm.destroy + assert_equal num_accounts - 1, Account.count end def test_succesful_build_association @@ -563,7 +564,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase # Should be destroyed since the association is exclusively dependent. assert Client.find_by_id(client_id).nil? - end + end def test_deleting_a_item_which_is_not_in_the_collection force_signal37_to_load_all_clients_of_firm @@ -634,9 +635,26 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_dependence_on_account - assert_equal 2, Account.count + num_accounts = Account.count companies(:first_firm).destroy - assert_equal 1, Account.count + assert_equal num_accounts - 1, Account.count + end + + + def test_depends_and_nullify + num_accounts = Account.count + num_companies = Company.count + + core = companies(:rails_core) + assert_equal accounts(:rails_core_account), core.account + assert_equal [companies(:leetsoft), companies(:jadedpixel)], core.companies + core.destroy + assert_nil accounts(:rails_core_account).reload.firm_id + assert_nil companies(:leetsoft).reload.client_of + assert_nil companies(:jadedpixel).reload.client_of + + + assert_equal num_accounts, Account.count end def test_included_in_collection @@ -658,7 +676,8 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert firm.save, "Could not save firm" firm.reload assert_equal 1, firm.clients.length - end + end + def test_replace_with_new firm = Firm.find(:first) |