diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-22 18:34:43 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-22 18:34:43 +0000 |
commit | 3dcae9fefd0af8f7f8e7d3368ec36128880add51 (patch) | |
tree | 5b1ae85446b05ae607919dafc69bb0fe96f43c01 /activesupport | |
parent | 59c36fd4567cea821953c8b3ec73264d50e0a4ad (diff) | |
download | rails-3dcae9fefd0af8f7f8e7d3368ec36128880add51.tar.gz rails-3dcae9fefd0af8f7f8e7d3368ec36128880add51.tar.bz2 rails-3dcae9fefd0af8f7f8e7d3368ec36128880add51.zip |
Fixed that pluralizing an empty string should return the same empty string, not "s" (closes #7720) [josh]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7569 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/inflector.rb | 2 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 4 |
3 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index e0057eb72e..d2684da9a1 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that pluralizing an empty string should return the same empty string, not "s" #7720 [josh] + * Added call to inspect on non-string classes for the logger #8533 [codahale] * Deprecation: remove deprecated :mday option from Time, Date, and DateTime#change. [Jeremy Kemper] diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 39edf64117..baa342f669 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -106,7 +106,7 @@ module Inflector def pluralize(word) result = word.to_s.dup - if inflections.uncountables.include?(result.downcase) + if word.empty? || inflections.uncountables.include?(result.downcase) result else inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) } diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 684150a925..ebf07e1d0f 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -220,6 +220,10 @@ class InflectorTest < Test::Unit::TestCase assert_equal "Plurals", Inflector.pluralize("Plurals") end + def test_pluralize_empty_string + assert_equal "", Inflector.pluralize("") + end + SingularToPlural.each do |singular, plural| define_method "test_pluralize_#{singular}" do assert_equal(plural, Inflector.pluralize(singular)) |