Changeset 4774
- Timestamp:
- 08/16/06 17:50:52 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (1 diff)
- trunk/activesupport/test/dependencies_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r4769 r4774 1 1 *SVN* 2 3 * Stop using defined? in Dependencies.qualified_const_defined? since defined? may invoke const_missing. [Nicholas Seckar] 2 4 3 5 * Dependencies can autoload directories of nested classes. [Jeremy Kemper] trunk/activesupport/lib/active_support/dependencies.rb
r4769 r4774 97 97 raise NameError, "#{path.inspect} is not a valid constant name!" unless 98 98 /^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ path 99 Object.module_eval("defined?(#{path})", __FILE__, __LINE__) 99 100 names = path.split('::') 101 names.shift if names.first.empty? 102 103 # We can't use defined? because it will invoke const_missing for the parent 104 # of the name we are checking. 105 names.inject(Object) do |mod, name| 106 return false unless mod.const_defined? name 107 mod.const_get name 108 end 109 return true 100 110 end 101 111 trunk/activesupport/test/dependencies_test.rb
r4769 r4774 1 1 require File.dirname(__FILE__) + '/abstract_unit' 2 3 module ModuleWithMissing 4 mattr_accessor :missing_count 5 def self.const_missing(name) 6 self.missing_count += 1 7 name 8 end 9 end 2 10 3 11 class DependenciesTest < Test::Unit::TestCase … … 250 258 end 251 259 260 def test_qualified_const_defined_should_not_call_method_missing 261 ModuleWithMissing.missing_count = 0 262 assert ! Dependencies.qualified_const_defined?("ModuleWithMissing::A") 263 assert_equal 0, ModuleWithMissing.missing_count 264 assert ! Dependencies.qualified_const_defined?("ModuleWithMissing::A::B") 265 assert_equal 0, ModuleWithMissing.missing_count 266 end 267 252 268 def test_autoloaded? 253 269 with_loading 'autoloading_fixtures' do