Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

4 participants

@nateberkopec

Test case fails on the current master branch, but works on 3-2-stable.

Calling #subclasses here only catches the direct children, which causes creating a new complex subclass to fail.

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') }

Too many spaces :smile:

@senny Owner
senny added a note

could you update to Ruby 1.9 hash syntax? On the master branch we try to stick to the 1.9 Syntax when possible.

Whoops! Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@nateberkopec

Fixed the spaces issue! :sweat_smile:

@senny
Owner

looks good to me. I think we don't need a changelog entry as it is fixing a regression only present on master.

@carlosantoniodasilva @rafaelfranca can you take another look?

@rafaelfranca rafaelfranca merged commit 6fee836 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.