提交 9bd007c7 编写于 作者: N Nicholas Seckar

Add forgotten files; Fix double loading errors.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4730 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 4635d339
......@@ -51,11 +51,12 @@ def clear
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 @@ def require_or_load(file_name, const_path = nil)
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 @@ def require_or_load(file_name, const_path = nil)
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 @@ def load_missing_constant(from_mod, const_name)
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)
......
$counting_loaded_times ||= 0
$counting_loaded_times += 1
module CountingLoader
end
ModuleWithCustomConstMissing::A::B = "10"
\ No newline at end of file
......@@ -57,34 +57,35 @@ def test_warnings_should_be_enabled_on_first_load
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 @@ module A
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册