mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
invalid sti error message contains the full class name.
This can resolve confusing situation when a top level constant exists but a namespaced version is identified. Related to #19531.
This commit is contained in:
parent
15354b6fd0
commit
f7881d3e2b
2 changed files with 12 additions and 1 deletions
|
@ -203,7 +203,7 @@ module ActiveRecord
|
|||
|
||||
if subclass.name != self.name
|
||||
unless descendants.include?(subclass)
|
||||
raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{name}")
|
||||
raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass.name} is not a subclass of #{name}")
|
||||
end
|
||||
|
||||
subclass
|
||||
|
|
|
@ -213,6 +213,17 @@ class InheritanceTest < ActiveRecord::TestCase
|
|||
assert_raise(ActiveRecord::SubclassNotFound) { Company.new(:type => 'Account') }
|
||||
end
|
||||
|
||||
def test_new_with_unrelated_namespaced_type
|
||||
without_store_full_sti_class do
|
||||
e = assert_raises ActiveRecord::SubclassNotFound do
|
||||
Namespaced::Company.new(type: 'Firm')
|
||||
end
|
||||
|
||||
assert_equal "Invalid single-table inheritance type: Namespaced::Firm is not a subclass of Namespaced::Company", e.message
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_new_with_complex_inheritance
|
||||
assert_nothing_raised { Client.new(type: 'VerySpecialClient') }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue