diff options
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 37 | ||||
-rwxr-xr-x | activerecord/test/deprecated_associations_test.rb | 24 |
2 files changed, 37 insertions, 24 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 71e2ab01f8..6cca750644 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -105,6 +105,30 @@ class HasOneAssociationsTest < Test::Unit::TestCase assert_equal 1, Account.find_all.length end + def test_succesful_build_association + firm = Firm.new("name" => "GlobalMegaCorp") + firm.save + + account = firm.build_account("credit_limit" => 1000) + assert account.save + assert_equal account, firm.account + end + + def test_failing_build_association + firm = Firm.new("name" => "GlobalMegaCorp") + firm.save + + account = firm.build_account + assert !account.save + assert_equal "can't be empty", account.errors.on("credit_limit") + end + + def test_create_association + firm = Firm.new("name" => "GlobalMegaCorp") + firm.save + assert_equal firm.create_account("credit_limit" => 1000), firm.account + end + def test_build firm = Firm.new("name" => "GlobalMegaCorp") firm.save @@ -563,6 +587,19 @@ class BelongsToAssociationsTest < Test::Unit::TestCase assert_equal apple.id, citibank.firm_id end + def test_creating_the_belonging_object + citibank = Account.create("credit_limit" => 10) + apple = citibank.create_firm("name" => "Apple") + assert_equal apple, citibank.firm + end + + def test_building_the_belonging_object + citibank = Account.create("credit_limit" => 10) + apple = citibank.build_firm("name" => "Apple") + citibank.save + assert_equal apple.id, citibank.firm_id + end + def test_natural_assignment_to_nil client = Client.find(3) client.firm = nil diff --git a/activerecord/test/deprecated_associations_test.rb b/activerecord/test/deprecated_associations_test.rb index 49387ec8dc..4c2c62b8bd 100755 --- a/activerecord/test/deprecated_associations_test.rb +++ b/activerecord/test/deprecated_associations_test.rb @@ -174,30 +174,6 @@ class DeprecatedAssociationsTest < Test::Unit::TestCase assert_equal @signals37.create_in_clients_of_firm("name" => "Another Client"), @signals37.clients_of_firm(true).last end - def test_succesful_build_association - firm = Firm.new("name" => "GlobalMegaCorp") - firm.save - - account = firm.build_account("credit_limit" => 1000) - assert account.save - assert_equal account, firm.account - end - - def test_failing_build_association - firm = Firm.new("name" => "GlobalMegaCorp") - firm.save - - account = firm.build_account - assert !account.save - assert_equal "can't be empty", account.errors.on("credit_limit") - end - - def test_create_association - firm = Firm.new("name" => "GlobalMegaCorp") - firm.save - assert_equal firm.create_account("credit_limit" => 1000), firm.account - end - def test_has_and_belongs_to_many david = Developer.find(1) assert david.has_projects? |