Fix regression re: #new with an STI object & complex inheritance #10038

Merged
merged 1 commit into from Apr 2, 2013
Jump to file or symbol
Failed to load files and symbols.
+5 −1
Diff settings

Always

Just for now

@@ -174,7 +174,7 @@ def subclass_from_attrs(attrs)
if subclass_name.present? && subclass_name != self.name
subclass = subclass_name.safe_constantize
- unless subclasses.include?(subclass)
+ unless descendants.include?(subclass)
raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{name}")
end
@@ -194,6 +194,10 @@ def test_new_with_unrelated_type
assert_raise(ActiveRecord::SubclassNotFound) { Company.new(:type => 'Account') }
end
+ def test_new_with_complex_inheritance
+ assert_nothing_raised { Client.new(type: 'VerySpecialClient') }
+ end
+
def test_new_with_autoload_paths
path = File.expand_path('../../models/autoloadable', __FILE__)
ActiveSupport::Dependencies.autoload_paths << path