Commit Graph

122 Commits

Author SHA1 Message Date
Michael Grosser
203998c916
allow running each test with pure ruby path/to/test.rb
also:
 - makes test dependencies obvious
 - makes tests runnable from within subfolders
2019-12-18 08:49:19 -06:00
Sharang Dashputre
818437c366 Fix bug with parametrize when locale is passed
Also add tests for parametrize and transliterate
2019-03-12 01:48:21 +05:30
Rafael Mendonça França
0ce67d3cd6
Remove deprecated #acronym_regex method from Inflections 2019-01-17 16:08:33 -05:00
Daniel Colson
82c39e1a0b Use assert_empty and assert_not_empty 2018-01-25 23:32:59 -05:00
Daniel Colson
94333a4c31 Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
Matthew Draper
52483d3fa0
Merge pull request #30782 from NickLaMuro/improve_performance_of_inflections
Cache regexps generated from acronym_regex
2017-11-14 11:10:16 +10:30
Andrew White
0ddde0a8fc Fix acronym support in humanize
Acronym inflections are stored with lowercase keys in the hash but
the match wasn't being lowercased before being looked up in the hash.
This shouldn't have any performance impact because before it would
fail to find the acronym and perform the `downcase` operation anyway.

Fixes #31052.
2017-11-06 14:47:47 +00:00
Nick LaMuro
b2545e4106 Deprecate ActiveSupport::Inflector#acronym_regex
To be removed in Rails 6.0 (default for the deprecate helper).  Code
moved around as well for the ActiveSupport::Deprecation modules, since
it was dependent on ActiveSupport::Inflector being loaded for it to
work.  By "lazy loading" the Inflector code from within the Deprecation
code, we can require ActiveSupport::Deprecation from
ActiveSupport::Inflector and not get a circular dependency issue.
2017-10-28 17:32:32 -05:00
Koichi ITO
ac717d65a3 [Active Support] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
Kir Shatrov
72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Eilis Hamilton
7c45146b15 Fix pluralization of uncountables when given a locale
Previously apply_inflections would only use the :en uncountables
rather then the ones for the locale that was passed to pluralize or
singularize.

This changes apply_inflections to take a locale which it will use to
find the uncountables.
2017-05-19 13:58:19 +12:00
Rafael Mendonça França
0875256fe9
Merge pull request #28480 from mubashirhanif/add_keep_id_suffix_option_to_humanize_new
Add keep id suffix option to humanize new
2017-03-28 17:57:17 -04:00
Mubashir Hanif
f0c8f1b085 Added options hash to titleize method and keep_id_suffix option to humanize
some documentation

remove extra whitespace.

Added id in the middle test case and corrected some testcases.

Some Coding standard guidelines corrections as suggested by codeclimate.

Some more corrections suggested by codeclimate.
2017-03-21 22:55:17 +01:00
Akira Matsuda
ed7a3cde67 This seems to be working on JRuby 9K
% ruby -ve "p 'ほげ'.encode(Encoding::UTF_8_MAC)"
jruby 1.7.26 (1.9.3p551) 2016-08-26 69763b8 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14 +jit [darwin-x86_64]
"\u307B\u3052"

% ruby -ve "p 'ほげ'.encode(Encoding::UTF_8_MAC)"
jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [darwin-x86_64]
"\u307B\u3051\u3099"

% ruby -ve "p 'ほげ'.encode(Encoding::UTF_8_MAC)"
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin14]
"\u307B\u3051\u3099"
2017-01-25 18:27:52 +09:00
Prathamesh Sonpatki
11b6f9e06a
Make the tests for uncountability of ascii and non-ascii words uniform 2016-12-31 09:51:43 +05:30
Matthew Draper
c3ff36815c Merge pull request #12509 from eitoball/pluralize_for_non_ascii_character_words
Fix ActiveSupport::Inflector.pluralize behavior for words that consist of non-ASCII characters

(test only; the original bug was fixed by 1bf50badd943e684a56a03392ef0ddafefca0ad7)
2016-12-31 11:47:24 +10:30
Andrew White
0189f4db6f Remove deprecated separator argument from parameterize 2016-11-14 12:14:23 +00:00
Ryuta Kamizono
3464cd5c28 Fix broken comments indentation caused by rubocop auto-correct [ci skip]
All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772.
But comments was still kept absolute position. This commit aligns
comments with method definitions for consistency.
2016-09-14 18:26:32 +09:00
Ryuta Kamizono
762e3f05f3 Add Style/EmptyLines in .rubocop.yml and remove extra empty lines 2016-08-07 17:50:59 +09:00
Xavier Noria
a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Swaathi K
c9143e15a1 Parameterize with options to preserve case of string
Added test cases

Using kwargs instead of three seperate functions

Updated parameterize in transliterate.rb

Updated parameterize in transliterate.rb

Added deprecation warnings and updating RDoc+Guide

Misspelled separtor. Fixed.

Deprecated test cases and added support to parameterize with keyword parameters

Squashing commits.

Fixed test cases and added deprecated test cases

Small changes to Gemfile.lock and CHANGELOG

Update Gemfile.lock
2015-11-07 16:57:04 +05:30
Eito Katagiri
c7fc843431 fix pluralize behavior for words that consist of non-ascii characters
The code below returns "猫" in 3.2, but "猫s" in 4.0.
```ruby
ActiveSupport::Inflector.inflections do |inflect|
  inflect.uncountable "猫"
end
"猫".pluralize
```
2015-07-02 09:53:34 +09:00
Roque Pinel
c1a694d9d2 Fix inflector test by using dup inflections when it needs to be changed
This is not something that is failing at the moment, but can do it
eventually. I had the issue with db62081 as the HEAD and with the
following change:

```
--- a/activesupport/test/inflector_test.rb
+++ b/activesupport/test/inflector_test.rb
@@ -101,6 +101,7 @@ class InflectorTest < ActiveSupport::TestCase
   def test_acronyms
     ActiveSupport::Inflector.inflections do |inflect|
       inflect.acronym("API")
+      inflect.acronym("HTM")
       inflect.acronym("HTML")
       inflect.acronym("HTTP")
       inflect.acronym("RESTful")
```

I was expecting only `test_acronyms` to fail, but with a specific `seed`
others were also failing: `ruby -w -I"lib:test" test/inflector_test.rb
--seed 4313`.

Now, `inflections` instance is duplicated on `setup` and restored on
`teardown`.

I decided to benchmark and check the impact of the patch and it seems
to me to be fine.

```
Calculating -------------------------------------
     without changes     1.000  i/100ms
      with setup dup     1.000  i/100ms
      with block dup     1.000  i/100ms
-------------------------------------------------
     without changes      0.817  (± 0.0%) i/s -      5.000  in
     6.119916s
      with setup dup      0.784  (± 0.0%) i/s -      4.000
      with block dup      0.797  (± 0.0%) i/s -      4.000
```

Where `with setup dup` duplicates on setup for each test and `with block`
duplicates for just for tests that actually modify `inflections`.
2015-06-15 08:46:20 -04:00
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 fa3ef8e82ab2f96cf15ef9bc885b2468fad77621, reversing
changes made to e0af93dd3a5eeee2e2a67b05f34afb66cc80c00b.

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 7db0b073fec6bc3e6f213b58c76e7f43fcc2ab97,
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 867dc1700f32aae6f98c4651bd501597e6b52bc0, reversing
changes made to 9a421aaa8285cf2a7ecb1af370748b0337818930.

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