Fix ActionView::Helpers::DateHelper#distance_of_time_in_words test #27091

Closed
wants to merge 2 commits into
from

Projects

None yet

6 participants

@yui-knk
Contributor
yui-knk commented Nov 18, 2016

Summary

The behavior of #round was changed to round to even in Ruby 2.4.
So we have to pass half: :up to #round.

see: ruby/ruby@6ed8c79 and
ruby/ruby@295f60b

And for back compatibility, adding core_ext #round to accept options.

@arthurnn arthurnn was assigned by rails-bot Nov 18, 2016
@rails-bot

r? @arthurnn

(@rails-bot has picked a reviewer for you, use r? to override)

@rafaelfranca
Member

O_O. Are they aware of this breaking change?

@rafaelfranca
Member

Is this the only place where we use round?

+if !(0.0.round(0, half: :up) rescue false)
+ module ActiveSupport::NumericRoundWithOption
+ def round(ndigits = 0, half: nil)
+ super(ndigits)
@matthewd
matthewd Nov 18, 2016 Member

Accepting the option and then ignoring it seems quite rude.

@rafaelfranca
Member

I opened a bug to get their feedback because changing this in a minor version seems weird https://bugs.ruby-lang.org/issues/12958

yui-knk added some commits Nov 18, 2016
@yui-knk yui-knk Add `Integer#round` and `Float#round` core extensions
`half` option was added to Integer#round and Float#round in Ruby 2.4.
And a behavior of round was changed to round to even.
We have depended a behavior of rounding to nearest.
In some case (i.e. `ActionView::Helpers::DateHelper#distance_of_time_in_words`),
we have to pass `half: :up` to `round`.

This core_ext enables to us to pass a option,
even before Ruby 2.3.
61a6597
@yui-knk yui-knk Ensure to round to nearest
The behavior of `#round` was changed to round to even in Ruby 2.4.
So we have to pass `half: :up` to `#round`.

see: ruby/ruby@dfe91fc
09c3d28
@yui-knk
Contributor
yui-knk commented Dec 13, 2016

Also #27177 . This PR is now useless. So I will close this.

@yui-knk yui-knk closed this Dec 13, 2016
@yui-knk yui-knk deleted the yui-knk:fix_round_test branch Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment