aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorGabriel Mansour <gabrielmansour@gmail.com>2010-01-30 12:38:33 -0500
committerJeremy Kemper <jeremy@bitsweat.net>2010-02-07 12:12:09 -0800
commitb235af702a086dd06fa9849ee47942e8ce82090d (patch)
treedc09ec6a9b6bd33fe0bca0fe81e8025beb0b559c /actionpack
parenta1a6e54d14b70e1d418d4939328e6eb24bdd8f3b (diff)
downloadrails-b235af702a086dd06fa9849ee47942e8ce82090d.tar.gz
rails-b235af702a086dd06fa9849ee47942e8ce82090d.tar.bz2
rails-b235af702a086dd06fa9849ee47942e8ce82090d.zip
Fix pluralization for numbers formatted like '1.00'
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb2
-rw-r--r--actionpack/test/template/text_helper_test.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 412e0c82cb..b63617322f 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -187,7 +187,7 @@ module ActionView
# pluralize(0, 'person')
# # => 0 people
def pluralize(count, singular, plural = nil)
- "#{count || 0} " + ((count == 1 || count == '1') ? singular : (plural || singular.pluralize))
+ "#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
end
# Wraps the +text+ into lines no longer than +line_width+ width. This method
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 088c07b8bb..39bea12501 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -228,6 +228,8 @@ class TextHelperTest < ActionView::TestCase
assert_equal("2 counts", pluralize('2', "count"))
assert_equal("1,066 counts", pluralize('1,066', "count"))
assert_equal("1.25 counts", pluralize('1.25', "count"))
+ assert_equal("1.0 count", pluralize('1.0', "count"))
+ assert_equal("1.00 count", pluralize('1.00', "count"))
assert_equal("2 counters", pluralize(2, "count", "counters"))
assert_equal("0 counters", pluralize(nil, "count", "counters"))
assert_equal("2 people", pluralize(2, "person"))