diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-08-14 18:22:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-14 18:22:11 -0400 |
commit | 6b632336c172ea397bb1386ff44c2e8320672cb4 (patch) | |
tree | 9ab46ece0d7742f79c5eb6ee8b52947f20d16d20 /activerecord | |
parent | cf91b96be3ff4aafd0ec29f5c34013792bddf33d (diff) | |
parent | 25cb200cb7ec91f3ef51ff7bf3fb32cd82d4a33a (diff) | |
download | rails-6b632336c172ea397bb1386ff44c2e8320672cb4.tar.gz rails-6b632336c172ea397bb1386ff44c2e8320672cb4.tar.bz2 rails-6b632336c172ea397bb1386ff44c2e8320672cb4.zip |
Merge pull request #30215 from untidy-hair/clarify-abstract-or-not-in-tests
Clarify base_class tests on abstract STI vs concrete STI
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/associations/join_model_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 13 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 7 |
3 files changed, 18 insertions, 8 deletions
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 9d3d5353ff..3abdcf3564 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -99,11 +99,11 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_polymorphic_has_many_create_model_with_inheritance_and_custom_base_class - post = SubStiPost.create title: "SubStiPost", body: "SubStiPost body" - assert_instance_of SubStiPost, post + post = SubAbstractStiPost.create title: "SubAbstractStiPost", body: "SubAbstractStiPost body" + assert_instance_of SubAbstractStiPost, post tagging = tags(:misc).taggings.create(taggable: post) - assert_equal "SubStiPost", tagging.taggable_type + assert_equal "SubAbstractStiPost", tagging.taggable_type end def test_polymorphic_has_many_going_through_join_model_with_inheritance diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index a263106f6d..c931f7d21c 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -147,12 +147,16 @@ class InheritanceTest < ActiveRecord::TestCase # Concrete subclass of AR::Base. assert Post.descends_from_active_record? + # Concrete subclasses of a concrete class which has a type column. + assert !StiPost.descends_from_active_record? + assert !SubStiPost.descends_from_active_record? + # Abstract subclass of a concrete class which has a type column. # This is pathological, as you'll never have Sub < Abstract < Concrete. - assert !StiPost.descends_from_active_record? + assert !AbstractStiPost.descends_from_active_record? - # Concrete subclasses an abstract class which has a type column. - assert !SubStiPost.descends_from_active_record? + # Concrete subclass of an abstract class which has a type column. + assert !SubAbstractStiPost.descends_from_active_record? end def test_company_descends_from_active_record @@ -172,7 +176,8 @@ class InheritanceTest < ActiveRecord::TestCase assert_equal Post, Post.base_class assert_equal Post, SpecialPost.base_class assert_equal Post, StiPost.base_class - assert_equal SubStiPost, SubStiPost.base_class + assert_equal Post, SubStiPost.base_class + assert_equal SubAbstractStiPost, SubAbstractStiPost.base_class end def test_abstract_inheritance_base_class diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 4b3576fce8..4c8e847354 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -184,14 +184,19 @@ end class SpecialPost < Post; end class StiPost < Post - self.abstract_class = true has_one :special_comment, class_name: "SpecialComment" end +class AbstractStiPost < Post + self.abstract_class = true +end + class SubStiPost < StiPost self.table_name = Post.table_name end +class SubAbstractStiPost < AbstractStiPost; end + class FirstPost < ActiveRecord::Base self.inheritance_column = :disabled self.table_name = "posts" |