aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
Commit message (Collapse)AuthorAgeFilesLines
...
* | | `assert_called_with` should require `args` argumentbogdanvlviv2018-10-252-13/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two main reasons why `assert_called_with` should require `args` argument: 1) If we want to assert that some method should be called and we don't need to check with which arguments it should be called then we should use `assert_called`. 2) `assert_called_with` without `args` argument doesn't assert anything! ```ruby assert_called_with(@object, :increment) do @object.decrement end ``` It causes false assertions in tests that could cause regressions in the project. I found this bug by working on [minitest-mock_expectations](https://github.com/bogdanvlviv/minitest-mock_expectations) gem. This gem is an extension for minitest that provides almost the same method call assertions. I was wondering whether you would consider adding "minitest-mock_expectations" to `rails/rails` instead of private `ActiveSupport::Testing::MethodCallAssertions` module. If yes, I'll send a patch - https://github.com/bogdanvlviv/rails/commit/a970ecc42c3a9637947599f2c13e3762e4b59208
* | | Use String#truncate_bytes inside Multibyte::Chars#limitFrancesco Rodríguez2018-10-201-18/+0
| | |
* | | Deprecate Unicode's #pack_graphemes and #unpack_graphemes methodsFrancesco Rodríguez2018-10-181-4/+6
| | | | | | | | | | | | in favor of `array.flatten.pack("U*")` and `string.scan(/\X/).map(&:codepoints)`, respectively.
* | | Deprecate ActiveSupport::Multibyte::Chars.consumes?Francesco Rodríguez2018-10-151-3/+9
| | | | | | | | | | | | | | | | | | In favor of String#is_utf8?. I think this method was made for internal use only, and its usage was removed here: https://github.com/rails/rails/pull/8261/files#diff-ce956ebe93786930e40f18db1da5fd46L39.
* | | 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
* | Deprecate Unicode#normalize and Chars#normalize (#34202)Francesco Rodríguez2018-10-123-106/+163
| |
* | Use native String#capitalizeFrancesco Rodríguez2018-10-121-1/+1
| |
* | Deprecate Unicode#downcase/upcase/swapcase.Francesco Rodríguez2018-10-121-0/+6
| | | | | | | | Use String methods directly instead.
* | Test that nested structs to_json works as expectedEileen Uchitelle2018-10-111-0/+10
| | | | | | | | | | Check that options passed to the to_json are passed to all objects that respond to as_json.
* | Deprecate ActionDispatch::Http::ParameterFilter in favor of ↵Yoshiyuki Kinjo2018-10-081-0/+51
| | | | | | | | ActiveSupport::ParameterFilter
* | Array with single item correctly uses cache_keyGraham Turner2018-10-051-0/+49
| |
* | Bugfix: ActiveSupport::EncryptedConfiguration reading of comment-only ↵Martin Spickermann2018-10-051-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | encrypted files (#34014) * Fix reading comment only encrypted files When a encrypted file contains only comments then reading that files raises an error: NoMethodError: undefined method `deep_symbolize_keys' for false:FalseClass activesupport/lib/active_support/encrypted_configuration.rb:33:in `config' test/encrypted_configuration_test.rb:52:in `block in <class:EncryptedConfigurationTest>' This happens because the previous implementation returned a `{}` fallback for blank YAML strings. But it did not handle YAML strings that are present but still do not contain any _usefull_ YAML - like the file created by `Rails::Generators::EncryptedFileGenerator` which looks like this: # aws: # access_key_id: 123 # secret_access_key: 345 * Fix coding style violation * Add backwardscompatible with Psych versions that were shipped with Ruby <2.5 * Do not rely on railties for Active Support test * Simplify error handling * Improve test naming * Simplify file creation in test
* | Don't use deprecated `LoggerSilence`yuuji.yaginuma2018-10-041-1/+1
| |
* | Merge pull request #34055 from Edouard-chin/ec-logger-fixRafael França2018-10-032-1/+37
|\ \ | | | | | | Fix the LoggerSilence to work as described:
| * | Fix the LoggerSilence to work as described:Edouard CHIN2018-10-022-1/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Following the Rails guide which state that a logger needs to include the `ActiveSupport::LoggerSilence` as well as `ActiveSupport::LoggerThreadSafe` modules isn't enough and won't work. Here is a test cases with 3 tests that all fails https://gist.github.com/Edouard-chin/4a72930c2b1eafbbd72a80c66f102010 The problems are the following: 1) The logger needs to call `after_initialize` in order to setup some instance variables. 2) The silence doesn't actually work because the bare ruby Logger `add` method checks for the instance variable `@logger`. We need to override the `add` (like we used to in the ActiveSupport::Logger class). 3) Calling `debug?` `info?` etc... doesn't work as the bare ruby methods will check for the instance variable. Again we need to override this methods (like we used to in the ActiveSupport::Logger class) The LoggerSilence won't work without LoggerThreadSafe, but the later is not public API, the user shouldn't have to include it so I modified to include it automatically. Same for the `after_initialize` method. I find unuintitive to have to call it directly. I modified to instance the variables when the module get included.
* | | :warning: assigned but unused variable - loggerAkira Matsuda2018-10-031-1/+1
|/ /
* | Merge pull request #34051 from gmcgibbon/module_parent_method_renameRafael Mendonça França2018-10-021-11/+29
|\ \ | | | | | | | | | Prefix Module#parent, Module#parents, and Module#parent_name with module
| * | Prefix Module#parent, Module#parents, and Module#parent_name with moduleGannon McGibbon2018-10-021-11/+29
| | |
* | | Deprecate the `LoggerSilence` constant:Edouard CHIN2018-10-021-1/+9
|/ / | | | | | | | | | | | | | | - I found this weird that the LoggerSilence wasn't using the `ActiveSupport` namespace (AFAIK all other classes have it). This PR deprecate the use of `LoggerSilence` for `ActiveSupport::LoggerSilence` instead.
* | 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-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 ```