diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-18 11:07:03 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-18 11:07:03 +0000 |
commit | bce0e1493024ccfe78efc93da14740a8d503cb7c (patch) | |
tree | f6619f94f9cfa1742eeb0f2acada7b68be27b523 /activerecord/test | |
parent | 652f1ef02fdf75e8e971971707b3d5861d06b8be (diff) | |
download | rails-bce0e1493024ccfe78efc93da14740a8d503cb7c.tar.gz rails-bce0e1493024ccfe78efc93da14740a8d503cb7c.tar.bz2 rails-bce0e1493024ccfe78efc93da14740a8d503cb7c.zip |
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
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 27 |
1 files changed, 22 insertions, 5 deletions
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 |