Fixes an issue with Options.merge! and Faraday instrumentation middleware (#711)

Fixes #710
This commit is contained in:
Mattia 2017-07-19 18:34:34 +01:00 committed by GitHub
parent debc8e938b
commit cf6f2b10ac
2 changed files with 17 additions and 1 deletions

View File

@ -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

View File

@ -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)