Commit Graph

7771 Commits

Author SHA1 Message Date
Krzysztof Rybka 40da1c430b Refactor calculating beginning_of_quarter and end_of_quarter (#34927)
* Calculate first month of quarter instead of finding

* Calculate last month of quarter instead of finding

[Krzysztof Rybka + Rafael Mendonça França]
2019-01-14 16:11:53 -05:00
Keenan Brock a930f5ba06 Fix safe_constantize to not raise a LoadError.
### Summary

There was an issues when using `safe_constantize` on a string that has
the wrong case.

File `em.rb` defines `EM`.
`"Em".safe_constantize` causes a little confusion with the autoloader.
The autoloader finds file "em.rb",
expecting it to define `Em`, but `Em` is not defined.
The autoloader raises a `LoadError`, which is good,
But `safe_constantize` is defined to return `nil` when a class is not found.

### Before

```
"Em".safe_constantize
LoadError: Unable to autoload constant Em, \
expected rails/activesupport/test/autoloading_fixtures/em.rb to define it
```

### After

```
"Em".safe_constantize
# => nil
```
2019-01-09 14:52:46 -05:00
Aaron Patterson 28bb21bf5a
Merge pull request #34899 from rails/speed-up-step
Duration#coerce should always return a Scalar
2019-01-09 09:28:00 -08:00
Ryuta Kamizono ea65d92f19
Enable `Lint/UselessAssignment` cop to avoid unused variable warnings (#34904)
* Enable `Lint/UselessAssignment` cop to avoid unused variable warnings

Since we've addressed the warning "assigned but unused variable"
frequently.

370537de05
3040446cec
5ed618e192
76ebafe594

And also, I've found the unused args in c1b14ad which raises no warnings
by the cop, it shows the value of the cop.
2019-01-09 18:09:01 +09:00
Aaron Patterson 36de9eadaa
Duration#coerce should always return a Scalar
This speeds up Range.new(x, y).step(Duration).each { ... }

Fixes #34888
2019-01-08 15:05:40 -08:00
Kasper Timm Hansen 647d7e6167
Revert "Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json""
I reverted the wrong commit. Damn it.

This reverts commit f66a977fc7.
2019-01-08 22:19:22 +01:00
Kasper Timm Hansen f66a977fc7
Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json"
We had a discussion on the Core team and we don't want to expose this information
as a JSON endpoint and not by default.

It doesn't make sense to expose this JSON locally and this controller is only
accessible in dev, so the proposed access from a production app seems off.

This reverts commit 8eaffe7e89, reversing
changes made to b6e4305c3b.
2019-01-08 22:16:58 +01:00
Rafael França cd16413ef3
Merge pull request #34700 from gmcgibbon/fetch_multi_key_order
Preserve key order of #fetch_multi
2019-01-07 13:49:02 -05:00
bogdanvlviv ee79a842ff
Clarify `delegate_missing_to` [ci skip]
Since #34864 removed explicit receiver to clarify the
purpose of `delegate_missing_to`, I think it will be
better to do the same a few lines above to easier figure
out that `delegate_missing_to` defines `method_missing`,
`respond_to_missing?` when comparing these examples.
2019-01-04 22:18:00 +02:00
Michael Gee 348f8e0c91
Clarify benefit of `delegate_missing_to`
Removing the explicit receiver clarifies the purpose of `delegate_missing_to`.
2019-01-04 11:50:30 -05:00
Gannon McGibbon 1b402a510a Fix examples in ActiveSupport::LogSubscriber docs
[ci skip]
2019-01-01 20:27:54 -05:00
Gannon McGibbon 710e0ffc5a
Merge pull request #34707 from xlts/update-notifications-docs
Add examples describing error handling in ActiveSupport::Notification…
2018-12-31 15:11:53 -05:00
Arun Agrawal 50e3680768 Bump license years for 2019 2018-12-31 10:24:38 +07:00
George Claghorn f28b28fe8d Tweak test name 2018-12-30 12:01:55 -05:00
Julik Tarkhanov e5f4162b61 Make Active Storage blob keys lowercase
Accommodate case-insensitive filesystems and database collations.
2018-12-30 11:56:22 -05:00
Gannon McGibbon 94ecf95674 Preserve key order passed to ActiveSupport::CacheStore#fetch_multi
fetch_multi(*names) now returns its results in the same order
as the `*names` requested, rather than returning cache hits
followed by cache misses.
2018-12-27 01:39:43 -06:00
Yasuo Honda 05781f1f9c No need to handle if FrozenError is available
Rails 6 requires Ruby 2.5, which introduces `FrozenError`
https://docs.ruby-lang.org/en/2.5.0/NEWS.html

Related to #31520
2018-12-23 13:26:20 +00:00
utilum 59effbed33 Fixes `warning: mismatched indentations at 'rescue' with 'def' at 15`.
See https://travis-ci.org/rails/rails/jobs/470890129#L2361
2018-12-21 12:28:33 +01:00
yuuji.yaginuma a1c57cf69f Add missing require for `String#to_d` 2018-12-21 18:12:10 +09:00
Yuji Yaginuma 5abe612b0d
Merge pull request #34767 from y-yagi/fix_convert_string_to_bigdecimal
Use BigDecimal provided methods to convert String to BigDecimal
2018-12-21 17:58:57 +09:00
Ryuta Kamizono b75192845a
Merge pull request #34764 from kamipo/avoid_redundant_begin
Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin block
2018-12-21 17:36:30 +09:00
Ryuta Kamizono 07235ec371
Merge pull request #34769 from elebow/module-delegate-to-docstring
Module.delegate rdoc update to clarify :to parameter [ci skip]
2018-12-21 17:32:47 +09:00
Yuji Yaginuma 1d21ad9c46
Merge pull request #33822 from y-yagi/do_not_check_parents_dor_directories
Do no watch parent directory of `dirs`
2018-12-21 16:58:47 +09:00
Eddie Lebow ff09c8cef9 Clarify the :to parameter of delegate 2018-12-20 22:17:37 -05:00
yuuji.yaginuma d5f8486d3f Use BigDecimal provided methods to convert String to BigDecimal
`String#to_d` does not raise an exception if an invalid value is specified.
So can remove exception handling.

```
$ bundle exec ruby -v -rbigdecimal -rbigdecimal/util -e 'p "123,003".to_d'
ruby 2.6.0dev (2018-12-21 trunk 66474) [x86_64-linux]
0.123e3
```
2018-12-21 10:28:06 +09:00
yuuji.yaginuma 5d905abbe7 Add test for `travel_to` with time zone
This is a regression test for #34751.
2018-12-21 10:08:33 +09:00
Kasper Timm Hansen 788bc21ef3
Merge pull request #34762 from bogdanvlviv/fix-a-few-deprecation-warnings
Follow up #34754
2018-12-20 23:02:39 +01:00
Ryuta Kamizono 892e38c78e Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin block
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.
2018-12-21 06:12:42 +09:00
bogdanvlviv 25b969a446
Follow up #34754
- Fix a few deprecation warnings
- Remove testing of `Hash#slice`
- Imporve test of `Hash#slice!`
- Remove mention about `Hash#slice` from the guide
2018-12-20 18:53:25 +02:00
Ryuta Kamizono 8034dde023 Module#{define_method,alias_method,undef_method,remove_method} become public since Ruby 2.5
https://bugs.ruby-lang.org/issues/14133
2018-12-21 01:39:18 +09:00
Ryuta Kamizono 3da358ea83 Remove remaining tests for `Hash#transform_keys` and `Hash#transform_keys!`
Follow up #34761.
2018-12-21 00:16:39 +09:00
Ryuta Kamizono d5197d59a1 Use native `Array#append`, `Array#prepend`, `Hash#transform_keys`, and `Hash#transform_keys!`
Since Rails 6 requires Ruby 2.5.

https://github.com/ruby/ruby/blob/ruby_2_5/NEWS

Follow up #34754.
2018-12-20 23:22:46 +09:00
Kasper Timm Hansen 1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
Bogdan e9f6ce617b Add option to set parallel test worker count to the physical core count of the machine (#34735)
* Add option to set parallel test worker count to the physical core count of the machine

Also, use the physical core count of the machine as
the default number of workers, and  generate the `test_helper.rb` file
with `parallelize(workers: :number_of_processors)`

Closes #34734

* Ensure that we always test parallel testing

Since #34734 we decided to use the physical core count of the machine as
the default number of workers in the parallel testing, we need to
ensure that some tests use at least 2 workers because we could
run those tests on VM that has only 1 physical core.
It also fixes tests failures on the CI since Travis server we are using
has only one physical core.
See https://travis-ci.org/rails/rails/jobs/469281088#L2352
2018-12-18 10:25:35 -08:00
yuuji.yaginuma caa3cc8868 Do not add parent directory to file system monitoring
`EventedFileUpdateChecker` will search the parent directory if the
specified directory does not exist.

Since `test/mailers/previews` is included in the watch target by default,
if there is no test directory (e.g. using `rspec`), the Rails root directory
will be included in the watch target.

```
$ rails new app
$ cd app
$ ./bin/rails r "p Rails.application.reloaders.last.send(:directories_to_watch).include?(Rails.root)"
false
$ rm -rf test
$ ./bin/rails r "p Rails.application.reloaders.last.send(:directories_to_watch).include?(Rails.root)"
true
```

This causes `node_modules` to be included in watch target. Adding parent
directories to watch target may include unexpected directories.

In order to avoid this, fixed that parents of nonexistent directories are
not added to the watch targets, instead checking that the directory
exists when checking changes.

Related to #32700.

[Matthew Draper & Yuji Yaginuma]
2018-12-18 08:09:16 +09:00
Bogdan fdb2719308 Extend documentation of `ActiveSupport::Notifications.subscribe` (#34721)
* Extend documentation of `ActiveSupport::Notifications.subscribe`

Add mention that a block with only one argument passed to the method
will yield an event object.

Related to #33451

* Emphasize that `SubscribeEventObjects` is a test class by adding suffix `Test`
2018-12-17 17:25:55 +09:00
Mariusz Hausenplas 2701a18d38 Add examples describing error handling in ActiveSupport::Notifications and ActiveSupport::LogSubscriber documentation files 2018-12-14 22:59:44 +01:00
Yosuke Kabuto ccbdbca364 Test ActiveSupport::Deprecation.deprecate_methods
There was no test without an alternate method name is given.
2018-12-14 11:49:54 +09:00
Ryuta Kamizono f907b418ae Enable `Layout/SpaceAfterSemicolon` cop to avoid newly adding odd spacing
Ref 59ff1ba30d (diff-38fb97fba84b1ef0f311c4110a597c44R35)
2018-12-13 18:06:04 +09:00
Yuji Yaginuma c4f37cc8c5
Merge pull request #34648 from y-yagi/fixes_34646
Make `deprecate` work for non-exists methods
2018-12-12 15:52:08 +09:00
Vinicius Stock 3b7a4d3d75
Upgrade Rubocop to 0.61.1 and fix offenses 2018-12-10 19:22:56 -02:00
yuuji.yaginuma 59ff1ba30d Make `deprecate` work for non-exists methods
Before #33325, `deprecate` works for non-exist methods.
This is necessary, for example, if want to deprecate dynamically defined
methods like attributes methods.

Fixes #34646
2018-12-07 18:16:30 +09:00
utilum ab631b363e Another Ruby 2.6 BigDecimal compatibility issue
This patch modifies XmlMini::Parsing["decimal"] to handle a string that
contains an invalid number. Since [ruby/ruby@a0e438c#diff-6b866d482baf2bdfd8433893fb1f6d36R144](a0e438cd3c (diff-6b866d482baf2bdfd8433893fb1f6d36R144)) this case raises an `ArgumentError`. `String.to_f` returns 0.0 if there is not a valid number at the start of the argument, so current behavior is conserved.

See https://travis-ci.org/rails/rails/jobs/463180341#L6264

Related: #34600, #34601
2018-12-04 13:50:45 +01:00
Ryuta Kamizono aa9b0932ec Don't expose internal `clock_gettime_supported?` class method 2018-11-30 21:14:12 +09:00
Mark J. Titorenko 8212dfcf14 Do nothing when the same block is included again.
If the same block is included multiple times, we no longer raise an exception
or overwrite the included block instance variable.

Fixes #14802.

[Mark J. Titorenko + Vlad Bokov]
2018-11-29 18:37:06 +00:00
yuuji.yaginuma 8687a035d7 Pass the test reporter by reference
This prevents the array from being dumped as a DRbObject so we can reduce
communication with the server.

In DRb, if `Marshal.dump` fails, `Marshal.dump` is executed again after
converting the object to `DRbObject`. This also possible to reduce the
execution of `Marshal.dump` by converting to a format that can be
marshalized in advance using `DRbObject`.
This is the same approach to Action Pack's parallel test. Ref: 5751b7ea58
2018-11-28 15:43:58 +09:00
Daniel Colson 3cfb05daa4
Remove unnecessary reduce in Duration#inspect
When the `Duration` class was introduced in 276c9f29, the `parts` were
represented as an array of arrays
(for example `[[:seconds, 5], [:days, 3], [:seconds, 7]]`).
At that time the `reduce` in `#inspect` made sense,
since we would need to get the totals for each part
(the example would become `{ seconds: 12, days: 3 }`).

With the current version of `Duration` we call `to_h` on the `parts`
immediately on initialize, so now the `reduce` doesn't seem to be doing
anything meaningful.
2018-11-24 11:42:28 -05:00
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
Ryuta Kamizono 50d1e00625 Remove odd spaces [ci skip] 2018-11-21 17:08:06 +09:00