aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
Commit message (Collapse)AuthorAgeFilesLines
* Use Thread.pass instead of Kernel.sleep to trigger race conditionGuilherme Mansur2019-08-051-14/+7
|
* Able to initalize default value for thread_mattr_*Guilherme Mansur2019-08-051-11/+27
| | | | | | | | | | | | | | | | | Added the ability to initialize `thread_mattr_*` methods with default values like so: ``` ruby class MyClass thread_attr_reader :foo, default: :foo thread_attr_writer :bar, default: :bar thread_attr_accessor: baz do "baz" end end ``` This is consistent with the api exposed by `mattr_accessor`.
* Missing require AS/core_ext/date/conversionsAkira Matsuda2019-08-021-0/+1
|
* Let's try not to depend too much on other core extensions in a core ↵Akira Matsuda2019-08-021-1/+1
| | | | extension test
* require only what each test concernsAkira Matsuda2019-08-024-4/+7
|
* 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 "".
* | Merge pull request #36412 from robotdana/compact_blankRafael Mendonça França2019-07-251-0/+24
|\ \ | | | | | | | | | Add compact_blank shortcut for reject(&:blank?)
| * | Add compact_blank shortcut for reject(&:blank?)Dana Sherson2019-06-051-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I frequently find myself having to .compact but for blank. which means on an array reject(&:blank?) (this is fine), or, on a hash `.reject { |_k, v| v.blank? }` which is slightly more frustrating and i usually write it as .reject(&:blank?) first and am confused when it's trying to check if the keys are blank. I've added the analagous .compact_blank! where there's a reject! to build on (there's also a reject! in Set, but there's no other core_ext touching Set so i've left that alone)
* | | Omit marshal_dump & _dump from delegate_missing_toAaron Lipman2019-07-171-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Exclude missing marshal_dump and _dump methods from being delegated to an object's delegation target via the delegate_missing_to extension. This avoids unintentionally adding instance variables to an object during marshallization, should the delegation target be a method which would otherwise add them. In current versions of Ruby, a bug exists in the way objects are marshalled, allowing for instance variables to be added or removed during marshallization (see https://bugs.ruby-lang.org/issues/15968). This results in a corrupted serialized byte stream, causing an object's instance variables to "leak" into subsequent serialized objects during demarshallization. In Rails, this behavior may be triggered when marshalling an object that uses the delegate_missing_to extension, if the delegation target is a method which adds or removes instance variables to an object being marshalled - when calling Marshal.dump(object), Ruby's built in behavior will check whether the object responds to :marshal_dump or :_dump, which in turn triggers the delegation target method in the responds_to_missing? function defined in activesupport/lib/active_support/core_ext/module/delegation.rb While future versions of Ruby will resolve this bug by raising a RuntimeError, the underlying cause of this error may not be readily apparent when encountered by Rails developers. By excluding marshal_dump and _dump from being delegated to an object's target, this commit eliminates a potential cause of unexpected behavior and/or RuntimeErrors. Fixes #36522
* | | Implement UnboundMethod#duplicable?Jean Boussier2019-07-121-1/+1
| | |
* | | Delete `DateAndTime` method definition in rails that is compatible with ruby ↵soartec-lab2019-06-163-76/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | definition Tests are also only on the `Time` class Update doc forgetting to erase when moved Update guide `Date` class to `Time` class and defined file Update guide correction omission
* | | Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
|/ / | | | | | | | | | | | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* | ruby < 2.5 is no longer supportedAkira Matsuda2019-05-281-7/+2
| |
* | Add :allow_nil option to delegate_missing_to; use in ActiveStorageMatt Tanous2019-05-231-0/+14
|/ | | | attachment
* 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 in Range comparisons when comparing to excluded-end RangeOwen Stephens2019-03-281-2/+6
| | | | | | | | | | | | | | | Before: ```ruby (1..10).cover?(1...11) => false ``` After: ```ruby (1..10).cover?(1...11) => true ``` See https://git.io/fjTtz for the commit against Ruby core that added support for Range arguments, with similar handling of this case.
* Fix Time#advance to work with dates before 1001-03-07Andrew White2019-03-181-0/+2
| | | | | | | | | In #10634 the behavior of Time#advance was changed to maintain a proleptic gregorian calendar for dates before calendar reform. However it didn't full address dates a long time before calendar reform and they gradually drift away from the proleptic calendar the further you go back in time. Fix this by always converting the date to gregorian before calling advance which sets the reform date to -infinity.
* Fix bug with parametrize when `locale` is passedSharang Dashputre2019-03-121-0/+6
| | | | Also add tests for parametrize and transliterate
* Fix including/excluding flatteningGabriel Sobrinho2019-03-062-0/+3
|
* Added Array#including, Array#excluding, Enumerable#including, ↵David Heinemeier Hansson2019-03-052-3/+19
| | | | Enumerable#excluding
* Fix rubocop violationsyuuji.yaginuma2019-02-091-2/+2
|
* Delete uneeded blank fileGuillermo Iguaran2019-02-081-0/+0
|
* Add 'Hash#deep_transform_values', and 'Hash#deep_transform_values!'Guillermo Iguaran2019-02-082-0/+27
|
* 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.