Commit Graph

97 Commits

Author SHA1 Message Date
Erik Michaels-Ober 8bb33e920a Replace Enumerable#reverse.each with Enumerable#reverse_each 2014-10-13 11:47:16 +01:00
James Le Cuirot 6a8464fa4f Fix underscore inflector handling of adjacent acronyms
I suspect that positive lookbehind would have been used in the
original implementation had it been available in supported Ruby
versions at the time. Now that Rails requires Ruby 1.9.2 or above,
this is no longer an issue.

This fixes #14146 for acronyms such as APIRESTful. This technique also
addresses namespaced acronyms that are not entirely uppercased. This
was broken when the commit was originally written but has since been
fixed in ccbb481. The latter does not deal with adjacent acronyms so
this commit wins.
2014-10-03 22:45:40 +01:00
Matthew Draper ccbb48196e Fix for inflector's incorrect camelCase replacement for acronyms
Fixes #8015, #9756.

[Fred Wu & Matthew Draper]
2014-09-06 04:56:25 +09:30
Robin Dupret 643409dcb0 Make the apply_inflections method case-sensitive
Since d3071db1, 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 d3071db1  135.610000   0.290000  135.900000 (137.807081)
Since d3071db1   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.
2014-06-26 14:03:56 +02:00
Yves Senn 42fe948917 Merge pull request #15316 from akshay-vishnoi/test-cases
Fix test cases for inflector.rb
2014-05-26 08:56:26 +02:00
Akshay Vishnoi 93c193ed82 Fix test cases for inflector.rb
`yield` was missing in #with_dup, due to which 57 assertions were not running
in real, and all tests were passing by default.
Error was introduced in commit - 31ceb5e.
2014-05-25 21:36:02 +05:30
Akshay Vishnoi 075a1e21fa Add more test case for #demodulize, Improve documentation 2014-04-11 17:57:16 +05:30
Lihan Li 534b36093d wrap test that changes inflections in with_dup 2013-11-28 12:35:20 -05:00
claudiob c61544c781 Add +capitalize+ option to Inflector.humanize
So strings can be humanized without being capitalized:

    'employee_salary'.humanize                    # => "Employee salary"
    'employee_salary'.humanize(capitalize: false) # => "employee salary"
2013-11-06 13:03:46 -08:00
Gaurish Sharma a67b956d28 Skip few of the ActiveSupport'sinflector test on JRuby 2013-08-21 09:26:59 +05:30
Gaurish Sharma ab5e99ed63 Avoid calling define_method with non-english chars in InflectorTest
When we call define_method with non-english chars like ¿por qué? it
errors out on JRuby as of 1.7.4 & would leave out the following error

invalid byte sequence in US-ASCII

To work around this issue, I have switched to define_test method call
define method with fixed string & the index of the hash. the index was
added because otherwise, ruby will raise method redefined warning.

As far as I can see there are no side-effect of this change for
other implementations. For readbility I have added a message to
asssert_equal informing for which word/phase the test has passed.

Before this Change:
JRuby:
Tests terminated suddenly with an error. no reported of Failues
or errors
MRI:
All Green.

After this Change,
JRuby:
the `ActiveSupport` TestsSuite gracefully fails with report at the end which test failed & why.
MRI:
All Green(no change)
2013-08-03 18:21:17 +05:30
Andrew White 2d53ee0f42 Don't mutate the original inflections instance in the tests 2013-07-30 12:01:56 +01:00
Rafael Mendonça França d716fe05df Revert "Merge pull request #10158 from steveklabnik/issue_10125"
This reverts commit fa3ef8e82a, reversing
changes made to e0af93dd3a.

Reason: Routes, Active Record and the rendering stack should not depend
on the default locale
2013-04-10 12:44:39 -03:00
Nick Cox 8cf88cc75a Fix inflector to respect default locale.
The inflector was made aware of locales in 7db0b073fe,
but it defaulted to :en. That should actually be our default
locale instead.

Fixes #10125
2013-04-10 04:22:34 +00:00
Vipul A M 4bd8ccd984 fix repeat of test; remove unused variable by use of each_key 2013-03-18 19:58:02 +05:30
Steve Klabnik feaa6e2048 Revert "Merge pull request #8156 from fredwu/acronym_fix-master"
This reverts commit 867dc1700f, reversing
changes made to 9a421aaa82.

