Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix #new with an STI object with complex inheritance

  • Loading branch information...
commit ab157ac6bef3e1aa9c3a221011c5dd7024f14d7e 1 parent abad4f7
@nateberkopec authored
View
2  activerecord/lib/active_record/inheritance.rb
@@ -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
View
4 activerecord/test/cases/inheritance_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.