diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2006-12-09 05:21:33 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2006-12-09 05:21:33 +0000 |
commit | 6a485c3100090fbf474336802c851b842b8a96f3 (patch) | |
tree | ab4121b338acea7e1bb87f3e08d7650f271889cf /activesupport | |
parent | d1a2449220303f24da0d70504f5959635730da88 (diff) | |
download | rails-6a485c3100090fbf474336802c851b842b8a96f3.tar.gz rails-6a485c3100090fbf474336802c851b842b8a96f3.tar.bz2 rails-6a485c3100090fbf474336802c851b842b8a96f3.zip |
Fix remove_constant to correctly handle constant names of the form "::A::...". References #6720.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5710 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 3 | ||||
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 2 | ||||
-rw-r--r-- | activesupport/test/dependencies_test.rb | 11 |
4 files changed, 16 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index ac42d9c630..bec1edf6c1 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix remove_constant to correctly handle constant names of the form "::A::...". References #6720. [Nicholas Seckar] + * Fixed Array#to_xml when it contains a series of hashes (each piece would get its own XML declaration) #6610 [thkarcher/cyu] * Added Time#to_s(:time) which will just return H:M, like 17:44 [DHH] diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index ad4e4da669..b169393bf7 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -405,8 +405,9 @@ protected def remove_constant(const) return false unless qualified_const_defined? const + const = $1 if /\A::(.*)\Z/ =~ const.to_s names = const.split('::') - if names.size == 1 || names.first.empty? # It's under Object + if names.size == 1 # It's under Object parent = Object else parent = (names[0..-2] * '::').constantize diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 709df84f06..87608de8d5 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -176,7 +176,7 @@ class ArrayToXmlTests < Test::Unit::TestCase { :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') } ].to_xml(:skip_instruct => false, :indent => 0) - assert /^<\?xml [^>]*/.match(xml) + assert(/^<\?xml [^>]*/.match(xml)) assert xml.rindex(/<\?xml /) == 0 end end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 954f2f4a85..52f83e0f9f 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -691,4 +691,15 @@ class DependenciesTest < Test::Unit::TestCase ensure Object.send(:remove_const, :RaisesNameError) if defined?(::RaisesNameError) end + + def test_remove_constant_handles_double_colon_at_start + Object.const_set 'DeleteMe', Module.new + DeleteMe.const_set 'OrMe', Module.new + Dependencies.send :remove_constant, "::DeleteMe::OrMe" + assert ! defined?(DeleteMe::OrMe) + assert defined?(DeleteMe) + Dependencies.send :remove_constant, "::DeleteMe" + assert ! defined?(DeleteMe) + end + end |