Simplify copying custom_members to new Env instance

This commit is contained in:
Mislav Marohnić 2015-10-02 00:06:53 +02:00
parent 03f373a1fb
commit 441d8ac979
2 changed files with 5 additions and 5 deletions

View File

@ -272,10 +272,8 @@ module Faraday
# Public
def self.from(value)
env = super(value)
if value.kind_of?(self)
value.custom_members.each do |custom_key, custom_value|
env[custom_key] = custom_value
end
if value.respond_to?(:custom_members)
env.custom_members.update(value.custom_members)
end
env
end

View File

@ -70,13 +70,15 @@ class EnvTest < Faraday::TestCase
assert_equal 'proxy.com', env.request.proxy.host
end
def test_custom_headers_are_retained
def test_custom_members_are_retained
env = make_env
env[:foo] = "custom 1"
env[:bar] = :custom_2
env2 = Faraday::Env.from(env)
assert_equal "custom 1", env2[:foo]
assert_equal :custom_2, env2[:bar]
env2[:baz] = "custom 3"
assert_nil env[:baz]
end
private