提交 459f7bf3 编写于 作者: K Kuldeep Aggarwal

Fix inconsistent behavior from String#pluralize

Before:
  When calling String#pluralize with count=1 then it returned same
  string, but with count other than 1, returned new string.

After:
  String#pluralize always return a new string.

  => Prevent mutation of a string inadvertently.
上级 5f72fc6a
......@@ -31,7 +31,7 @@ class String
def pluralize(count = nil, locale = :en)
locale = count if count.is_a?(Symbol)
if count == 1
self
self.dup
else
ActiveSupport::Inflector.pluralize(self, locale)
end
......
......@@ -58,6 +58,11 @@ def test_pluralize
assert_equal("blargles", "blargle".pluralize(2))
end
test 'pluralize with count = 1 still returns new string' do
name = "Kuldeep"
assert_not_same name.pluralize(1), name
end
def test_singularize
SingularToPlural.each do |singular, plural|
assert_equal(singular, plural.singularize)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册