Changeset 4730
- Timestamp:
- 08/08/06 22:08:09 (2 years ago)
- Files:
-
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (5 diffs)
- trunk/activesupport/test/autoloading_fixtures/counting_loader.rb (added)
- trunk/activesupport/test/autoloading_fixtures/module_with_custom_const_missing (added)
- trunk/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a (added)
- trunk/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb (added)
- trunk/activesupport/test/dependencies_test.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/dependencies.rb
r4729 r4730 52 52 def require_or_load(file_name, const_path = nil) 53 53 file_name = $1 if file_name =~ /^(.*)\.rb$/ 54 return if loaded.include?(file_name) 54 expanded = File.expand_path(file_name) 55 return if loaded.include?(expanded) 55 56 56 57 # Record that we've seen this file *before* loading it to avoid an 57 58 # infinite loop with mutual dependencies. 58 loaded << file_name59 loaded << expanded 59 60 60 61 if load? … … 65 66 load_args << const_path unless const_path.nil? 66 67 67 if !warnings_on_first_load or history.include?( file_name)68 if !warnings_on_first_load or history.include?(expanded) 68 69 load_file(*load_args) 69 70 else … … 71 72 end 72 73 rescue 73 loaded.delete file_name74 loaded.delete expanded 74 75 raise 75 76 end … … 79 80 80 81 # Record history *after* loading so first load gets warnings. 81 history << file_name82 history << expanded 82 83 end 83 84 … … 156 157 157 158 file_path = search_for_autoload_file(path_suffix) 158 if file_path #&& ! loaded.include?(file_path) # We found a matching file to load159 if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load 159 160 require_or_load file_path, qualified_name 160 161 raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless from_mod.const_defined?(const_name) trunk/activesupport/test/dependencies_test.rb
r4729 r4730 58 58 59 59 filename = "#{File.dirname(__FILE__)}/dependencies/check_warnings" 60 expanded = File.expand_path(filename) 60 61 $check_warnings_load_count = 0 61 62 62 assert !Dependencies.loaded.include?( filename)63 assert !Dependencies.history.include?( filename)63 assert !Dependencies.loaded.include?(expanded) 64 assert !Dependencies.history.include?(expanded) 64 65 65 66 silence_warnings { require_dependency filename } … … 67 68 assert_equal true, $checked_verbose, 'On first load warnings should be enabled.' 68 69 69 assert Dependencies.loaded.include?( filename)70 assert Dependencies.loaded.include?(expanded) 70 71 Dependencies.clear 71 assert !Dependencies.loaded.include?( filename)72 assert Dependencies.history.include?( filename)72 assert !Dependencies.loaded.include?(expanded) 73 assert Dependencies.history.include?(expanded) 73 74 74 75 silence_warnings { require_dependency filename } … … 76 77 assert_equal nil, $checked_verbose, 'After first load warnings should be left alone.' 77 78 78 assert Dependencies.loaded.include?( filename)79 assert Dependencies.loaded.include?(expanded) 79 80 Dependencies.clear 80 assert !Dependencies.loaded.include?( filename)81 assert Dependencies.history.include?( filename)81 assert !Dependencies.loaded.include?(expanded) 82 assert Dependencies.history.include?(expanded) 82 83 83 84 enable_warnings { require_dependency filename } … … 85 86 assert_equal true, $checked_verbose, 'After first load warnings should be left alone.' 86 87 87 assert Dependencies.loaded.include?( filename)88 assert Dependencies.loaded.include?(expanded) 88 89 end 89 90 end … … 303 304 def test_const_missing_should_not_double_load 304 305 with_loading 'autoloading_fixtures' do 305 require_dependency ' counting_loader'306 require_dependency '././counting_loader' 306 307 assert_equal 1, $counting_loaded_times 307 ModuleFolder308 Dependencies.load_missing_constant Object, :CountingLoader 308 309 assert_equal 1, $counting_loaded_times 309 310 end