Changeset 3181
- Timestamp:
- 11/24/05 05:43:27 (3 years ago)
- Files:
-
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (2 diffs)
- trunk/activesupport/test/dependencies_test.rb (modified) (1 diff)
- trunk/activesupport/test/dependencies/mutual_one.rb (added)
- trunk/activesupport/test/dependencies/mutual_two.rb (added)
- trunk/activesupport/test/dependencies/raises_exception.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/dependencies.rb
r3176 r3181 46 46 load_file_name = (file_name =~ /\.rb$/ ? file_name : "#{file_name}.rb") 47 47 48 # Enable warnings iff this file has not been loaded before. 49 if history.include?(file_name) 50 load load_file_name 51 else 52 enable_warnings { load load_file_name } 48 # Record that we've seen this file *before* loading it to avoid an 49 # infinite loop with mutual dependencies. 50 loaded << file_name 51 52 begin 53 # Enable warnings iff this file has not been loaded before. 54 if history.include?(file_name) 55 load load_file_name 56 else 57 enable_warnings { load load_file_name } 58 end 59 rescue 60 loaded.delete file_name 61 raise 53 62 end 54 63 else … … 56 65 end 57 66 58 # Record that we've seen this file. 59 loaded << file_name 67 # Record history *after* loading so first load gets warnings. 60 68 history << file_name 61 69 end trunk/activesupport/test/dependencies_test.rb
r3169 r3181 80 80 Dependencies.mechanism = old_mechanism 81 81 end 82 83 def test_mutual_dependencies_dont_infinite_loop 84 $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/dependencies" 85 old_mechanism, Dependencies.mechanism = Dependencies.mechanism, :load 86 87 $mutual_dependencies_count = 0 88 assert_nothing_raised { require_dependency 'mutual_one' } 89 assert_equal 2, $mutual_dependencies_count 90 91 Dependencies.clear 92 93 $mutual_dependencies_count = 0 94 assert_nothing_raised { require_dependency 'mutual_two' } 95 assert_equal 2, $mutual_dependencies_count 96 ensure 97 $LOAD_PATH.shift 98 Dependencies.mechanism = old_mechanism 99 end 82 100 end trunk/activesupport/test/dependencies/raises_exception.rb
r3169 r3181 1 1 $raises_exception_load_count += 1 2 2 raise 'Loading me failed, so do not add to loaded or history.' 3 $raises_exception_load_count += 1