From 7d9e601812d0f2fa5bd355e83987bff32c1b4695 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 19 Aug 2010 17:51:06 +0100 Subject: [PATCH] Use constant.constants.member? rather than const_defined? as the former will include constants in ancestors [#410 state:resolved] --- .../lib/active_support/inflector/methods.rb | 6 ++++-- activesupport/test/inflector_test.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index de49750..bc8e5cc 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -110,7 +110,8 @@ module ActiveSupport constant = Object names.each do |name| - constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) + module_with_constant = constant.ancestors.detect {|mod| mod.const_defined?(name)} + constant = module_with_constant ? module_with_constant.const_get(name) : constant.const_missing(name) end constant end @@ -121,7 +122,8 @@ module ActiveSupport constant = Object names.each do |name| - constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name) + module_with_constant = constant.ancestors.detect {|mod| mod.const_defined?(name, false)} + constant = module_with_constant ? module_with_constant.const_get(name, false) : constant.const_missing(name) end constant end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 2990177..c36f543 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -4,8 +4,21 @@ require 'active_support/inflector' require 'inflector_test_cases' module Ace + module Extension + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def mission_accomplished? + false + end + end + end + module Base class Case + include Extension end end end @@ -176,6 +189,8 @@ class InflectorTest < Test::Unit::TestCase def test_constantize_does_lexical_lookup assert_raise(NameError) { ActiveSupport::Inflector.constantize("Ace::Base::InflectorTest") } + assert_nothing_raised { Ace::Base::Case::ClassMethods } + assert_nothing_raised { assert_equal Ace::Base::Case::ClassMethods, ActiveSupport::Inflector.constantize("Ace::Base::Case::ClassMethods") } end def test_ordinal -- 1.7.1