提交 0fc53139 编写于 作者: X Xavier Noria

let demodulize do less work, and add tests

This is also faster on 1.9.
上级 2e74334a
......@@ -166,7 +166,9 @@ def dasherize(underscored_word)
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
# "Inflections".demodulize # => "Inflections"
def demodulize(class_name_in_module)
class_name_in_module.to_s.gsub(/^.*::/, '')
# If you remove the module part of an empty string, you get an empty string.
# That's why the regexp uses the * quantifier.
class_name_in_module.to_s[/[^:]*\z/]
end
# Creates a foreign key name from a class name.
......
......@@ -194,6 +194,8 @@ def test_underscore_with_slashes
def test_demodulize
assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account")
assert_equal "Account", ActiveSupport::Inflector.demodulize("Account")
assert_equal "", ActiveSupport::Inflector.demodulize("")
end
def test_foreign_key
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册