Merge pull request #47573 from codergeek121/fix-timewithzone-argumenterror

Fixes TimeWithZone ArgumentError #47572
This commit is contained in:
Rafael Mendonça França 2023-03-03 18:02:48 -05:00 committed by GitHub
commit 5aa84bcea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

@ -535,8 +535,8 @@ def respond_to_missing?(sym, include_priv)
# Send the missing method to +time+ instance, and wrap result in a new
# TimeWithZone with the existing +time_zone+.
def method_missing(sym, *args, &block)
wrap_with_time_zone time.__send__(sym, *args, &block)
def method_missing(...)
wrap_with_time_zone time.__send__(...)
rescue NoMethodError => e
raise e, e.message.sub(time.inspect, inspect).sub("Time", "ActiveSupport::TimeWithZone"), e.backtrace
end

@ -628,6 +628,12 @@ def time.foo; "bar"; end
assert_equal "bar", @twz.foo
end
def test_method_missing_works_with_kwargs
time = @twz.time
def time.method_with_kwarg(foo:); foo; end
assert_equal "bar", @twz.method_with_kwarg(foo: "bar")
end
def test_date_part_value_methods
twz = ActiveSupport::TimeWithZone.new(Time.utc(1999, 12, 31, 19, 18, 17, 500), @time_zone)
assert_not_called(twz, :method_missing) do