aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
Commit message (Collapse)AuthorAgeFilesLines
* Remove deprecated `Module#reachable?` methodRafael Mendonça França2019-01-171-51/+0
|
* Tweak test nameGeorge Claghorn2018-12-301-1/+1
|
* Make Active Storage blob keys lowercaseJulik Tarkhanov2018-12-301-0/+20
| | | Accommodate case-insensitive filesystems and database collations.
* No need to handle if FrozenError is availableYasuo Honda2018-12-231-1/+1
| | | | | | | Rails 6 requires Ruby 2.5, which introduces `FrozenError` https://docs.ruby-lang.org/en/2.5.0/NEWS.html Related to #31520
* Fixes `warning: mismatched indentations at 'rescue' with 'def' at 15`.utilum2018-12-211-2/+2
| | | | See https://travis-ci.org/rails/rails/jobs/470890129#L2361
* Merge pull request #34764 from kamipo/avoid_redundant_beginRyuta Kamizono2018-12-211-4/+3
|\ | | | | Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin block
| * Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-211-4/+3
| | | | | | | | | | | | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* | Follow up #34754bogdanvlviv2018-12-201-28/+6
|/ | | | | | | - Fix a few deprecation warnings - Remove testing of `Hash#slice` - Imporve test of `Hash#slice!` - Remove mention about `Hash#slice` from the guide
* Remove remaining tests for `Hash#transform_keys` and `Hash#transform_keys!`Ryuta Kamizono2018-12-211-27/+0
| | | | Follow up #34761.
* Use native `Array#append`, `Array#prepend`, `Hash#transform_keys`, and ↵Ryuta Kamizono2018-12-202-71/+4
| | | | | | | | | | `Hash#transform_keys!` Since Rails 6 requires Ruby 2.5. https://github.com/ruby/ruby/blob/ruby_2_5/NEWS Follow up #34754.
* Merge pull request #34037 from reitermarkus/atomic_write-permissionsRafael França2018-11-221-0/+14
|\ | | | | `atomic_write`: Ensure correct permission when `tmpdir` is the same as `dirname`.
| * Ensure correct permission when `tmpdir` is the same as `dirname`.Markus Reiter2018-10-021-0/+14
| |
* | Fix issue where duration where always rounded up to a second:Edouard CHIN2018-10-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Adding a Float as a duration to a datetime would result in the Float being rounded. Doing something like would have no effect because the 0.45 seconds would be rounded to 0 second. ```ruby time = DateTime.parse("2018-1-1") time += 0.45.seconds ``` This behavior was intentionally added a very long time ago, the reason was because Ruby 1.8 was using `Integer#gcd` in the constructor of Rational which didn't accept a float value. That's no longer the case and doing `Rational(0.45, 86400)` would now perfectly work fine. - Fixes #34008
* | Prefix Module#parent, Module#parents, and Module#parent_name with moduleGannon McGibbon2018-10-021-11/+29
| |
* | 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]
* | Fix spellings for 'unmarshall(ing/ed)' & 'marshall(ing/ed)'Sharang Dashputre2018-10-021-19/+19
| |
* | Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-293-4/+4
|/ | | | | | | | | | | | | | | | | | | | | 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]
* Change the empty block style to have space inside of the blockRafael Mendonça França2018-09-254-7/+7
|
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-232-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ```
* Fix obsoleted method URI.unescape in activesupport/testVitor Oliveira2018-08-151-1/+1
|
* Add `Array#extract!`bogdanvlviv2018-08-141-0/+44
| | | | | | | | | | | The method removes and returns the elements for which the block returns a true value. If no block is given, an Enumerator is returned instead. ``` numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] odd_numbers = numbers.extract! { |number| number.odd? } # => [1, 3, 5, 7, 9] numbers # => [0, 2, 4, 6, 8] ```
* e4e1b62 broke `to_param` handling:Edouard CHIN2018-07-121-0/+14
| | | | | | | | | | | | | | | | | | | - There was an issue inside controller tests where order params were not respected, the reason was because we were calling `Hash#to_query` which sorts the results lexicographically. 1e4e1b62 fixed that issue by not using `to_query` but instead a utility function provided by rack. - However with the fix came another issue where it's now no longer possible to do this ``` post :foo, params: { user: User.first } # Prior to the patch the controller will receive { "user" => "1" } # Whereas now you get { "user": "#<User: ...>" } ``` The fix in this PR is to modify `Hash#to_query` to sort only when it doesn't contain an array structure that looks something like "bar[]" Ref https://github.com/rails/rails/pull/33341#issuecomment-404039396
* Add tests for duration multiplication and divisionEugene Kenny2018-06-251-0/+12
| | | | | | | | | | | When multiplying or dividing a duration by a scalar, it's tempting to operate directly on the duration's value in seconds and recompute the parts from the result. However this loses information, as there are multiple combinations of parts that map to any given number of seconds (e.g. `2.weeks` or `336.hours`). This is especially problematic when dealing with durations on the scale of months or years, as converting an exact number of seconds to one of those intervals and then using the resulting duration to modify a date will give the wrong result.
* Add Enumerable#index_with.Kasper Timm Hansen2018-05-211-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the app I'm working on I've wished that index_by had a buddy that would assign the hash value instead of the key multiple times. Enter index_with. Useful when building a hash from a static list of symbols. Before you'd do: ```ruby POST_ATTRIBUTES.map { |attr_name| [ attr_name, public_send(attr_name) ] }.to_h ``` But now that's a little clearer and faster with: ````ruby POST_ATTRIBUTES.index_with { |attr_name| public_send(attr_name) } ``` It's also useful when you have an enumerable that should be converted to a hash, but you don't want to muddle the code up with the overhead that it takes to create that hash. So before, that's: ```ruby WEEKDAYS.each_with_object(Hash.new) do |day, intervals| intervals[day] = [ Interval.all_day ] end ``` And now it's just: ```ruby WEEKDAYS.index_with([ Interval.all_day ]) ``` It's also nice to quickly get a hash with either nil, [], or {} as the value.
* Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-131-1/+1
| | | | Follow up of #32605.
* Remove `test_match_p` since Rails 6 requires Ruby 2.4.1 or newerRyuta Kamizono2018-05-071-24/+0
| | | | Follow up of #32034.
* Fix #29632 - nil #path leads to NoMethodError in LoadError#is_missing?Neil Souza2018-05-041-0/+7
| | | | | | | | See #29632 for details. In short, it's possible to enter `LoadError#is_missing?` when `LoadError#path` returns `nil`, leading to `path.sub` throwing an none-to-helpful `NoMethodError`. This tiniest of patch inserts `#to_s` before the `sub` call to make sure it succeeds. Affected surface area should be just as tiny since something has already gone wrong to get us into `#is_missing?` and the current behavior when `#path` returns `nil` seems clearly not intended. [Gannon McGibbon + Neil Souza]
* Replace `assert !` with `assert_not`Daniel Colson2018-04-1911-42/+42
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Move implementation of `before?` and `after?` to `DateAndTime::Calculations`bogdanvlviv2018-03-314-36/+12
| | | | | | | | This prevents duplication of code. Prevent duplication of tests by moving them to `DateAndTimeBehavior`. Related to #32185.
* Merge pull request #32185 from nholden/human_readable_date_time_comparisonsRafael França2018-03-264-0/+50
|\ | | | | Add `before?` and `after?` methods to date and time classes
| * Add `before?` and `after?` methods to date and time classesNick Holden2018-03-064-0/+50
| | | | | | | | | | | | | | | | Equality comparisons between dates and times can take some extra time to comprehend. I tend to think of a date or time as "before" or "after" another date or time, but I naturally read `<` and `>` as "less than" and "greater than." This change seeks to make date/time comparisons more human readable.
* | Use try in tests that try to test try.Kasper Timm Hansen2018-03-211-7/+2
| |
* | URI.unescape handles mixed Unicode/escaped inputAshe Connor2018-03-071-1/+1
|/ | | | | | | | | | | | | | | | | | Previously, URI.enscape could handle Unicode input (without any actual escaped characters), or input with escaped characters (but no actual Unicode characters) - not both. URI.unescape("\xe3\x83\x90") # => "バ" URI.unescape("%E3%83%90") # => "バ" URI.unescape("\xe3\x83\x90%E3%83%90") # => # Encoding::CompatibilityError We need to let `gsub` handle this for us, and then force back to the original encoding of the input. The result String will be mangled if the percent-encoded characters don't conform to the encoding of the String itself, but that goes without saying. Signed-off-by: Ashe Connor <ashe@kivikakk.ee>
* Deprecate "active_support/core_ext/numeric/inquiry"bogdanvlviv2018-03-021-80/+3
| | | | | | Numeric#positive? and Numeric#negative? was added to Ruby since 2.3, see https://github.com/ruby/ruby/blob/ruby_2_3/NEWS Rails 6 requires Ruby 2.4.1+ since https://github.com/rails/rails/pull/32034
* Deprecate `active_support/core_ext/hash/compact`yuuji.yaginuma2018-03-021-34/+4
| | | | | Ruby 2.4+ provides `Hash#compact` and `Hash#compact!` natively, so `active_support/core_ext/hash/compact` is no longer necessary.
* Add separate test to ensure that `delegate` with `:private` option returns ↵bogdanvlviv2018-02-281-6/+16
| | | | | | | | correct value Remove extra comments `# Asking for private method` in activesupport/test/core_ext/module_test.rb Improve docs of using `delegate` with `:private` Update changelog of #31944
* add private: true option for ActiveSupport delegateTomas Valent2018-02-261-0/+57
|
* 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 !?? ```
* Rails 6 requires Ruby 2.4.1+Jeremy Daer2018-02-174-79/+9
| | | | | | Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug. References #32028
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-162-6/+5
| | | | | 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.
* Add missing requireyuuji.yaginuma2018-02-081-0/+1
| | | | | Without this require, an error occurs when executing only `duration_test.rb`. Ref: https://travis-ci.org/rails/rails/jobs/338817558#L2205-L2210
* Merge pull request #31923 from jdelStrother/duration-deserializationRafael França2018-02-071-0/+6
|\ | | | | Fix yaml deserialization of ActiveSupport::Duration
| * Fix yaml deserialization of ActiveSupport::DurationJonathan del Strother2018-02-071-0/+6
| | | | | | | | | | | | This ensures the duration's @parts hash has a default value, to avoid this regression introduced in 5.1: YAML.load(YAML.dump(10.minutes)) + 1 # => NoMethodError: undefined method `+' for nil:NilClass
* | Remove extra whitespaceDaniel Colson2018-01-253-39/+39
| |
* | Use assert_predicate and assert_not_predicateDaniel Colson2018-01-2511-80/+80
| |
* | Change refute to assert_notDaniel Colson2018-01-251-2/+2
| |
* | Use respond_to test helpersDaniel Colson2018-01-257-33/+33
| |