diff options
Diffstat (limited to 'activesupport')
4 files changed, 25 insertions, 17 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index f5d047ee07..81f0e6f449 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -51,11 +51,12 @@ module Dependencies #:nodoc: def require_or_load(file_name, const_path = nil) file_name = $1 if file_name =~ /^(.*)\.rb$/ - return if loaded.include?(file_name) + expanded = File.expand_path(file_name) + return if loaded.include?(expanded) # Record that we've seen this file *before* loading it to avoid an # infinite loop with mutual dependencies. - loaded << file_name + loaded << expanded if load? begin @@ -64,13 +65,13 @@ module Dependencies #:nodoc: load_args = ["#{file_name}.rb"] load_args << const_path unless const_path.nil? - if !warnings_on_first_load or history.include?(file_name) + if !warnings_on_first_load or history.include?(expanded) load_file(*load_args) else enable_warnings { load_file(*load_args) } end rescue - loaded.delete file_name + loaded.delete expanded raise end else @@ -78,7 +79,7 @@ module Dependencies #:nodoc: end # Record history *after* loading so first load gets warnings. - history << file_name + history << expanded end # Is the provided constant path defined? @@ -155,7 +156,7 @@ module Dependencies #:nodoc: name_error = NameError.new("uninitialized constant #{qualified_name}") file_path = search_for_autoload_file(path_suffix) - if file_path #&& ! loaded.include?(file_path) # We found a matching file to load + if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load require_or_load file_path, qualified_name raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless from_mod.const_defined?(const_name) return from_mod.const_get(const_name) diff --git a/activesupport/test/autoloading_fixtures/counting_loader.rb b/activesupport/test/autoloading_fixtures/counting_loader.rb new file mode 100644 index 0000000000..4225c4412c --- /dev/null +++ b/activesupport/test/autoloading_fixtures/counting_loader.rb @@ -0,0 +1,5 @@ +$counting_loaded_times ||= 0 +$counting_loaded_times += 1 + +module CountingLoader +end diff --git a/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb b/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb new file mode 100644 index 0000000000..d12d02f3aa --- /dev/null +++ b/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb @@ -0,0 +1 @@ +ModuleWithCustomConstMissing::A::B = "10"
\ No newline at end of file diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index b607093e8e..fe823a9e52 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -57,34 +57,35 @@ class DependenciesTest < Test::Unit::TestCase old_warnings, Dependencies.warnings_on_first_load = Dependencies.warnings_on_first_load, true filename = "#{File.dirname(__FILE__)}/dependencies/check_warnings" + expanded = File.expand_path(filename) $check_warnings_load_count = 0 - assert !Dependencies.loaded.include?(filename) - assert !Dependencies.history.include?(filename) + assert !Dependencies.loaded.include?(expanded) + assert !Dependencies.history.include?(expanded) silence_warnings { require_dependency filename } assert_equal 1, $check_warnings_load_count assert_equal true, $checked_verbose, 'On first load warnings should be enabled.' - assert Dependencies.loaded.include?(filename) + assert Dependencies.loaded.include?(expanded) Dependencies.clear - assert !Dependencies.loaded.include?(filename) - assert Dependencies.history.include?(filename) + assert !Dependencies.loaded.include?(expanded) + assert Dependencies.history.include?(expanded) silence_warnings { require_dependency filename } assert_equal 2, $check_warnings_load_count assert_equal nil, $checked_verbose, 'After first load warnings should be left alone.' - assert Dependencies.loaded.include?(filename) + assert Dependencies.loaded.include?(expanded) Dependencies.clear - assert !Dependencies.loaded.include?(filename) - assert Dependencies.history.include?(filename) + assert !Dependencies.loaded.include?(expanded) + assert Dependencies.history.include?(expanded) enable_warnings { require_dependency filename } assert_equal 3, $check_warnings_load_count assert_equal true, $checked_verbose, 'After first load warnings should be left alone.' - assert Dependencies.loaded.include?(filename) + assert Dependencies.loaded.include?(expanded) end end @@ -302,9 +303,9 @@ class DependenciesTest < Test::Unit::TestCase def test_const_missing_should_not_double_load with_loading 'autoloading_fixtures' do - require_dependency 'counting_loader' + require_dependency '././counting_loader' assert_equal 1, $counting_loaded_times - ModuleFolder + Dependencies.load_missing_constant Object, :CountingLoader assert_equal 1, $counting_loaded_times end end |