aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
Commit message (Collapse)AuthorAgeFilesLines
...
| * 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-296-8/+8
|/ | | | | | | | | | | | | | | | | | | | | 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'
* Fix HashWithIndifferentAccess#without bugAbraham Chan2018-09-281-0/+11
|
* Handle more unsafe String methods (#33990)Janosch Müller2018-09-272-9/+82
| | | | | | | | | | * 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-2514-58/+58
|
* Merge pull request #33949 from sjain1107/no-private-defKasper Timm Hansen2018-09-231-13/+14
|\ | | | | Remove private def
| * Remove private defSakshi Jain2018-09-231-13/+14
| |
* | Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-238-32/+32
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ```
* Merge pull request #27792 from tjoyal/sandbox-tagged-loggingRafael Mendonça França2018-09-111-8/+21
|\ | | | | | | TaggedLogging to return a new logger instance
| * TaggedLogging to return a new logger instanceThierry Joyal2017-02-271-8/+21
| |
* | Add #unfreeze_time to ActiveSupport::Testing::TimeHelpersryanwhocodes2018-09-101-0/+4
| |
* | trace autoloads, and document hints for troubleshootingXavier Noria2018-09-071-0/+49
| | | | | | | | Closes #32885.
* | Use assert_predicate insteadYumin Wong2018-09-061-2/+2
| | | | | | | | Co-authored-by: no-itsbackpack <no-itsbackpack@github.com>
* | SafeBuffer should maintain safety upon getting a slice via a range if ↵Yumin Wong2018-08-311-0/+12
| | | | | | | | | | | | original buffer was safe. Co-Authored-By: no-itsbackpack <no-itsbackpack@github.com>
* | Remove redundant `travel_back`yuuji.yaginuma2018-08-311-5/+0
| | | | | | | | Since #29860, `travel_back` automatically called at the end of the test.
* | Merge pull request #33162 from utilum/stop_using_mochaKasper Timm Hansen2018-08-221-0/+83
|\ \ | | | | | | Stop using Mocha
| * | Add method_call_assertions and use them instead of Mochautilum2018-08-131-0/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Six Mocha calls prove quite resistant to Minitestification. For example, if we replace ``` ActiveRecord::Associations::HasManyAssociation .any_instance .expects(:reader) .never ``` with `assert_not_called`, Minitest wisely raises ``` NameError: undefined method `reader' for class `ActiveRecord::Associations::HasManyAssociation' ``` as `:reader` comes from a deeply embedded abstract class, `ActiveRecord::Associations::CollectionAssociation`. This patch tackles this difficulty by adding `ActiveSupport::Testing::MethodCallAsserts#assert_called_on_instance_of` which injects a stubbed method into `klass`, and verifies the number of times it is called, similar to `assert_called`. It also adds a convenience method, `assert_not_called_on_instance_of`, mirroring `assert_not_called`. It uses the new method_call_assertions to replace the remaining Mocha calls in `ActiveRecord` tests. [utilum + bogdanvlviv + kspath]
* | | Remove unused requiresyuuji.yaginuma2018-08-171-3/+0
| | |
* | | Fix obsoleted method URI.unescape in activesupport/testVitor Oliveira2018-08-151-1/+1
| | |
* | | Merge pull request #33499 from lsylvester/caller-ignore-pathsKasper Timm Hansen2018-08-151-0/+40
|\ \ \ | | | | | | | | use BacktraceCleaner for ActiveRecord verbose logging
| * | | Use backtrace cleaner to clean up backtrace for verbose query logsLachlan Sylvester2018-08-141-0/+40
| |/ /
* | | Merge pull request #33612 from bogdanvlviv/test-assert_calledRyuta Kamizono2018-08-151-0/+10
|\ \ \ | | | | | | | | Test `assert_called` and `assert_called_with`
| * | | Test `assert_called` and `assert_called_with`bogdanvlviv2018-08-141-0/+10
| |/ / | | | | | | | | | | | | | | | | | | | | | - ActiveSupport::Testing::MethodCallAssertions#assert_called - Ensure that the method stubbed by `assert_called` returns correct value after - ActiveSupport::Testing::MethodCallAssertions#assert_called_with - Ensure that `#assert_called_with` stubs the method to return a specific value - Ensure that the method stubbed by `assert_called_with` returns correct value after
* / / 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] ```
* | Fix the obvious typos detected by github.com/client9/misspellKazuhiro Sera2018-08-081-1/+1
| |
* | Support skip nil for cache fetch (#25437)Martin2018-08-051-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | * test case for fetch cache miss with skip_nil * abondon nil cache if skip_nil specified * ensure not cache key for skip nil * add document with skip_nil for Store#fetch * add a new change log entry for #25437
* | Merge pull request #33325 from Edouard-chin/ec-deprecate-class-methodRyuta Kamizono2018-07-311-0/+35
|\ \ | | | | | | A regression in `deprecate_methods` was introduced in a982a42:
| * | A regression in deprecate_methods was introduced in a982a42:Edouard CHIN2018-07-301-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Refactoring alias_chain to Module#prepend broke the possibility to deprecate class methods since the module generated was prepended to the target's instance. A suggestion to fix this was to use `AS#redefine_method` which would solve the problem but with the cost of redefining directly the method. Decided to go with the same alias_chain implementation as before instead. - Fixes #33253
* | | cpu_time and allocations are 0 when JRuby is usedYasuo Honda2018-07-301-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to #33449 and #33468, cpu_time and allocations are 0 when JRuby is used. ```ruby $ ruby -v jruby 9.2.1.0-SNAPSHOT (2.5.0) 2018-07-27 13b2df5 Java HotSpot(TM) 64-Bit Server VM 25.181-b13 on 1.8.0_181-b13 [linux-x86_64] $ bundle exec ruby -w -Itest test/log_subscriber_test.rb -n test_event_attributes Run options: -n test_event_attributes --seed 6231 F Failure: SyncLogSubscriberTest#test_event_attributes [test/log_subscriber_test.rb:84]: Expected 0 to be > 0. rails test test/log_subscriber_test.rb:78 Finished in 0.018983s, 52.6791 runs/s, 105.3582 assertions/s. 1 runs, 2 assertions, 1 failures, 0 errors, 0 skips ```
* | | Remove unused `require "active_support/core_ext/regexp"`Ryuta Kamizono2018-07-291-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | Ruby 2.4 has native `Regexp#match?`. https://ruby-doc.org/core-2.4.0/Regexp.html#method-i-match-3F Related #32034.
* | | Always subscribe to event objects via `AS::Notifications.subscribe`Aaron Patterson2018-07-261-9/+16
| | | | | | | | | | | | | | | | | | | | | We don't need to have a special subscribe method for objects. The regular `subscribe` method is more expensive than a specialized method, but `subscribe` should not be called frequently. If that turns out to be a hotspot, we can introduce a specialized method. :)
* | | Subscribe to event objects via `subscribe`Aaron Patterson2018-07-261-0/+12
| | |
* | | Subscribe to event objects via `subscribe_event`Aaron Patterson2018-07-261-0/+17
| | | | | | | | | | | | | | | | | | Fanout notifier can send event objects to subscribers now. Also moved `end` lower in the `finish!` method to guarantee that CPU time is shorter than real time.
* | | Add cpu_time, idle_time, and allocations to EventEileen Uchitelle2018-07-261-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Use process clock instead of Time.now This fixes any issues with the system clock changing and also eliminates 2 object allocations per event. * Add start! and finish! methods to the event object so we can record more information * Adds cpu time, idle time, and allocation count for a particular event. Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
* | | Turn on performance based copsDillon Welch2018-07-231-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use attr_reader/attr_writer instead of methods method is 12% slower Use flat_map over map.flatten(1) flatten is 66% slower Use hash[]= instead of hash.merge! with single arguments merge! is 166% slower See https://github.com/rails/rails/pull/32337 for more conversation
* | | 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
* | added tests for assert_no_difference with multiple expressionslxxxvi2018-07-081-0/+16
| |
* | Merge pull request #33289 from Edouard-chin/ec-lazy-load-hooksRafael França2018-07-041-0/+49
|\ \ | | | | | | Use class_eval or instance_eval when triggering lazy load hooks
| * | Use class_eval or instance_eval when triggering lazy load hooks:Edouard CHIN2018-07-031-0/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - When lazy load hooks were triggered we were using `Object.instance_eval` which evaluates the block in the context of the class being passed. Most of the time that class was a `Class`. If one wants to define a instance method on the class then it wasn't possible. ```ruby class A; end; A.instance_eval do def foo puts 'bar' end end A.new.foo #> NoMethodError: undefined method `foo` A.foo #> bar ``` - This PR checks what object is passed when triggering the hooks and either call `class_eval` or `instance_eval`. My rational and assumptions being that if an instance of a class is passed, then the blocks needs to evaluate in the context of that instance (i.e. defining a method should only define it on that instance). On the other hand, if a Class or Module is passed when triggering hooks, then defining a method should define it on the class itself - #32776 Pushed me to introduce this change
* | | Refactor #33254.Kasper Timm Hansen2018-07-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Firstly, increment and decrement shouldn't care about the particulars of key expiry. They should only know that they have to pass that responsibility on to somewhere else. Secondly, it moves the key normalization back inside the instrumentation like it was originally. I think that matches the original design intention or at the very least it lets users catch haywire key truncation. Thirdly, it moves the changelog entry to the top of the file, where new entries go. I couldn't understand what the entry was saying so I tried to rewrite it.
* | | Fix Cache :redis_store increment/decrement ttl check and add more tests.Jason Lee2018-06-301-4/+20
| | |
* | | Add :expires_in option support for RedisCacheStore increment/decrement method.Jason Lee2018-06-291-0/+24
| | |
* | | 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.
* | Merge pull request #33078 from bogdanvlviv/add-remove-requireRyuta Kamizono2018-06-095-13/+5
|\ \ | | | | | | Add/Remove `require`
| * | Add missing `require`bogdanvlviv2018-06-072-0/+5
| | | | | | | | | | | | | | | | | | | | | `activesupport/test/logger_test.rb` requires `tmpdir`. `activesupport/test/multibyte_test_helpers.rb` requires `filutils`, `open-uri`, and `tmpdir`.
| * | Remove unused `require`bogdanvlviv2018-06-073-13/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - `activesupport/multibyte_normalization_conformance_test.rb` `fileutils`, `tmpdir`, and `open-uri` are unused since c245ca30f248367e07d5d831195b12c93a1e3137, c245ca30f248367e07d5d831195b12c93a1e3137, and 7d7c2d13ba896dd8b58fe91d2fe0c4fc588069ca in accordance. - `activesupport/test/multibyte_conformance_test.rb` `tmpdir`, and `open-uri` are unused since c245ca30f248367e07d5d831195b12c93a1e3137, and 7d7c2d13ba896dd8b58fe91d2fe0c4fc588069ca in accordance. Remove using of `fileutils` since c245ca30f248367e07d5d831195b12c93a1e3137. - `activesupport/test/multibyte_grapheme_break_conformance_test.rb` `fileutils`, `tmpdir`, and `open-uri` are unused since c245ca30f248367e07d5d831195b12c93a1e3137, c245ca30f248367e07d5d831195b12c93a1e3137, and 7d7c2d13ba896dd8b58fe91d2fe0c4fc588069ca in accordance.
* | | Remove extra `include ActiveSupport::Testing::MethodCallAssertions`bogdanvlviv2018-06-081-3/+0
|/ / | | | | | | It includes via `require "abstract_unit"`.
* | Allow Time.zone.at to receive a second argumentJosh Pencheon2018-05-301-0/+10
| | | | | | | | For parity with Ruby's Time::at
* | Merge pull request #32822 from lxxxvi/improved_error_message_in_assert_changesRafael França2018-05-221-1/+1
|\ \ | | | | | | Clearer error message in assert_changes