Skip to content

Commit

Permalink
Fix that irregular plural inflections should not be double-pluralized…
Browse files Browse the repository at this point in the history
…: 'people'.pluralize should return 'people' not 'peoples'.

[#1183 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
sikachu authored and jeremy committed Aug 10, 2009
1 parent 84d24cd commit 82dd725
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions activesupport/lib/active_support/inflector.rb
Expand Up @@ -69,10 +69,13 @@ def irregular(singular, plural)
@uncountables.delete(plural)
if singular[0,1].upcase == plural[0,1].upcase
plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
plural(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + plural[1..-1])
singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
else
plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
plural(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
plural(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
end
Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/inflector_test.rb
Expand Up @@ -256,6 +256,16 @@ def test_clear_with_default
end
end

Irregularities.each do |irregularity|
singular, plural = *irregularity
ActiveSupport::Inflector.inflections do |inflect|
define_method("test_pluralize_of_irregularity_#{plural}_should_be_the_same") do
inflect.irregular(singular, plural)
assert_equal plural, ActiveSupport::Inflector.pluralize(plural)
end
end
end

[ :all, [] ].each do |scope|
ActiveSupport::Inflector.inflections do |inflect|
define_method("test_clear_inflections_with_#{scope.kind_of?(Array) ? "no_arguments" : scope}") do
Expand Down

0 comments on commit 82dd725

Please sign in to comment.