Inconsistent inflector behaviour for uncountable words in a multi-word string separated by underscores #7132

Closed
chancancode opened this Issue Jul 23, 2012 · 5 comments

Comments

Projects
None yet
5 participants
@chancancode
Member

chancancode commented Jul 23, 2012

# Single-word + uncountables = no problem!
"information".singularize # => "information"
"information".pluralize # => "information"

# Multi-word + spaces + countables = no problem!
"weird bugs".singularize # => "weird bug"
"weird bug".pluralize # => "weird bugs"

# Multi-word + spaces + uncountables = no problem!
"funky jeans".pluralize # => "funky jeans"
"funky jeans".singularize # => "funky jeans"

# Multi-word + underscores + countables = no problem!
"weird_bugs".singularize # => "weird_bug"
"weird_bug".pluralize # => "weird_bugs"

# Multi-word + underscores + uncountables = BOOM!
"funky_jeans".singularize # => "funky_jean"
"client_information".pluralize # => "client_informations"

I consider this a bug because...

  1. According to this test case, pluralizing/singularizing a multi-word string is a supported feature
  2. According to this test cases, pluralizing/singularizing a multi-word string separated by underscores is a supported feature
  3. tableize depends on 2.
  4. "funky_jeans".singularize used to work before 9b4622a:
mbp:godfrey rails [(no branch)] $ git checkout baebe7d0d5c82cc7bb0570ae7d17a947f9bf58f7
HEAD is now at baebe7d... Avoid Bundler Resolver bug until they solve the issue
mbp:godfrey rails [(no branch)] $ irb -Iactivesupport/lib
>> require 'active_support/all'
=> true
>> 'funky_jeans'.singularize
=> "funky_jeans"

However, as far as I know, "client_information".pluralize have always been (incorrectly) returning "client_informations", meaning that fixing this might break certain apps out there. singularize and pluralize used to go through different code paths, but 52fa34f merged them into a single path, so it's no longer possible to just fix the bug introduced in 9b4622a without affecting the other direction as well. (I don't think that's a very reasonable behaviour anyways.)

chancancode added a commit to chancancode/rails that referenced this issue Jul 23, 2012

Correctly apply inflection rules on uncountable multi-word strings.
Currently, apply_inflections does not take into account that the input might be a multi-word string separated by underscore. (tableize etc relies on this behavior to work correctly.) This bug affects only uncountable multi-word strings separated by underscores:

   "funky jeans".singularize # => "funky jeans"
   "client information".pluralize # => "client information"

   "funky_jeans".singularize # => "funky_jean"
   "client_information".pluralize # => "client_informations"

It's also worth pointing out that "funky_jeans".singularize used to work correctly before 9b4622a, which was merged almost 2 years ago so this is essentially broken since Rails 3.

On the other hand, it appears that "client_information".pluralize has always been broken, so this does change the behavior of tableize and could potentially break some older apps out there.

Closes #7132.
@steveklabnik

This comment has been minimized.

Show comment Hide comment
@steveklabnik

steveklabnik Sep 21, 2012

Member

Generally, the inflector is frozen. I'll defer to @fxn on this particular case, though.

Member

steveklabnik commented Sep 21, 2012

Generally, the inflector is frozen. I'll defer to @fxn on this particular case, though.

@blakewatters

This comment has been minimized.

Show comment Hide comment
@blakewatters

blakewatters Nov 3, 2012

+1 This is an irritating case that is easily fixed by applying this existing rules across the words

+1 This is an irritating case that is easily fixed by applying this existing rules across the words

@ghost ghost assigned fxn Oct 13, 2013

@rafaelfranca

This comment has been minimized.

Show comment Hide comment
@rafaelfranca

rafaelfranca Oct 13, 2013

Owner

@fxn could you take a look?

Owner

rafaelfranca commented Oct 13, 2013

@fxn could you take a look?

@chancancode

This comment has been minimized.

Show comment Hide comment
@chancancode

chancancode Dec 1, 2013

Member

Since the PR fixing this issue (#7134) has been rejected, this should probably be closed as well!

Member

chancancode commented Dec 1, 2013

Since the PR fixing this issue (#7134) has been rejected, this should probably be closed as well!

@chancancode chancancode closed this Dec 1, 2013

@fxn

This comment has been minimized.

Show comment Hide comment
@fxn

fxn Dec 2, 2013

Owner

Yeah, this is something that has been discussed in the past. Basically, the behaviour of singularize and friends on multi-word strings is undefined, their contract only includes whole words.

Owner

fxn commented Dec 2, 2013

Yeah, this is something that has been discussed in the past. Basically, the behaviour of singularize and friends on multi-word strings is undefined, their contract only includes whole words.

@rafaelfranca rafaelfranca removed the stale label Apr 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment