diff options
author | Matthew Draper <matthew@trebex.net> | 2017-07-01 22:12:54 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-01 22:12:54 +0930 |
commit | 3acc3767c103e1a2a5de4d262d166f447f537e0f (patch) | |
tree | 48efb0c665bd556e69463dd4ab6150a3b9ee2b6e /activerecord/test/cases | |
parent | 4fd4d369f7351b880d9165af571b49ed23e3c5c8 (diff) | |
parent | c2120582e4d27d2a64131820a46392af60f1e8b6 (diff) | |
download | rails-3acc3767c103e1a2a5de4d262d166f447f537e0f.tar.gz rails-3acc3767c103e1a2a5de4d262d166f447f537e0f.tar.bz2 rails-3acc3767c103e1a2a5de4d262d166f447f537e0f.zip |
Merge pull request #28808 from fschwahn/fix-polymorphic-automic-inverse
Fix automatic inverse for polymorphic interfaces
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 14 | ||||
-rw-r--r-- | activerecord/test/cases/associations/inverse_associations_test.rb | 8 |
2 files changed, 16 insertions, 6 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index a936017ae3..84c359f2f0 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! @@ -2175,6 +2182,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! diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb index 467cc73ecd..8e3087e7ca 100644 --- a/activerecord/test/cases/associations/inverse_associations_test.rb +++ b/activerecord/test/cases/associations/inverse_associations_test.rb @@ -116,15 +116,11 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase assert !club_reflection.has_inverse?, "A has_many_through association should not find an inverse automatically" end - def test_polymorphic_relationships_should_still_not_have_inverses_when_non_polymorphic_relationship_has_the_same_name + def test_polymorphic_has_one_should_find_inverse_automatically man_reflection = Man.reflect_on_association(:polymorphic_face_without_inverse) - face_reflection = Face.reflect_on_association(:man) - - assert_respond_to face_reflection, :has_inverse? - assert face_reflection.has_inverse?, "For this test, the non-polymorphic association must have an inverse" assert_respond_to man_reflection, :has_inverse? - assert !man_reflection.has_inverse?, "The target of a polymorphic association should not find an inverse automatically" + assert man_reflection.has_inverse? end end |