diff options
author | George Ogata <george.ogata@gmail.com> | 2009-11-26 00:05:57 -0500 |
---|---|---|
committer | Eloy Duran <eloy.de.enige@gmail.com> | 2009-12-28 15:12:07 +0100 |
commit | fc85c665271578e55e7fe90a721ca1533289d923 (patch) | |
tree | c4cfa36301d29301121e24bc78dd21aa35683905 /activerecord/test | |
parent | e8ca22d129c1e93574e770dd69dc964be6686469 (diff) | |
download | rails-fc85c665271578e55e7fe90a721ca1533289d923.tar.gz rails-fc85c665271578e55e7fe90a721ca1533289d923.tar.bz2 rails-fc85c665271578e55e7fe90a721ca1533289d923.zip |
Set inverse for #replace on a has_one association. [#3513 state:resolved]
Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/inverse_associations_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index 47f83db112..ee360dff10 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -135,6 +135,21 @@ class InverseHasOneTests < ActiveRecord::TestCase assert_equal m.name, f.man.name, "Name of man should be the same after changes to newly-created-child-owned instance" end + def test_parent_instance_should_be_shared_with_replaced_child + man = Man.find(:first) + old_face = man.face + new_face = Face.new + + assert_not_nil man.face + man.face.replace(new_face) + + assert_equal man.name, new_face.man.name, "Name of man should be the same before changes to parent instance" + man.name = 'Bongo' + assert_equal man.name, new_face.man.name, "Name of man should be the same after changes to parent instance" + new_face.man.name = 'Mungo' + assert_equal man.name, new_face.man.name, "Name of man should be the same after changes to replaced-parent-owned instance" + end + def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).dirty_face } end |