提交 6a485c31 编写于 作者: N Nicholas Seckar

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
上级 d1a24492
*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]
......
......@@ -405,8 +405,9 @@ def to_constant_name(desc)
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
......
......@@ -176,7 +176,7 @@ def test_to_with_instruct
{ :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
......@@ -691,4 +691,15 @@ def test_autoload_doesnt_shadow_name_error
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册