Commit Graph

3207 Commits

Author SHA1 Message Date
Rafael França
548bd50985
Merge pull request #34037 from reitermarkus/atomic_write-permissions
`atomic_write`: Ensure correct permission when `tmpdir` is the same as `dirname`.
2018-11-22 15:47:19 -05:00
yuuji.yaginuma
f8bd01cdd9 Fix ruby warnings
This fixes following warnings:

```
test/dependencies_test.rb:287: warning: possibly useless use of :: in void context
test/dependencies_test.rb:300: warning: possibly useless use of a constant in void context
```
2018-11-22 17:20:51 +09:00
Fumiaki MATSUSHIMA
c30f664c71 Add test for normalizing non-unicode string
Closes #34062
2018-11-15 01:34:05 +09:00
Nick Weiland
4ba5386e6c Make #to_options an alias for #symbolize_keys
Fixes #34359

Prior to 5.2.0 (2cad8d7), HashWithIndifferentAccess#to_options acted as
an alias to HashWithIndifferentAccess#symbolize_keys. Now, #to_options
returns an instance of HashWithIndifferentAccess while #symbolize_keys
returns and instance of Hash.

This pr makes it so HashWithIndifferentAccess#to_options acts as an
alias for HashWithIndifferentAccess#symbolize_keys once again.
2018-11-01 09:12:56 -07:00
Jan Habermann
e302725751 Improve the logic that detects non-autoloaded constants
If you require `nokogiri` from `app/models/user.rb`, dependencies.rb
does not mark `Nokogiri` as an autoloaded constant, as expected.
But the logic to detect these non-autoloaded constants is incomplete.
See the tests defined in the patch for some cases incorrectly handled.
2018-10-28 16:34:50 +01:00
Ryuta Kamizono
61490805fe
Merge pull request #34208 from yskkin/inspect_with_parameter_filter
Implement AR#inspect using ParameterFilter
2018-10-26 19:05:34 +09:00
bogdanvlviv
9d0cf52096
assert_called_with should require args argument
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 - a970ecc42c
2018-10-25 21:29:39 +03:00
Francesco Rodríguez
d684778a00 Use String#truncate_bytes inside Multibyte::Chars#limit 2018-10-20 12:00:37 -07:00
Yoshiyuki Kinjo
32b03b4615 Implement AR#inspect using ParamterFilter.
AR instance support `filter_parameters` since #33756.
Though Regex or Proc is valid as `filter_parameters`,
they are not supported as AR#inspect.

