Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure all-caps nested consts marked as autoloaded

Previously, an autoloaded constant `HTML::SomeClass` would not be marked
as autoloaded by AS::Dependencies. This is because the
`#loadable_constants_for_path` method uses `String#camelize` on the
inferred file path, which in turn means that, unless otherwise directed,
AS::Dependencies watches for loaded constants in the `Html` namespace.

By passing the original qualified constant name to `#load_or_require`,
this inference step is avoided, and the new constant is picked up in the
correct namespace.

Conflicts:
	activesupport/CHANGELOG.md
  • Loading branch information...
commit 94f44ee0d719d97a6ccff18311017a32667d5696 1 parent e36692a
@urbanautomaton urbanautomaton authored fxn committed
View
5 activesupport/CHANGELOG.md
@@ -1,5 +1,10 @@
## unreleased ##
+* Ensure that autoloaded constants in all-caps nestings are marked as
+ autoloaded.
+
+ *Simon Coffey*
+
* Adds a new deprecation behaviour that raises an exception. Throwing this
line into `config/environments/development.rb`:
View
2  activesupport/lib/active_support/dependencies.rb
@@ -459,7 +459,7 @@ def load_missing_constant(from_mod, const_name)
if loaded.include?(expanded)
raise "Circular dependency detected while autoloading constant #{qualified_name}"
else
- require_or_load(expanded)
+ require_or_load(expanded, qualified_name)
raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
return from_mod.const_get(const_name)
end
View
4 activesupport/test/autoloading_fixtures/html/some_class.rb
@@ -0,0 +1,4 @@
+module HTML
+ class SomeClass
+ end
+end
View
8 activesupport/test/dependencies_test.rb
@@ -648,6 +648,14 @@ def test_preexisting_constants_are_not_marked_as_autoloaded
Object.class_eval { remove_const :E }
end
+ def test_constants_in_capitalized_nesting_marked_as_autoloaded
+ with_autoloading_fixtures do
+ ActiveSupport::Dependencies.load_missing_constant(HTML, "SomeClass")
+
+ assert ActiveSupport::Dependencies.autoloaded?("HTML::SomeClass")
+ end
+ end
+
def test_unloadable
with_autoloading_fixtures do
Object.const_set :M, Module.new
Please sign in to comment.
Something went wrong with that request. Please try again.