From 5427526bce4bd649f46617ea04c14167e68a77b1 Mon Sep 17 00:00:00 2001 From: ono Date: Wed, 8 Apr 2009 19:41:15 +0100 Subject: [PATCH] inherited_const_defined? for class loader issue --- activesupport/lib/active_support/dependencies.rb | 11 ++++++++++- activesupport/test/dependencies_test.rb | 5 +++++ 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 2badad5..7823357 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -303,6 +303,15 @@ module ActiveSupport #:nodoc: end end + # Does this module or its ascendants define this constant? + def inherited_const_defined?(mod, const) + return false if mod==nil + + return true if uninherited_const_defined?(mod, const) + + return inherited_const_defined?(mod.superclass, const) + end + # Given +path+, a filesystem path to a ruby file, return an array of constant # paths which would cause Dependencies to attempt to load this file. def loadable_constants_for_path(path, bases = load_paths) @@ -423,7 +432,7 @@ module ActiveSupport #:nodoc: file_path = search_for_file(path_suffix) if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load require_or_load file_path - raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless uninherited_const_defined?(from_mod, const_name) + raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless inherited_const_defined?(from_mod, const_name) return from_mod.const_get(const_name) elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix) return mod diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index a21f094..0d227d2 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -773,4 +773,9 @@ class DependenciesTest < Test::Unit::TestCase ensure ActiveSupport::Dependencies.hook! end + + def test_inherited_const_defined + assert ! ActiveSupport::Dependencies.uninherited_const_defined?(String, :Array) + assert ActiveSupport::Dependencies.inherited_const_defined?(String, :Array) + end end -- 1.6.0.6