From 40afcade0dc1450e765a91fc15a6ac6d442c9826 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 3 Jan 2011 23:48:53 +0000 Subject: Remove undocumented feature from has_one where you could pass false as the second parameter to build_assoc or create_assoc, and the existing associated object would be untouched (the foreign key would not be nullified, and it would not be deleted). If you want behaviour similar to this you can do the following things: * Use :dependent => :nullify (or don't specify :dependent) if you want to prevent the existing associated object from being deleted * Use has_many if you actually want multiple associated objects * Explicitly set the foreign key if, for some reason, you really need to have multiple objects associated with the same has_one. E.g. previous = obj.assoc obj.create_assoc previous.update_attributes(:obj_id => obj.id) --- .../test/cases/associations/inverse_associations_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'activerecord/test/cases/associations/inverse_associations_test.rb') diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index 0491b2d1fa..a0f94a22e3 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -146,9 +146,9 @@ 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_newly_built_child_when_we_dont_replace_existing + def test_parent_instance_should_be_shared_with_newly_built_child m = Man.find(:first) - f = m.build_face({:description => 'haunted'}, false) + f = m.build_face(:description => 'haunted') assert_not_nil f.man assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" m.name = 'Bongo' @@ -157,9 +157,9 @@ class InverseHasOneTests < ActiveRecord::TestCase assert_equal m.name, f.man.name, "Name of man should be the same after changes to just-built-child-owned instance" end - def test_parent_instance_should_be_shared_with_newly_created_child_when_we_dont_replace_existing + def test_parent_instance_should_be_shared_with_newly_created_child m = Man.find(:first) - f = m.create_face({:description => 'haunted'}, false) + f = m.create_face(:description => 'haunted') assert_not_nil f.man assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" m.name = 'Bongo' @@ -168,9 +168,9 @@ 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_newly_created_child_via_bang_method_when_we_dont_replace_existing + def test_parent_instance_should_be_shared_with_newly_created_child_via_bang_method m = Man.find(:first) - f = m.face.create!({:description => 'haunted'}, false) + f = m.face.create!(:description => 'haunted') assert_not_nil f.man assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" m.name = 'Bongo' @@ -203,7 +203,7 @@ class InverseHasOneTests < ActiveRecord::TestCase assert_equal m.name, f.man.name, "Name of man should be the same after changes to replaced-child-owned instance" end - def test_parent_instance_should_be_shared_with_replaced_via_method_child_when_we_dont_replace_existing + def test_parent_instance_should_be_shared_with_replaced_via_method_child m = Man.find(:first) f = Face.new(:description => 'haunted') m.face.replace(f, false) -- cgit v1.2.3 From 3f4143eedb3ec1c8e55bfc1ea0083fbb35749659 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 4 Jan 2011 15:16:56 -0800 Subject: fixing merge errors --- .../associations/inverse_associations_test.rb | 67 ---------------------- 1 file changed, 67 deletions(-) (limited to 'activerecord/test/cases/associations/inverse_associations_test.rb') diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index a0f94a22e3..4cca78da9d 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -113,39 +113,6 @@ class InverseHasOneTests < ActiveRecord::TestCase assert_equal m.name, f.man.name, "Name of man should be the same after changes to child-owned instance" end - def test_parent_instance_should_be_shared_with_newly_built_child - m = men(:gordon) - f = m.build_face(:description => 'haunted') - assert_not_nil f.man - assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" - m.name = 'Bongo' - assert_equal m.name, f.man.name, "Name of man should be the same after changes to parent instance" - f.man.name = 'Mungo' - assert_equal m.name, f.man.name, "Name of man should be the same after changes to just-built-child-owned instance" - end - - def test_parent_instance_should_be_shared_with_newly_created_child - m = men(:gordon) - f = m.create_face(:description => 'haunted') - assert_not_nil f.man - assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" - m.name = 'Bongo' - assert_equal m.name, f.man.name, "Name of man should be the same after changes to parent instance" - f.man.name = 'Mungo' - 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_newly_created_child_via_bang_method - m = Man.find(:first) - f = m.face.create!(:description => 'haunted') - assert_not_nil f.man - assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" - m.name = 'Bongo' - assert_equal m.name, f.man.name, "Name of man should be the same after changes to parent instance" - f.man.name = 'Mungo' - 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_newly_built_child m = Man.find(:first) f = m.build_face(:description => 'haunted') @@ -191,18 +158,6 @@ class InverseHasOneTests < ActiveRecord::TestCase assert_equal m.name, f.man.name, "Name of man should be the same after changes to replaced-child-owned instance" end - def test_parent_instance_should_be_shared_with_replaced_via_method_child - m = Man.find(:first) - f = Face.new(:description => 'haunted') - m.face.replace(f) - assert_not_nil f.man - assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" - m.name = 'Bongo' - assert_equal m.name, f.man.name, "Name of man should be the same after changes to parent instance" - f.man.name = 'Mungo' - assert_equal m.name, f.man.name, "Name of man should be the same after changes to replaced-child-owned instance" - end - def test_parent_instance_should_be_shared_with_replaced_via_method_child m = Man.find(:first) f = Face.new(:description => 'haunted') @@ -257,17 +212,6 @@ class InverseHasManyTests < ActiveRecord::TestCase end end - def test_parent_instance_should_be_shared_with_newly_built_child - m = men(:gordon) - i = m.interests.build(:topic => 'Industrial Revolution Re-enactment') - assert_not_nil i.man - assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance" - m.name = 'Bongo' - assert_equal m.name, i.man.name, "Name of man should be the same after changes to parent instance" - i.man.name = 'Mungo' - assert_equal m.name, i.man.name, "Name of man should be the same after changes to just-built-child-owned instance" - end - def test_parent_instance_should_be_shared_with_newly_block_style_built_child m = Man.find(:first) i = m.interests.build {|ii| ii.topic = 'Industrial Revolution Re-enactment'} @@ -280,17 +224,6 @@ class InverseHasManyTests < ActiveRecord::TestCase assert_equal m.name, i.man.name, "Name of man should be the same after changes to just-built-child-owned instance" end - def test_parent_instance_should_be_shared_with_newly_created_child - m = men(:gordon) - i = m.interests.create(:topic => 'Industrial Revolution Re-enactment') - assert_not_nil i.man - assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance" - m.name = 'Bongo' - assert_equal m.name, i.man.name, "Name of man should be the same after changes to parent instance" - i.man.name = 'Mungo' - assert_equal m.name, i.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_newly_created_via_bang_method_child m = Man.find(:first) i = m.interests.create!(:topic => 'Industrial Revolution Re-enactment') -- cgit v1.2.3 From 5b28e5254267c581ce6934408aaf458616e44e3f Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 6 Jan 2011 19:54:23 +0000 Subject: Don't not remove double negatives --- activerecord/test/cases/associations/inverse_associations_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/associations/inverse_associations_test.rb') diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index 4cca78da9d..e9a57a00a0 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -161,7 +161,7 @@ class InverseHasOneTests < ActiveRecord::TestCase def test_parent_instance_should_be_shared_with_replaced_via_method_child m = Man.find(:first) f = Face.new(:description => 'haunted') - m.face.replace(f, false) + m.face.replace(f) assert_not_nil f.man assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" m.name = 'Bongo' -- cgit v1.2.3