aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-10-15 18:44:11 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-10-15 18:44:11 -0300
commit1130b5d38904a19966508154023fca5df7eecaab (patch)
treee26dee6ecebf7f820682a1fefba8cfc447483e75 /activerecord/test
parentba769cc4836cd909fd6dd659220790d9b98e4072 (diff)
parentf260f9cd294f33301a4971e44a25cccdd95273d6 (diff)
downloadrails-1130b5d38904a19966508154023fca5df7eecaab.tar.gz
rails-1130b5d38904a19966508154023fca5df7eecaab.tar.bz2
rails-1130b5d38904a19966508154023fca5df7eecaab.zip
Merge pull request #17267 from rebyn/master
Raise an error for has_one associations which try to go :through a polymorphic association
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_one_through_associations_test.rb6
-rw-r--r--activerecord/test/models/member.rb3
2 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb
index 089cb0a3a2..19d1aa87a8 100644
--- a/activerecord/test/cases/associations/has_one_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb
@@ -289,6 +289,12 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_has_one_through_polymorphic_association
+ assert_raise(ActiveRecord::HasOneAssociationPolymorphicThroughError) do
+ @member.premium_club
+ end
+ end
+
def test_has_one_through_belongs_to_should_update_when_the_through_foreign_key_changes
minivan = minivans(:cool_first)
diff --git a/activerecord/test/models/member.rb b/activerecord/test/models/member.rb
index 72095f9236..dc0566d8a7 100644
--- a/activerecord/test/models/member.rb
+++ b/activerecord/test/models/member.rb
@@ -27,6 +27,9 @@ class Member < ActiveRecord::Base
has_many :clubs, :through => :current_memberships
has_one :club_through_many, :through => :current_memberships, :source => :club
+
+ belongs_to :admittable, polymorphic: true
+ has_one :premium_club, through: :admittable
end
class SelfMember < ActiveRecord::Base