Clarify base_class tests on abstract STI vs concrete STI
This commit is contained in:
parent
98360a96cc
commit
25cb200cb7
@ -99,11 +99,11 @@ def test_polymorphic_has_many_going_through_join_model_with_custom_foreign_key
|
||||
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
|
||||
|
@ -147,12 +147,16 @@ def test_descends_from_active_record
|
||||
# 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 @@ def test_inheritance_base_class
|
||||
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
|
||||
|
@ -184,14 +184,19 @@ def self.log(message = nil, side = nil, new_record = nil)
|
||||
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"
|
||||
|
Loading…
Reference in New Issue
Block a user