This breaks anyone who's using ForceSSL: https://travis-ci.org/rails-api/rails-api/jobs/5556065

Please see comments on #8156 for some discussion.
2013-03-16 15:25:49 -07:00
Fred Wu 515feb1fd6 Fixed a bug where the inflector would replace camelCase strings and disregarding specified acronyms, fixes #8015 2013-03-17 00:31:00 +11:00
Vipul A M 647a9abb02 Cleanup tests for unused variables 2013-03-11 16:03:10 +05:30
Rafael Mendonça França 59e0c2624a Remove assert_nothing_raised 2013-01-03 23:14:57 -03:00
Francesco Rodriguez cc14a3b2c1 Fix ActiveSupport tests that depend on run order 2012-08-23 16:00:58 -05:00
David Celis 7db0b073fe Make ActiveSupport::Inflector locale aware and multilingual
The Inflector is currently not very supportive of internationalized
websites. If a user wants to singularize and/or pluralize words based on
any locale other than English, they must define each case in locale
files. Rather than create large locale files with mappings between
singular and plural words, why not allow the Inflector to accept a
locale?

This patch makes ActiveSupport::Inflector locale aware and uses `:en`` unless
otherwise specified. Users will still be provided a list of English (:en)
inflections, but they may additionally define inflection rules for other
locales. Each list is kept separately and permanently. There is no reason to
limit users to one list of inflections:

    ActiveSupport::Inflector.inflections(:es) do |inflect|
      inflect.plural(/$/, 's')
      inflect.plural(/([^aeéiou])$/i, '\1es')
      inflect.plural(/([aeiou]s)$/i, '\1')
      inflect.plural(/z$/i, 'ces')
      inflect.plural(/á([sn])$/i, 'a\1es')
      inflect.plural(/é([sn])$/i, 'e\1es')
      inflect.plural(/í([sn])$/i, 'i\1es')
      inflect.plural(/ó([sn])$/i, 'o\1es')
      inflect.plural(/ú([sn])$/i, 'u\1es')

      inflect.singular(/s$/, '')
      inflect.singular(/es$/, '')

      inflect.irregular('el', 'los')
    end

    'ley'.pluralize(:es)   # => "leyes"
    'ley'.pluralize(:en)   # => "leys"
    'avión'.pluralize(:es) # => "aviones"
    'avión'.pluralize(:en) # => "avións"

A multilingual Inflector should be of use to anybody that is tasked with
internationalizing their Rails application.

Signed-off-by: David Celis <david@davidcelis.com>
2012-07-30 21:49:18 -07:00
Godfrey Chan fe933be5e2 Adds missing inflector tests to ensure idempotency
This is a follow up to #4719. It appears that singularize and pluralize
are supposed to be idempotent - i.e. when you call singularize or
pluralize multiple times on the same string, you should get the same
result. (At least for the "officially supported" cases that the stock
inflector is designed to handle.) #4719 added the missing tests for
regular cases, and this commit added the missing tests for the
irregularities.

While I'm at that, I also synced up the irregularity test cases with
the current set of irregularity cases that we ship out-of-the-box.
2012-06-21 02:16:48 -07:00
Xavier Noria 31ceb5e67b decouples the implementation of the inflector from its test suite
Trying alternative implementations of the inflections
is hard because the suite is coupled with the current
one, setting ivars by hand etc. This commit relies on
initialize_dup, as long as you maintain that one you
can tweak the implementation.
2012-02-24 15:06:17 -08:00
Xavier Noria 6728191494 Merge pull request #4719 from markmcspadden/singularize_words_that_end_in_ss
Add Inflection test (and fixes) to ensure singularizing a singular actually give you the correct singular in more cases
2012-02-10 11:14:10 -08:00
Tim Gildea 6fa0190fe4 Add ActiveSupport::Inflector.ordinal and Integer#ordinal 2012-02-04 18:25:54 +05:30
Mark McSpadden 532cd49530 Add Inflection test (and fixes) to ensure singularizing a singular actually give you the correct singular in more cases 2012-01-27 02:20:13 -06:00
Aaron Patterson b8d8c50785 use AS::TestCase as the base class 2012-01-05 17:12:46 -08:00
Xavier Noria 11f6795b23 defines Module#qualified_const_(defined?|get|set) and String#deconstantize
This commit also implements a faster version of #demodulize I was unable
to isolate with git add --patch.

Not a big fan of the name #deconstantize. It complements #demodulize
getting rid of the rightmost constant, hence the name, but it is
unrelated to the well-known #constantize. So unsure. Could not come
with anything better, please feel free to rename.
2011-10-29 18:10:45 -07:00
Xavier Noria 0fc531392d let demodulize do less work, and add tests
This is also faster on 1.9.
2011-10-29 01:07:54 -07:00
Ryan Oblak 310565f537 Added ActiveSupport::Inflector.safe_constantize and String#safe_constantize; refactored common constantize tests into ConstantizeTestCases 2011-09-23 15:36:33 +02:00
José Valim 6b010c2690 Revert removing gsub and sub from safe buffer. 2011-09-08 20:54:30 +02:00
Damien Mathieu 3718ccd2a6 remove support of symbols on classify and camelize 2011-09-08 10:22:21 +02:00
David Lee d38ca78dbd Add acronym support to Inflector; Issue #1366 2011-06-11 01:43:24 -07:00
David Lee f3e8bb8394 Test retain delimiter in parameterization inflector 2011-06-11 01:35:16 -07:00
Stefan Huber ba9891f13d proper reset all inflector scopes 2011-04-25 02:17:22 +01:00
Sam Elliott 9cf3b1f671 Remove warnings about redefined test methods
[#6490 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-01 12:39:04 -02:00
Dan Pickett 1754bd9b20 handle double pluralization for irregular plurals
[#6363]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-02-16 15:08:25 -02:00
Piotr Sarnacki 1a2c427991 Ensure that uncountable are removed after test 2010-12-22 09:44:46 +01:00
John Paul Ashenfelter 9b4622a483 Added a word boundary to uncountable inflection regex for #singularize so short inflections like ors do not affect larger words like sponsors [#6093 state:resolved] 2010-12-22 09:44:46 +01:00
Santiago Pastorino aacf2581cd refactor evals and adds some __FILE__ and __LINE__
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-20 15:18:57 +02:00
Prem Sichanugrist 82dd725fc1 Fix that irregular plural inflections should not be double-pluralized: 'people'.pluralize should return 'people' not 'peoples'.
[#1183 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-08-09 20:28:57 -07:00
Yehuda Katz + Carl Lerche 882dd4e605 ensure Inflector.camelize works with symbols [#2856 state:resolved]
Signed-off-by: Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>
2009-07-01 12:14:34 -07:00
Jeremy Kemper f28bd9557c Fix dependencies revealed by testing in isolation 2009-04-22 18:54:13 -07:00
Henrik N ea0e41d8fa Make Inflector#parameterize correctly squeeze multi-character separators [#1489 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2009-03-10 21:36:46 +00:00
Jeremy Kemper 1c36172c13 Ruby 1.9 compat: rename deprecated assert_raises to assert_raise.
[#1617 state:resolved]
2009-03-08 13:11:58 -07:00
Jeremy Kemper 2c43a6429e Ruby 1.9 compat: no Unicode normalization support yet 2008-11-26 17:59:35 -08:00
Adam Cigánek a4f2ba8fb3 Modified ActiveSupport::Inflector#parameterize with code from slugalizer (http://github.com/henrik/slugalizer)
Handles trailing and leading slashes, and squashes repeated separators into a single character.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1034 state:committed]
2008-09-23 08:08:21 +02:00
David Heinemeier Hansson 90366a1521 Added Inflector#parameterize for easy slug generation ("Donald E. Knuth".parameterize => "donald-e-knuth") #713 [Matt Darby] 2008-09-10 00:36:37 -05:00
Peter Wagenet a652c300ac New inflectors will overwrite defaults [#337 state:resolved]
Signed-off-by: Tarmo Tänav <tarmo@itech.ee>
2008-08-23 20:43:22 +03:00
Amos King 381210daa0 camelize(:lower) should always downcase first character. [#696 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2008-08-22 13:31:13 +01:00