aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-02-26 05:15:22 +0900
committerGitHub <noreply@github.com>2018-02-26 05:15:22 +0900
commit91b30a001b79096b60d9424a4664a417dce0b767 (patch)
treeef0ce40e074e30e4674a4b4c0f776bbc9a444c36 /activerecord/test/cases
parent8ff70cad3d634da344d741c49304a69572cbe188 (diff)
parent1af039dd3dfd68f40dc37b9a75b0d8a3dc8b1efe (diff)
downloadrails-91b30a001b79096b60d9424a4664a417dce0b767.tar.gz
rails-91b30a001b79096b60d9424a4664a417dce0b767.tar.bz2
rails-91b30a001b79096b60d9424a4664a417dce0b767.zip
Merge pull request #31895 from kamipo/do_not_attempt_to_find_inverse_of_polymorphic
Make `reflection.klass` raise if `polymorphic?` not to be misused
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/inverse_associations_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb
index bad1bcdb67..896bf574f4 100644
--- a/activerecord/test/cases/associations/inverse_associations_test.rb
+++ b/activerecord/test/cases/associations/inverse_associations_test.rb
@@ -190,6 +190,16 @@ class InverseAssociationTests < ActiveRecord::TestCase
assert_nil belongs_to_ref.inverse_of
end
+ def test_polymorphic_associations_dont_attempt_to_find_inverse_of
+ belongs_to_ref = Sponsor.reflect_on_association(:sponsor)
+ assert_raise(ArgumentError) { belongs_to_ref.klass }
+ assert_nil belongs_to_ref.inverse_of
+
+ belongs_to_ref = Face.reflect_on_association(:human)
+ assert_raise(ArgumentError) { belongs_to_ref.klass }
+ assert_nil belongs_to_ref.inverse_of
+ end
+
def test_this_inverse_stuff
firm = Firm.create!(name: "Adequate Holdings")
Project.create!(name: "Project 1", firm: firm)