mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-05 00:05:35 -04:00
Fixes an issue with Options.merge! and Faraday instrumentation middleware (#711)
Fixes #710
This commit is contained in:
parent
debc8e938b
commit
cf6f2b10ac
@ -49,7 +49,7 @@ module Faraday
|
||||
other.each do |key, other_value|
|
||||
self_value = self.send(key)
|
||||
sub_options = self.class.options_for(key)
|
||||
new_value = (sub_options && other_value) ? self_value.merge(other_value) : other_value
|
||||
new_value = (self_value && sub_options && other_value) ? self_value.merge(other_value) : other_value
|
||||
self.send("#{key}=", new_value) unless new_value.nil?
|
||||
end
|
||||
self
|
||||
|
@ -46,6 +46,22 @@ class OptionsTest < Faraday::TestCase
|
||||
assert_equal merged.c, sub_opts
|
||||
end
|
||||
|
||||
def test_deep_merge_with_sub_nil
|
||||
options = ParentOptions.from(a: 1)
|
||||
|
||||
sub_opts = SubOptions.new(3, 4)
|
||||
options2 = ParentOptions.from(b: 2, c: sub_opts)
|
||||
|
||||
assert_equal options.a, 1
|
||||
assert_equal options2.b, 2
|
||||
assert_equal options2.c.sub_a, 3
|
||||
assert_equal options2.c.sub_b, 4
|
||||
|
||||
merged = options.merge(options2)
|
||||
|
||||
assert_equal merged.c, sub_opts
|
||||
end
|
||||
|
||||
def test_dup_is_shallow
|
||||
sub_opts = SubOptions.from(sub_a: 3)
|
||||
opts = ParentOptions.from(b: 1, c: sub_opts)
|
||||
|
Loading…
x
Reference in New Issue
Block a user