aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/string_ext_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #36185 from jonathanhefner/optimize-string-first-and-lastRafael França2019-07-281-12/+20
|\ | | | | Improve String#first and #last performance
| * Improve String#first and #last performanceJonathan Hefner2019-05-051-12/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Removes unnecessary conditional and method call for significant performance improvement. As a side effect, this fixes an unexpected behavior where passing a limit of 0 would return a frozen string. This also implements the Rails 6.1 intended behavior with regards to negative limits, and removes the previous deprecation warnings. String#first Comparison: new: 3056515.0 i/s old: 1943310.2 i/s - 1.57x slower String#last Comparison: new: 2691919.0 i/s old: 1924256.6 i/s - 1.40x slower (Note: "old" benchmarks have deprecation warnings commented out, for a more fair comparison.)
* | Remove tough to grasp -1 + 1 = 0 from String#toKasper Timm Hansen2019-07-261-0/+2
|/ | | | | | | | | | | In case a negative position is provided that exceeds the size of the string, we're relying on -1 returned from max to get 0 length by + 1 and let [] with a 0 length returning "" for us. E.g. "hello".to(-7), where -7 + 5 size = -2. That's lower than -1, so we use -1 instead and + 1 would turn it into 0. Instead allow outer bounds access and always return "".
* Frozen truncate (#36109)Jordan Thomas2019-04-261-0/+5
| | | | | | | | | | | | | | * Add test asserting truncate returns unfrozen string * Ensure strings returned from truncate are not frozen This fixes an issue where strings too short to be truncated were returned unfrozen, where as long-enough strings were returned frozen. Now retuned strings will not be frozen whether or not the string returned was shortened. * Update changelog w/ new truncate behavior description [Jordan Thomas + Rafael Mendonça França]
* Fix bug with parametrize when `locale` is passedSharang Dashputre2019-03-121-0/+6
| | | | Also add tests for parametrize and transliterate
* Merge pull request #33058 from gmcgibbon/string_first_last_negative_deprecationRafael França2018-10-021-0/+18
|\ | | | | Add deprecation warning when String#first and String#last receive neg…
| * Add deprecation warning when String#first and String#last receive negative ↵Gannon McGibbon2018-09-281-0/+18
| | | | | | | | | | | | integers [Gannon McGibbon + Eric Turner]
* | Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-291-1/+1
|/ | | | | | | | | | | | | | | | | | | | | Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb'
* Handle more unsafe String methods (#33990)Janosch Müller2018-09-271-0/+48
| | | | | | | | | | * Handle more unsafe String methods * Fix codeclimate issue * Revert stylistic change [Janosch Müller + Rafael Mendonça França]
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-2/+2
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* String#truncate_bytes: limit to N bytes without breaking multibyte charsJeremy Daer2018-02-181-0/+62
| | | | | This faithfully preserves grapheme clusters (characters composed of other characters and combining marks) and other multibyte characters.
* `String#strip_heredoc` preserves frozennessJeremy Daer2018-02-171-0/+4
| | | | | | | | | | | | | | | | | | ```ruby "foo".freeze.strip_heredoc.frozen? # => true ``` Fixes the case where frozen string literals would inadvertently become unfrozen: ```ruby foo = <<-MSG.strip_heredoc la la la MSG foo.frozen? # => false !?? ```
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-161-1/+1
| | | | | Some places we can't remove because Ruby still don't have a method equivalent to strip_heredoc to be called in an already existent string.
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-31/+31
|
* Fixed typo in test for activesupport parameterizePierre Hedkvist2017-11-011-1/+1
|
* Update String#camelize to provide feedback when wrong option is passedRicardo Díaz2017-08-021-0/+7
| | | | | | | | | String#camelize was returning nil without any feedback when an invalid option was passed as parameter. This update makes the method to raises an ArgumentError when the option passed is invalid, similar to what Ruby does for String#downcase (and others) in 2.4.1. https://ruby-doc.org/core-2.4.1/String.html#method-i-downcase
* [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.
* Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
|\ | | | | | | Enforce frozen string in Rubocop
| * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
* | Make ActiveSupport frozen string literal friendly.Pat Allan2017-06-201-9/+10
|/ | | | | | | The ActiveSupport test suite only passes currently if it uses the latest unreleased commits for dalli, and a patch for Builder: https://github.com/tenderlove/builder/pull/6 Beyond that, all external dependencies (at least, to the extent they’re used by ActiveSupport) are happy, including Nokogiri as of 1.8.0.
* Merge pull request #28480 from ↵Rafael Mendonça França2017-03-281-0/+12
|\ | | | | | | | | | | 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/+12
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Add more missing requiresAndrew White2017-02-221-0/+1
| | | | | | | | Further missing requires for Timeout exposed due to Bundler 1.14.5
* | Reduce string objects by using \ instead of + or << for concatenating stringsAkira Matsuda2017-01-121-1/+1
| | | | | | | | (I personally prefer writing one string in one line no matter how long it is, though)
* | assert_equal takes expectation firstAkira Matsuda2016-12-261-9/+9
| |
* | "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-1/+1
|/
* Remove deprecated separator argument from parameterizeAndrew White2016-11-141-16/+0
|
* modernizes hash syntax in activesupportXavier Noria2016-08-061-15/+15
|
* applies new string literal convention in activesupport/testXavier Noria2016-08-061-62/+62
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-11/+11
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* Fix tests when preserving timezonesAndrew White2016-05-051-4/+11
| | | | | | These two tests are explicitly testing that to_time is returning times with the sytem timezone's UTC offset, therefore they will fail when running them with `ActiveSupport.to_time_preserves_timezone = true`.
* Fix to_yaml test when run individuallyAndrew White2016-05-051-0/+1
| | | | | | | | | The to_yaml method is undefined when running the test as: $ ruby -I lib:test test/core_ext/string_ext_test.rb Doesn't fail when running rake test:isolated presumably because something else has required 'yaml' already.
* Match `String#to_time`'s behaviour to rubySiim Liiser2016-04-041-0/+1
| | | | | | | | Previously `String#to_time` returned the midnight of the current date in some cases where there was no relavant information in the string. Now the method returns `nil` instead in those cases. Fixes #22958.
* Fix method String#upcase_firstbogdanvlviv2016-03-311-0/+8
|
* Add upcase_first methodGlauco Custódio2016-02-251-0/+4
|
* Parameterize with options to preserve case of stringSwaathi K2015-11-071-2/+36
| | | | | | | | | | | | | | | | | | | | | | | | 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
* Handle invalid UTF-8 strings when HTML escapingGrey Baker2015-06-081-2/+8
| | | | | | | Use `ActiveSupport::Multibyte::Unicode.tidy_bytes` to handle invalid UTF-8 strings in `ERB::Util.unwrapped_html_escape` and `ERB::Util.html_escape_once`. Prevents user-entered input passed from a querystring into a form field from causing invalid byte sequence errors.
* Removed mocha stubbing in active_supportRonak Jangir2015-06-071-86/+92
|
* Merge pull request #19076 from nygrenh/truncate-words-fixRafael Mendonça França2015-02-251-0/+9
|\ | | | | | | Fix a backtracking problem in String#truncate_words
| * Fix a backtracking problem in String#truncate_wordsHenrik Nygren2015-02-251-0/+9
|/ | | | Fixes #19070.
* Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 ↵Vipul A M2015-02-031-1/+0
| | | | onwards.
* Remove deprecated `ActiveSupport::SafeBuffer#prepend`Rafael Mendonça França2015-01-041-10/+0
|
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-6/+2
|
* added example of squish!, remove, test case for multiple occurrence ofRishi Jain2014-11-061-0/+6
| | | | | | | | pattern removal added example for string#remove and test case for remove of multiple occurence of pattern removed extra whitespaces
* tests, add note about the usage of a specific timezone. Closes #17448.Yves Senn2014-11-051-1/+1
|
* Fix broken string_ext_test due to change in timezonePrathamesh Sonpatki2014-11-051-1/+1
| | | | | - Russian time was changed to UTC+3 from UTC+4 recently. This broke the string_to_ext test.
* Make `String#remove` and `String#remove!` accept multiple argumentsPavel Pravosud2014-10-251-2/+12
|