From 7d261a6085838c9a94f96e0cc7116a8615b19d90 Mon Sep 17 00:00:00 2001 From: Michelangelo Altamore Date: Fri, 3 Apr 2009 14:51:15 +0200 Subject: [PATCH] Fix for ticket #2399: adds correct singularization for singular words ending in '*ess' --- activesupport/lib/active_support/inflections.rb | 3 ++- activesupport/test/inflector_test.rb | 7 +++++++ activesupport/test/inflector_test_cases.rb | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/inflections.rb b/activesupport/lib/active_support/inflections.rb index 8fb3fa9..2865cd0 100644 --- a/activesupport/lib/active_support/inflections.rb +++ b/activesupport/lib/active_support/inflections.rb @@ -43,7 +43,8 @@ module ActiveSupport inflect.singular(/(matr)ices$/i, '\1ix') inflect.singular(/(quiz)zes$/i, '\1') inflect.singular(/(database)s$/i, '\1') - + inflect.singular(/ess$/i, 'ess') + inflect.irregular('person', 'people') inflect.irregular('man', 'men') inflect.irregular('child', 'children') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 6b9fbd3..8841be5 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -33,6 +33,13 @@ class InflectorTest < Test::Unit::TestCase assert_equal(singular.capitalize, ActiveSupport::Inflector.singularize(plural.capitalize)) end end + + SingularToSingularized.each do |singular, singularized| + define_method "test_singularize_#{singular}" do + assert_equal(singular, ActiveSupport::Inflector.singularize(singularized)) + assert_equal(singular.capitalize, ActiveSupport::Inflector.singularize(singularized.capitalize)) + end + end def test_overwrite_previous_inflectors assert_equal("series", ActiveSupport::Inflector.singularize("series")) diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 584cbff..3a8c58d 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -102,6 +102,14 @@ module InflectorTestCases "cow" => "kine", "database" => "databases" } + + SingularToSingularized = { + "business" => "business", + "address" => "address", + "express" => "express", + "dress" => "dress", + "press" => "press" + } CamelToUnderscore = { "Product" => "product", -- 1.5.5.4