diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/inflector.rb | 54 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 23 |
3 files changed, 43 insertions, 36 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 8168f989b1..9adac58cdf 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed Inflector.pluralize to handle capitalized words #932 [bitsweat] + * Added Object#suppress which allows you to make a saner choice around with exceptions to swallow #980. Example: suppress(ZeroDivisionError) { 1/0 } diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 557ffca06e..0fa6cb6e53 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -57,39 +57,39 @@ module Inflector private def plural_rules #:doc: [ - [/fish$/, 'fish'], # fish - [/(x|ch|ss|sh)$/, '\1es'], # search, switch, fix, box, process, address - [/series$/, '\1series'], - [/([^aeiouy]|qu)ies$/, '\1y'], - [/([^aeiouy]|qu)y$/, '\1ies'], # query, ability, agency - [/(?:([^f])fe|([lr])f)$/, '\1\2ves'], # half, safe, wife - [/sis$/, 'ses'], # basis, diagnosis - [/([ti])um$/, '\1a'], # datum, medium - [/person$/, 'people'], # person, salesperson - [/man$/, 'men'], # man, woman, spokesman - [/child$/, 'children'], # child - [/s$/, 's'], # no change (compatibility) + [/(fish)$/i, '\1\2'], # fish + [/(x|ch|ss|sh)$/i, '\1es'], # search, switch, fix, box, process, address + [/(series)$/i, '\1\2'], + [/([^aeiouy]|qu)ies$/i, '\1y'], + [/([^aeiouy]|qu)y$/i, '\1ies'], # query, ability, agency + [/(?:([^f])fe|([lr])f)$/i, '\1\2ves'], # half, safe, wife + [/sis$/i, 'ses'], # basis, diagnosis + [/([ti])um$/i, '\1a'], # datum, medium + [/(p)erson$/i, '\1\2eople'], # person, salesperson + [/(m)an$/i, '\1\2en'], # man, woman, spokesman + [/(c)hild$/i, '\1\2hildren'], # child + [/s$/i, 's'], # no change (compatibility) [/$/, 's'] ] end def singular_rules #:doc: [ - [/fish$/, 'fish'], - [/(x|ch|ss|sh)es$/, '\1'], - [/movies$/, 'movie'], - [/series$/, 'series'], - [/([^aeiouy]|qu)ies$/, '\1y'], - [/([lr])ves$/, '\1f'], - [/([^f])ves$/, '\1fe'], - [/(analy|ba|diagno|parenthe|progno|synop|the)ses$/, '\1sis'], - [/([ti])a$/, '\1um'], - [/people$/, 'person'], - [/men$/, 'man'], - [/status$/, 'status'], - [/children$/, 'child'], - [/news$/, 'news'], - [/s$/, ''] + [/(f)ish$/i, '\1\2ish'], + [/(x|ch|ss|sh)es$/i, '\1'], + [/(m)ovies$/i, '\1\2ovie'], + [/(s)eries$/i, '\1\2eries'], + [/([^aeiouy]|qu)ies$/i, '\1y'], + [/([lr])ves$/i, '\1f'], + [/([^f])ves$/i, '\1fe'], + [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis'], + [/([ti])a$/i, '\1um'], + [/(p)eople$/i, '\1\2erson'], + [/(m)en$/i, '\1\2an'], + [/(s)tatus$/i, '\1\2tatus'], + [/(c)hildren$/i, '\1\2hild'], + [/(n)ews$/i, '\1\2ews'], + [/s$/i, ''] ] end end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 14a532a9a2..ffadb5bd96 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -17,9 +17,9 @@ class InflectorTest < Test::Unit::TestCase "process" => "processes", "address" => "addresses", "case" => "cases", - "stack" => "stacks",
- "wish" => "wishes",
- "fish" => "fish", + "stack" => "stacks", + "wish" => "wishes", + "fish" => "fish", "category" => "categories", "query" => "queries", @@ -92,17 +92,22 @@ class InflectorTest < Test::Unit::TestCase "underground" => "Underground" } - def test_pluralize - SingularToPlural.each do |singular, plural| + def test_pluralize_plurals + assert_equal "plurals", Inflector.pluralize("plurals") + assert_equal "Plurals", Inflector.pluralize("Plurals") + end + + SingularToPlural.each do |singular, plural| + define_method "test_pluralize_#{singular}" do assert_equal(plural, Inflector.pluralize(singular)) + assert_equal(plural.capitalize, Inflector.pluralize(singular.capitalize)) end - - assert_equal("plurals", Inflector.pluralize("plurals")) end - def test_singularize - SingularToPlural.each do |singular, plural| + SingularToPlural.each do |singular, plural| + define_method "test_singularize_#{plural}" do assert_equal(singular, Inflector.singularize(plural)) + assert_equal(singular.capitalize, Inflector.singularize(plural.capitalize)) end end |