I also add :mask option and #filter_params to
`ActiveSupport::ParameterFilter#new` to implement this.
2018-10-19 14:16:03 +09:00
Francesco Rodríguez
b0f3070209 Deprecate Unicode's #pack_graphemes and #unpack_graphemes methods
in favor of `array.flatten.pack("U*")` and `string.scan(/\X/).map(&:codepoints)`, respectively.
2018-10-18 14:10:30 -07:00
Francesco Rodríguez
134dab46e4 Deprecate ActiveSupport::Multibyte::Chars.consumes?
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.
2018-10-15 13:11:59 -07:00
Edouard CHIN
c85e3f65f3 Fix issue where duration where always rounded up to a second:
- 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
2018-10-12 13:27:13 -04:00
Francesco Rodríguez
ee95bed3e6 Deprecate Unicode#normalize and Chars#normalize (#34202) 2018-10-12 08:40:29 -07:00
Francesco Rodríguez
16e3b65674 Use native String#capitalize 2018-10-12 07:47:23 +02:00
Francesco Rodríguez
e52b223487 Deprecate Unicode#downcase/upcase/swapcase.
Use String methods directly instead.
2018-10-12 07:42:51 +02:00
Eileen Uchitelle
8df7ed3b88 Test that nested structs to_json works as expected
Check that options passed to the to_json are passed to all objects that
respond to as_json.
2018-10-11 15:28:52 -04:00
Yoshiyuki Kinjo
7f80be29a2 Deprecate ActionDispatch::Http::ParameterFilter in favor of ActiveSupport::ParameterFilter 2018-10-08 08:05:40 +09:00
Graham Turner
d5b57c890e Array with single item correctly uses cache_key 2018-10-05 19:24:49 -04:00
Martin Spickermann
bd10796419 Bugfix: ActiveSupport::EncryptedConfiguration reading of comment-only 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
2018-10-05 08:06:33 +09:00
yuuji.yaginuma
c55fc43b3f Don't use deprecated LoggerSilence 2018-10-04 08:23:49 +09:00
Rafael França
ebf98df9fb
Merge pull request #34055 from Edouard-chin/ec-logger-fix
Fix the LoggerSilence to work as described:
2018-10-03 16:45:53 -04:00
Akira Matsuda
370537de05 ⚠️ assigned but unused variable - logger 2018-10-03 21:38:57 +09:00
Edouard CHIN
05ad44eb89 Fix the LoggerSilence to work as described:
- 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.
2018-10-02 17:17:23 -04:00
Rafael Mendonça França
92fece96da
Merge pull request #34051 from gmcgibbon/module_parent_method_rename
Prefix Module#parent, Module#parents, and Module#parent_name with module
2018-10-02 16:04:23 -04:00
Edouard CHIN
783f86822b Deprecate the LoggerSilence constant:
- 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.
2018-10-02 12:59:04 -04:00
Gannon McGibbon
004fda3568 Prefix Module#parent, Module#parents, and Module#parent_name with module 2018-10-02 12:51:35 -04:00
Rafael França
cf608ee34d
Merge pull request #33058 from gmcgibbon/string_first_last_negative_deprecation
Add deprecation warning when String#first and String#last receive neg…
2018-10-02 11:05:40 -04:00
Markus Reiter
c08272ac24 Ensure correct permission when tmpdir is the same as dirname. 2018-10-02 16:40:39 +02:00
Sharang Dashputre
3c4b729f48 Fix spellings for 'unmarshall(ing/ed)' & 'marshall(ing/ed)' 2018-10-02 13:55:39 +05:30
Yasuo Honda
aa3dcabd87 Add Style/RedundantFreeze to remove redudant .freeze
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'
2018-09-29 07:18:44 +00:00
Gannon McGibbon
ec9a89cb8b Add deprecation warning when String#first and String#last receive negative integers
[Gannon McGibbon + Eric Turner]
2018-09-28 14:29:46 -04:00
Abraham Chan
b2ea831073 Fix HashWithIndifferentAccess#without bug 2018-09-28 18:28:56 +10:00
Janosch Müller
47f2686148 Handle more unsafe String methods (#33990)
* Handle more unsafe String methods

* Fix codeclimate issue

* Revert stylistic change

[Janosch Müller + Rafael Mendonça França]
2018-09-27 20:50:21 -04:00
Rafael Mendonça França
f679933daa
Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
Kasper Timm Hansen
22dc2b3db8
Merge pull request #33949 from sjain1107/no-private-def
Remove private def
2018-09-23 19:39:15 +02:00
Sakshi Jain
0fe2bb816f Remove private def 2018-09-23 21:27:44 +05:30
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
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

```
2018-09-23 08:56:55 +09:00
Rafael Mendonça França
e09c55dc8e
Merge pull request #27792 from tjoyal/sandbox-tagged-logging
TaggedLogging to return a new logger instance
2018-09-11 19:33:59 -04:00
ryanwhocodes
36e6571a40 Add #unfreeze_time to ActiveSupport::Testing::TimeHelpers 2018-09-10 22:32:41 +01:00
Xavier Noria
c03bba4f1f trace autoloads, and document hints for troubleshooting
Closes #32885.
2018-09-07 23:32:54 +02:00
Yumin Wong
0a1567793b Use assert_predicate instead
Co-authored-by: no-itsbackpack <no-itsbackpack@github.com>
2018-09-06 12:48:50 -05:00
Yumin Wong
3f5bd11ed6 SafeBuffer should maintain safety upon getting a slice via a range if original buffer was safe.
Co-Authored-By: no-itsbackpack <no-itsbackpack@github.com>
2018-08-31 11:46:09 -05:00
yuuji.yaginuma
12fadea8ae Remove redundant travel_back
Since #29860, `travel_back` automatically called at the end of the test.
2018-08-31 16:19:58 +09:00
Kasper Timm Hansen
9136bb77a7
Merge pull request #33162 from utilum/stop_using_mocha
Stop using Mocha
2018-08-22 18:20:25 +02:00
yuuji.yaginuma
0193b89be6 Remove unused requires 2018-08-17 12:51:14 +09:00
Vitor Oliveira
0e0261b52e Fix obsoleted method URI.unescape in activesupport/test 2018-08-15 18:00:45 -03:00
Kasper Timm Hansen
977d77e9e2
Merge pull request #33499 from lsylvester/caller-ignore-paths
use BacktraceCleaner for ActiveRecord verbose logging
2018-08-15 20:16:43 +02:00
Ryuta Kamizono
111643b8a3
Merge pull request #33612 from bogdanvlviv/test-assert_called
Test `assert_called` and `assert_called_with`
2018-08-15 14:48:53 +09:00
bogdanvlviv
77b0126054
Add Array#extract!
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]
```
2018-08-14 19:53:12 +03:00
bogdanvlviv
88439585ed
Test assert_called and assert_called_with
- 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
2018-08-14 09:01:01 +03:00