Merge pull request #27354 from Shopify/fix-constantize-and-prepended-modules
Fix constantize edge case involving prepend, autoloading and name conflicts
This commit is contained in:
commit
4ae8595ca2
@ -274,7 +274,7 @@ def constantize(camel_cased_word)
|
||||
|
||||
# Go down the ancestors to check if it is owned directly. The check
|
||||
# stops when we reach Object or the end of ancestors tree.
|
||||
constant = constant.ancestors.inject do |const, ancestor|
|
||||
constant = constant.ancestors.inject(constant) do |const, ancestor|
|
||||
break const if ancestor == Object
|
||||
break ancestor if ancestor.const_defined?(name, false)
|
||||
const
|
||||
|
8
activesupport/test/autoloading_fixtures/prepend.rb
Normal file
8
activesupport/test/autoloading_fixtures/prepend.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class SubClassConflict
|
||||
end
|
||||
|
||||
class Prepend
|
||||
module PrependedModule
|
||||
end
|
||||
prepend PrependedModule
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
class Prepend::SubClassConflict
|
||||
end
|
@ -73,6 +73,11 @@ def run_constantize_tests_on
|
||||
yield("RaisesNoMethodError")
|
||||
end
|
||||
end
|
||||
|
||||
with_autoloading_fixtures do
|
||||
yield("Prepend::SubClassConflict")
|
||||
assert_equal "constant", defined?(Prepend::SubClassConflict)
|
||||
end
|
||||
end
|
||||
|
||||
def run_safe_constantize_tests_on
|
||||
|
Loading…
Reference in New Issue
Block a user