aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYukio Mizuta <untidyhair@gmail.com>2017-08-12 10:29:27 -0700
committerYukio Mizuta <untidyhair@gmail.com>2017-08-12 11:04:01 -0700
commit25cb200cb7ec91f3ef51ff7bf3fb32cd82d4a33a (patch)
treea3db6d34c6af66526179bff6b190d43b645f1a89
parent98360a96cc1e0bb6ab9eb31f421a36439e66eefc (diff)
downloadrails-25cb200cb7ec91f3ef51ff7bf3fb32cd82d4a33a.tar.gz
rails-25cb200cb7ec91f3ef51ff7bf3fb32cd82d4a33a.tar.bz2
rails-25cb200cb7ec91f3ef51ff7bf3fb32cd82d4a33a.zip
Clarify base_class tests on abstract STI vs concrete STI
-rw-r--r--activerecord/test/cases/associations/join_model_test.rb6
-rw-r--r--activerecord/test/cases/inheritance_test.rb13
-rw-r--r--activerecord/test/models/post.rb7
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"