Permalink
Browse files

Make the apply_inflections method case-sensitive

Since d3071db, the apply_inflections method check if the downcased
version of a string is contained inside the "whitelist" of uncountable
words. However, if the word is composed of capital letters, it won't be
matched in the list while it should.

We can't simply revert to the previous behavior as there is a
performance concern (benchmarked over /usr/share/dict/words):

Before d3071db  135.610000   0.290000  135.900000 (137.807081)
Since d3071db   22.170000    0.020000  22.190000  ( 22.530005)
With the patch   22.060000    0.020000  22.080000  ( 22.125771)

Benchmarked with http://git.io/aFnWig

This way, the solution is to put the down-case version of words inside
the @uncountables array.
  • Loading branch information...
1 parent 6099b64 commit 643409dcb04e7ac6a6c7b09edfb9606563e9aa21 @robin850 robin850 committed Mar 2, 2014
@@ -1,8 +1,13 @@
+* Make the `apply_inflections` method case-insensitive when checking
+ whether a word is uncountable or not.
+
+ *Robin Dupret*
+
* Make Dependencies pass a name to NameError error.
*arthurnn*
* Fixed `ActiveSupport::Cache::FileStore` exploding with long paths.
- *Adam Panzer / Michael Grosser*
+ *Adam Panzer / Michael Grosser*
* Fixed `ActiveSupport::TimeWithZone#-` so precision is not unnecessarily lost
when working with objects with a nanosecond component.
@@ -27,12 +32,12 @@
* Fixed precision error in NumberHelper when using Rationals.
Before:
-
+
ActiveSupport::NumberHelper.number_to_rounded Rational(1000, 3), precision: 2
#=> "330.00"
-
+
After:
-
+
ActiveSupport::NumberHelper.number_to_rounded Rational(1000, 3), precision: 2
#=> "333.33"
@@ -160,7 +160,7 @@ def irregular(singular, plural)
# uncountable 'money', 'information'
# uncountable %w( money information rice )
def uncountable(*words)
- (@uncountables << words).flatten!
+ @uncountables += words.flatten.map(&:downcase)
end
# Specifies a humanized form of a string by a regular expression rule or
@@ -509,6 +509,14 @@ def test_clear_with_default
end
end
+ def test_inflections_with_uncountable_words
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.uncountable "HTTP"
+ end
+
+ assert_equal "HTTP", ActiveSupport::Inflector.pluralize("HTTP")
+ end
+
# Dups the singleton and yields, restoring the original inflections later.
# Use this in tests what modify the state of the singleton.
#

0 comments on commit 643409d

Please sign in to comment.