diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 54f9b4e4ccea5323140547342fbfcf28bd126505..33961ce1c7d8b7f2c99051707eb81d5ff2e9b9fa 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix loadable_constants_for_path to handle load paths that do not end with a slash. [Nicholas Seckar] + * Fix logic error in determining what was loaded by a given file. Closes #6039. [Nicholas Seckar] * Equate Kernel.const_missing with Object.const_missing. Fixes #5988. [Nicholas Seckar] diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 1b027aa75bd7e66d12f1d4eee54ac78467c88abd..4a4861220ef6e2f36459f1c64f30358d614f4959 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -125,19 +125,18 @@ def loadable_constants_for_path(path, bases = load_paths - load_once_paths) expanded_path = File.expand_path(path) bases.collect do |root| - expanded_root = File.expand_path root - next unless expanded_path.starts_with? expanded_root + expanded_root = File.expand_path(root) + next unless %r{\A#{Regexp.escape(expanded_root)}(/|\\)} =~ expanded_path nesting = expanded_path[(expanded_root.size)..-1] nesting = nesting[1..-1] if nesting && nesting[0] == ?/ next if nesting.blank? - names = [nesting.camelize] - - # Special case: application.rb might define ApplicationControlller. - names << 'ApplicationController' if nesting == 'application' - - names + [ + nesting.camelize, + # Special case: application.rb might define ApplicationControlller. + ('ApplicationController' if nesting == 'application') + ] end.flatten.compact.uniq end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index fcd2889ac21596091b425d6a6fffc9e80639d339..c1e95f51a9571379fe425d31739931cf93e0443c 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -250,6 +250,13 @@ def test_loadable_constants_for_path_should_uniq_results end end + def test_loadable_constants_with_load_path_without_trailing_slash + path = File.dirname(__FILE__) + '/autoloading_fixtures/class_folder/inline_class.rb' + with_loading 'autoloading_fixtures/class/' do + assert_equal [], Dependencies.loadable_constants_for_path(path) + end + end + def test_qualified_const_defined assert Dependencies.qualified_const_defined?("Object") assert Dependencies.qualified_const_defined?("::Object")