Permalink
Browse files

Merge pull request #10038 from nateberkopec/sti-new-with-complex-inhe…

…ritance

Fix regression re: #new with an STI object & complex inheritance
  • Loading branch information...
2 parents 299ddbd + ab157ac commit 6fee836866ce70215247b4d1ec48730e0ff8cc7c @rafaelfranca rafaelfranca committed Apr 2, 2013
Showing with 5 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/inheritance.rb
  2. +4 −0 activerecord/test/cases/inheritance_test.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
@@ -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

0 comments on commit 6fee836

Please sign in to comment.