aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/inverse_associations_test.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2013-04-05 05:57:27 -0700
committerJon Leighton <j@jonathanleighton.com>2013-04-05 05:57:27 -0700
commit685cf144a9b7171160d6ac71da993349d1b0eda8 (patch)
tree6ebd80481a4f47de75181aaa657748c223910507 /activerecord/test/cases/associations/inverse_associations_test.rb
parentbab0e2804d1c061bf639e2fb01ffc27b9e98384e (diff)
parent448381593edf0b87e3afd4945bd13650a7483b17 (diff)
downloadrails-685cf144a9b7171160d6ac71da993349d1b0eda8.tar.gz
rails-685cf144a9b7171160d6ac71da993349d1b0eda8.tar.bz2
rails-685cf144a9b7171160d6ac71da993349d1b0eda8.zip
Merge pull request #9996 from mikz/master
Association with inverse_of does not set the parent in association building block
Diffstat (limited to 'activerecord/test/cases/associations/inverse_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/inverse_associations_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb
index 85d0ad0aa1..ec128acf28 100644
--- a/activerecord/test/cases/associations/inverse_associations_test.rb
+++ b/activerecord/test/cases/associations/inverse_associations_test.rb
@@ -235,6 +235,22 @@ class InverseHasManyTests < ActiveRecord::TestCase
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_within_create_block_of_new_child
+ man = Man.first
+ interest = man.interests.build do |i|
+ assert i.man.equal?(man), "Man of child should be the same instance as a parent"
+ end
+ assert interest.man.equal?(man), "Man of the child should still be the same instance as a parent"
+ end
+
+ def test_parent_instance_should_be_shared_within_build_block_of_new_child
+ man = Man.first
+ interest = man.interests.build do |i|
+ assert i.man.equal?(man), "Man of child should be the same instance as a parent"
+ end
+ assert interest.man.equal?(man), "Man of the child should still be the same instance as a parent"
+ end
+
def test_parent_instance_should_be_shared_with_poked_in_child
m = men(:gordon)
i = Interest.create(:topic => 'Industrial Revolution Re-enactment')