From 052b69d07104a0c27880ac316b0efe36c48704c3 Mon Sep 17 00:00:00 2001 From: Ryan Kinderman Date: Mon, 12 Oct 2009 20:09:38 -0500 Subject: [PATCH] solution to dependency loading issue for Class#const_missing --- activesupport/lib/active_support/dependencies.rb | 6 ++++- activesupport/test/dependencies_test.rb | 24 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 7f6f012..e689ea0 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -106,7 +106,11 @@ module ActiveSupport #:nodoc: begin Dependencies.load_missing_constant self, const_name rescue NameError - parent.send :const_missing, const_name + if parent.const_defined?(const_name) + parent.const_get(const_name) + else + parent.send :const_missing, const_name + end end rescue NameError => e # Make sure that the name we are missing is the one that caused the error diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 97d70cf..7c96dd5 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -783,4 +783,28 @@ class DependenciesTest < Test::Unit::TestCase ensure ActiveSupport::Dependencies.hook! end + + def test_class_const_missing_when_parent_module_defines_constant_should_return_constant_from_parent_module + const = DependencyBehavior::A.class_eval("B") + assert_equal DependencyBehavior::B.object_id, const.object_id + end + +end + +module DependencyBehavior + class A + def self.klass + B + end + end + + class B + end + + module Sub + class A + end + class B + end + end end -- 1.6.4.2