diff options
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 31 | ||||
-rwxr-xr-x | activerecord/test/deprecated_associations_test.rb | 11 | ||||
-rw-r--r-- | activerecord/test/fixtures/accounts.yml | 5 | ||||
-rw-r--r-- | activerecord/test/fixtures/companies.yml | 12 | ||||
-rwxr-xr-x | activerecord/test/fixtures/company.rb | 8 | ||||
-rwxr-xr-x | activerecord/test/inheritance_test.rb | 2 |
6 files changed, 56 insertions, 13 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) diff --git a/activerecord/test/deprecated_associations_test.rb b/activerecord/test/deprecated_associations_test.rb index 1d5908d774..d96a587dc0 100755 --- a/activerecord/test/deprecated_associations_test.rb +++ b/activerecord/test/deprecated_associations_test.rb @@ -79,10 +79,11 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase end def test_has_one_dependence + num_accounts = Account.count firm = Firm.find(1) assert firm.has_account? - firm.destroy - assert_equal 1, Account.find_all.length + firm.destroy + assert_equal num_accounts - 1, Account.count end def test_has_one_dependence_with_missing_association @@ -124,10 +125,10 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase assert !Account.find(2).firm?(companies(:first_firm)), "Unknown isn't linked" end - def test_has_many_dependence_on_account - assert_equal 2, Account.find_all.length + def test_has_many_dependence_on_account + num_accounts = Account.count companies(:first_firm).destroy - assert_equal 1, Account.find_all.length + assert_equal num_accounts - 1, Account.count end def test_find_in diff --git a/activerecord/test/fixtures/accounts.yml b/activerecord/test/fixtures/accounts.yml index 21a0aab52a..8cff4389fd 100644 --- a/activerecord/test/fixtures/accounts.yml +++ b/activerecord/test/fixtures/accounts.yml @@ -6,3 +6,8 @@ signals37: unknown: id: 2 credit_limit: 50 + +rails_core_account: + id: 3 + firm_id: 6 + credit_limit: 50 diff --git a/activerecord/test/fixtures/companies.yml b/activerecord/test/fixtures/companies.yml index 7d13bc6b75..29b949e16b 100644 --- a/activerecord/test/fixtures/companies.yml +++ b/activerecord/test/fixtures/companies.yml @@ -33,3 +33,15 @@ another_client: client_of: 4 name: Ex Nihilo ruby_type: Client + +rails_core: + id: 6 + type: DependentFirm + +leetsoft: + id: 7 + client_of: 6 + +jadedpixel: + id: 8 + client_of: 6
\ No newline at end of file diff --git a/activerecord/test/fixtures/company.rb b/activerecord/test/fixtures/company.rb index 748d43eb2e..4a0c96bdd3 100755 --- a/activerecord/test/fixtures/company.rb +++ b/activerecord/test/fixtures/company.rb @@ -27,6 +27,12 @@ class Firm < Company has_one :account, :foreign_key => "firm_id", :dependent => true end +class DependentFirm < Company + has_one :account, :foreign_key => "firm_id", :dependent => :nullify + has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify +end + + class Client < Company belongs_to :firm, :foreign_key => "client_of" belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id" @@ -62,4 +68,4 @@ class Account < ActiveRecord::Base def validate errors.add_on_empty "credit_limit" end -end +end
\ No newline at end of file diff --git a/activerecord/test/inheritance_test.rb b/activerecord/test/inheritance_test.rb index 11a2c3d7a9..a3b9ce25ad 100755 --- a/activerecord/test/inheritance_test.rb +++ b/activerecord/test/inheritance_test.rb @@ -57,7 +57,7 @@ class InheritanceTest < Test::Unit::TestCase end def test_inheritance_condition - assert_equal 5, Company.count + assert_equal 8, Company.count assert_equal 2, Firm.count assert_equal 3, Client.count end |