From bce0e1493024ccfe78efc93da14740a8d503cb7c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 18 Jan 2005 11:07:03 +0000 Subject: Fixed that the belongs_to and has_one proxy would fail a test like 'if project.manager' -- this unfortunately also means that you can't call methods like project.manager.build unless there already is a manager on the project #492 [Tim Bates] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@456 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_test.rb | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 6ed550a730..0e992526bc 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -105,7 +105,7 @@ class HasOneAssociationsTest < Test::Unit::TestCase firm = Firm.new("name" => "GlobalMegaCorp") firm.save - account = firm.account.build("credit_limit" => 1000) + firm.account = account = Account.new("credit_limit" => 1000) assert_equal account, firm.account assert account.save assert_equal account, firm.account @@ -125,7 +125,7 @@ class HasOneAssociationsTest < Test::Unit::TestCase def test_build_before_either_saved firm = Firm.new("name" => "GlobalMegaCorp") - account = firm.account.build("credit_limit" => 1000) + firm.account = account = Account.new("credit_limit" => 1000) assert_equal account, firm.account assert account.new_record? assert firm.save @@ -137,7 +137,7 @@ class HasOneAssociationsTest < Test::Unit::TestCase firm = Firm.new("name" => "GlobalMegaCorp") firm.save - account = firm.account.build + firm.account = account = Account.new assert_equal account, firm.account assert !account.save assert_equal account, firm.account @@ -147,12 +147,14 @@ class HasOneAssociationsTest < Test::Unit::TestCase def test_create firm = Firm.new("name" => "GlobalMegaCorp") firm.save - assert_equal firm.account.create("credit_limit" => 1000), firm.account + firm.account = account = Account.create("credit_limit" => 1000) + assert_equal account, firm.account end def test_create_before_save firm = Firm.new("name" => "GlobalMegaCorp") - assert_equal firm.account.create("credit_limit" => 1000), firm.account + firm.account = account = Account.create("credit_limit" => 1000) + assert_equal account, firm.account end def test_dependence_with_missing_association @@ -243,6 +245,21 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert_equal 1, Firm.find_first.clients_using_counter_sql.size assert_equal 0, Firm.find_first.clients_using_zero_counter_sql.size end + + def test_belongs_to_sanity + c = Client.new + assert_nil c.firm + + if c.firm + assert false, "belongs_to failed if check" + end + + unless c.firm + else + assert false, "belongs_to failed unless check" + end + + end def test_find_ids firm = Firm.find_first -- cgit v1.2.3