mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add forgotten files; Fix double loading errors.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4730 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
4635d33996
commit
9bd007c7c7
4 changed files with 25 additions and 17 deletions
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
$counting_loaded_times ||= 0
|
||||
$counting_loaded_times += 1
|
||||
|
||||
module CountingLoader
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
ModuleWithCustomConstMissing::A::B = "10"
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue