Skip to content

Commit

Permalink
Merge pull request #47573 from codergeek121/fix-timewithzone-argument…
Browse files Browse the repository at this point in the history
…error

Fixes TimeWithZone ArgumentError #47572
  • Loading branch information
rafaelfranca committed Mar 3, 2023
1 parent d1f52ae commit e237700
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/time_with_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,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
Expand Down
6 changes: 6 additions & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,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
Expand Down

0 comments on commit e237700

Please sign in to comment.