diff options
author | Fabian Schwahn <fabian.schwahn@gmail.com> | 2017-04-20 11:10:06 +0200 |
---|---|---|
committer | Fabian Schwahn <fabian.schwahn@gmail.com> | 2017-04-20 11:10:06 +0200 |
commit | c2120582e4d27d2a64131820a46392af60f1e8b6 (patch) | |
tree | 9a43f880a072d884553917a6aae45c0298c2690a /activerecord/test/cases | |
parent | dc47c2be4eb28a92e7fc0f2195b81ed453b8245d (diff) | |
download | rails-c2120582e4d27d2a64131820a46392af60f1e8b6.tar.gz rails-c2120582e4d27d2a64131820a46392af60f1e8b6.tar.bz2 rails-c2120582e4d27d2a64131820a46392af60f1e8b6.zip |
Add regression test for setting inverse instances on normal & polymorphic relationships when building objects on new records
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index e2f044c139..40a0bea91b 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -241,6 +241,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal "defaulty", bulb.name end + def test_build_from_association_sets_inverse_instance + car = Car.new(name: "honda") + + bulb = car.bulbs.build + assert_equal car, bulb.car + end + def test_do_not_call_callbacks_for_delete_all car = Car.create(name: "honda") car.funky_bulbs.create! @@ -2146,6 +2153,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal "Post", tagging.taggable_type end + def test_build_from_polymorphic_association_sets_inverse_instance + post = Post.new + tagging = post.taggings.build + + assert_equal post, tagging.taggable + end + def test_dont_call_save_callbacks_twice_on_has_many firm = companies(:first_firm) contract = firm.contracts.create! |