mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix segmentation fault in Ruby 2.0.0-p353.
In Ruby 2.0.0-p353 there was a
[commit](66915c5077
)
that switched case matching from actual sending `===` method to magic lookup,
that does not see it in `method_missing`. It's hard to predict how exactly and
when exactly this bug will be solved so here I suggest a solution of defining
it in Duration directly.
In Ruby 2.0.0-p353 without the added fix added test crashes to segmentation
fault.
This commit is contained in:
parent
61ad8d5c32
commit
8033d3370c
2 changed files with 13 additions and 0 deletions
|
@ -99,6 +99,14 @@ module ActiveSupport
|
|||
|
||||
private
|
||||
|
||||
# We define it as a workaround to Ruby 2.0.0-p353 bug.
|
||||
# For more information, check rails/rails#13055.
|
||||
# It should be dropped once a new Ruby patch-level
|
||||
# release after 2.0.0-p353 happens.
|
||||
def ===(other) #:nodoc:
|
||||
value === other
|
||||
end
|
||||
|
||||
def method_missing(method, *args, &block) #:nodoc:
|
||||
value.send(method, *args, &block)
|
||||
end
|
||||
|
|
|
@ -158,6 +158,11 @@ class DurationTest < ActiveSupport::TestCase
|
|||
assert_equal '172800', 2.days.to_json
|
||||
end
|
||||
|
||||
def test_case_when
|
||||
cased = case 1.day when 1.day then "ok" end
|
||||
assert_equal cased, "ok"
|
||||
end
|
||||
|
||||
protected
|
||||
def with_env_tz(new_tz = 'US/Eastern')
|
||||
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
|
||||
|
|
Loading…
Reference in a new issue