Merge pull request #30215 from untidy-hair/clarify-abstract-or-not-in-tests
Clarify base_class tests on abstract STI vs concrete STI
This commit is contained in:
commit
6b632336c1
@ -99,11 +99,11 @@ def test_polymorphic_has_many_going_through_join_model_with_custom_foreign_key
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_polymorphic_has_many_create_model_with_inheritance_and_custom_base_class
|
def test_polymorphic_has_many_create_model_with_inheritance_and_custom_base_class
|
||||||
post = SubStiPost.create title: "SubStiPost", body: "SubStiPost body"
|
post = SubAbstractStiPost.create title: "SubAbstractStiPost", body: "SubAbstractStiPost body"
|
||||||
assert_instance_of SubStiPost, post
|
assert_instance_of SubAbstractStiPost, post
|
||||||
|
|
||||||
tagging = tags(:misc).taggings.create(taggable: post)
|
tagging = tags(:misc).taggings.create(taggable: post)
|
||||||
assert_equal "SubStiPost", tagging.taggable_type
|
assert_equal "SubAbstractStiPost", tagging.taggable_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_polymorphic_has_many_going_through_join_model_with_inheritance
|
def test_polymorphic_has_many_going_through_join_model_with_inheritance
|
||||||
|
@ -147,12 +147,16 @@ def test_descends_from_active_record
|
|||||||
# Concrete subclass of AR::Base.
|
# Concrete subclass of AR::Base.
|
||||||
assert Post.descends_from_active_record?
|
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.
|
# Abstract subclass of a concrete class which has a type column.
|
||||||
# This is pathological, as you'll never have Sub < Abstract < Concrete.
|
# 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.
|
# Concrete subclass of an abstract class which has a type column.
|
||||||
assert !SubStiPost.descends_from_active_record?
|
assert !SubAbstractStiPost.descends_from_active_record?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_company_descends_from_active_record
|
def test_company_descends_from_active_record
|
||||||
@ -172,7 +176,8 @@ def test_inheritance_base_class
|
|||||||
assert_equal Post, Post.base_class
|
assert_equal Post, Post.base_class
|
||||||
assert_equal Post, SpecialPost.base_class
|
assert_equal Post, SpecialPost.base_class
|
||||||
assert_equal Post, StiPost.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
|
end
|
||||||
|
|
||||||
def test_abstract_inheritance_base_class
|
def test_abstract_inheritance_base_class
|
||||||
|
@ -184,14 +184,19 @@ def self.log(message = nil, side = nil, new_record = nil)
|
|||||||
class SpecialPost < Post; end
|
class SpecialPost < Post; end
|
||||||
|
|
||||||
class StiPost < Post
|
class StiPost < Post
|
||||||
self.abstract_class = true
|
|
||||||
has_one :special_comment, class_name: "SpecialComment"
|
has_one :special_comment, class_name: "SpecialComment"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class AbstractStiPost < Post
|
||||||
|
self.abstract_class = true
|
||||||
|
end
|
||||||
|
|
||||||
class SubStiPost < StiPost
|
class SubStiPost < StiPost
|
||||||
self.table_name = Post.table_name
|
self.table_name = Post.table_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class SubAbstractStiPost < AbstractStiPost; end
|
||||||
|
|
||||||
class FirstPost < ActiveRecord::Base
|
class FirstPost < ActiveRecord::Base
|
||||||
self.inheritance_column = :disabled
|
self.inheritance_column = :disabled
|
||||||
self.table_name = "posts"
|
self.table_name = "posts"
|
||||||
|
Loading…
Reference in New Issue
Block a user