aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/inflector_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix bug with parametrize when `locale` is passedSharang Dashputre2019-03-121-0/+6
| | | | Also add tests for parametrize and transliterate
* Remove deprecated `#acronym_regex` method from `Inflections`Rafael Mendonça França2019-01-171-6/+0
|
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-14/+14
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-14/+14
|
* Merge pull request #30782 from NickLaMuro/improve_performance_of_inflectionsMatthew Draper2017-11-141-0/+6
|\ | | | | Cache regexps generated from acronym_regex
| * Deprecate ActiveSupport::Inflector#acronym_regexNick LaMuro2017-10-281-0/+6
| | | | | | | | | | | | | | | | | | 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.
* | Fix acronym support in `humanize`Andrew White2017-11-061-0/+13
|/ | | | | | | | | 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.
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-091-0/+1
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Fix pluralization of uncountables when given a localeEilis Hamilton2017-05-191-0/+7
| | | | | | | | | 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.
* Merge pull request #28480 from ↵Rafael Mendonça França2017-03-281-0/+13
|\ | | | | | | | | | | mubashirhanif/add_keep_id_suffix_option_to_humanize_new Add keep id suffix option to humanize new
| * Added options hash to titleize method and keep_id_suffix option to humanizeMubashir Hanif2017-03-211-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | This seems to be working on JRuby 9KAkira Matsuda2017-01-251-10/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | % 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"
* | Make the tests for uncountability of ascii and non-ascii words uniformPrathamesh Sonpatki2016-12-311-11/+21
| |
* | Merge pull request #12509 from eitoball/pluralize_for_non_ascii_character_wordsMatthew Draper2016-12-311-0/+8
|\ \ | |/ |/| | | | | | | Fix ActiveSupport::Inflector.pluralize behavior for words that consist of non-ASCII characters (test only; the original bug was fixed by 1bf50badd943e684a56a03392ef0ddafefca0ad7)
| * fix pluralize behavior for words that consist of non-ascii charactersEito Katagiri2015-07-021-0/+9
| | | | | | | | | | | | | | | | | | | | The code below returns "猫" in 3.2, but "猫s" in 4.0. ```ruby ActiveSupport::Inflector.inflections do |inflect| inflect.uncountable "猫" end "猫".pluralize ```
* | Remove deprecated separator argument from parameterizeAndrew White2016-11-141-18/+0
| |
* | Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-6/+6
| | | | | | | | | | | | 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.
* | Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
| |
* | applies new string literal convention in activesupport/testXavier Noria2016-08-061-26/+26
| | | | | | | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* | Parameterize with options to preserve case of stringSwaathi K2015-11-071-2/+20
|/ | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix inflector test by using dup inflections when it needs to be changedRoque Pinel2015-06-151-86/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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`.
* Replace Enumerable#reverse.each with Enumerable#reverse_eachErik Michaels-Ober2014-10-131-2/+2
|
* Fix underscore inflector handling of adjacent acronymsJames Le Cuirot2014-10-031-0/+3
| | | | | | | | | | | | | 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.
* Fix for inflector's incorrect camelCase replacement for acronymsMatthew Draper2014-09-061-0/+1
| | | | | | Fixes #8015, #9756. [Fred Wu & Matthew Draper]
* Make the apply_inflections method case-sensitiveRobin Dupret2014-06-261-0/+8
| | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #15316 from akshay-vishnoi/test-casesYves Senn2014-05-261-7/+8
|\ | | | | | | Fix test cases for inflector.rb
| * Fix test cases for inflector.rbAkshay Vishnoi2014-05-251-7/+8
|/ | | | | | `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.
* Add more test case for #demodulize, Improve documentationAkshay Vishnoi2014-04-111-0/+1
|
* wrap test that changes inflections in with_dupLihan Li2013-11-281-4/+5
|
* Add +capitalize+ option to Inflector.humanizeclaudiob2013-11-061-0/+6
| | | | | | | So strings can be humanized without being capitalized: 'employee_salary'.humanize # => "Employee salary" 'employee_salary'.humanize(capitalize: false) # => "employee salary"
* Skip few of the ActiveSupport'sinflector test on JRubyGaurish Sharma2013-08-211-0/+10
|
* Avoid calling define_method with non-english chars in InflectorTestGaurish Sharma2013-08-031-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* Don't mutate the original inflections instance in the testsAndrew White2013-07-301-19/+22
|
* Revert "Merge pull request #10158 from steveklabnik/issue_10125"Rafael Mendonça França2013-04-101-17/+0
| | | | | | | | This reverts commit fa3ef8e82ab2f96cf15ef9bc885b2468fad77621, reversing changes made to e0af93dd3a5eeee2e2a67b05f34afb66cc80c00b. Reason: Routes, Active Record and the rendering stack should not depend on the default locale
* Fix inflector to respect default locale.Nick Cox2013-04-101-0/+17
| | | | | | | | The inflector was made aware of locales in 7db0b073fec6bc3e6f213b58c76e7f43fcc2ab97, but it defaulted to :en. That should actually be our default locale instead. Fixes #10125
* fix repeat of test; remove unused variable by use of each_keyVipul A M2013-03-181-1/+1
|
* Revert "Merge pull request #8156 from fredwu/acronym_fix-master"Steve Klabnik2013-03-161-2/+0
| | | | | | | | | 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.
* Fixed a bug where the inflector would replace camelCase strings and ↵Fred Wu2013-03-171-0/+2
| | | | disregarding specified acronyms, fixes #8015
* Cleanup tests for unused variablesVipul A M2013-03-111-2/+0
|
* Remove assert_nothing_raisedRafael Mendonça França2013-01-031-1/+1
|
* Fix ActiveSupport tests that depend on run orderFrancesco Rodriguez2012-08-231-2/+2
|
* Make ActiveSupport::Inflector locale aware and multilingualDavid Celis2012-07-301-1/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Adds missing inflector tests to ensure idempotencyGodfrey Chan2012-06-211-0/+10
| | | | | | | | | | | | | 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.
* decouples the implementation of the inflector from its test suiteXavier Noria2012-02-241-73/+66
| | | | | | | | 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.
* Merge pull request #4719 from markmcspadden/singularize_words_that_end_in_ssXavier Noria2012-02-101-0/+8
|\ | | | | Add Inflection test (and fixes) to ensure singularizing a singular actually give you the correct singular in more cases
| * Add Inflection test (and fixes) to ensure singularizing a singular actually ↵Mark McSpadden2012-01-271-0/+8
| | | | | | | | give you the correct singular in more cases
* | Add ActiveSupport::Inflector.ordinal and Integer#ordinalTim Gildea2012-02-041-0/+6
|/