mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
Merge branch 'issue-355' into 'master'
plugin init fixes: enforce usage of Options or hash for the second argument;... Closes #355 See merge request os85/httpx!403
This commit is contained in:
commit
92e891919f
@ -271,11 +271,12 @@ module HTTPX
|
|||||||
def merge(other)
|
def merge(other)
|
||||||
ivar_map = nil
|
ivar_map = nil
|
||||||
other_ivars = case other
|
other_ivars = case other
|
||||||
when Hash
|
when Options
|
||||||
|
other.instance_variables
|
||||||
|
else
|
||||||
|
other = Hash[other] unless other.is_a?(Hash)
|
||||||
ivar_map = other.keys.to_h { |k| [:"@#{k}", k] }
|
ivar_map = other.keys.to_h { |k| [:"@#{k}", k] }
|
||||||
ivar_map.keys
|
ivar_map.keys
|
||||||
else
|
|
||||||
other.instance_variables
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return self if other_ivars.empty?
|
return self if other_ivars.empty?
|
||||||
|
@ -488,6 +488,8 @@ module HTTPX
|
|||||||
label = pl
|
label = pl
|
||||||
# raise Error, "Cannot add a plugin to a frozen config" if frozen?
|
# raise Error, "Cannot add a plugin to a frozen config" if frozen?
|
||||||
pl = Plugins.load_plugin(pl) if pl.is_a?(Symbol)
|
pl = Plugins.load_plugin(pl) if pl.is_a?(Symbol)
|
||||||
|
raise ArgumentError, "Invalid plugin type: #{pl.class.inspect}" unless pl.is_a?(Module)
|
||||||
|
|
||||||
if !@plugins.include?(pl)
|
if !@plugins.include?(pl)
|
||||||
@plugins << pl
|
@plugins << pl
|
||||||
pl.load_dependencies(self, &block) if pl.respond_to?(:load_dependencies)
|
pl.load_dependencies(self, &block) if pl.respond_to?(:load_dependencies)
|
||||||
|
@ -46,6 +46,18 @@ class SessionTest < Minitest::Test
|
|||||||
body = response.body
|
body = response.body
|
||||||
assert body.respond_to?(:foo), "response body methods haven't been added"
|
assert body.respond_to?(:foo), "response body methods haven't been added"
|
||||||
assert body.foo == "response-body-foo", "response body method is unexpected"
|
assert body.foo == "response-body-foo", "response body method is unexpected"
|
||||||
|
|
||||||
|
# set default options via .plugin
|
||||||
|
klient_class2 = Class.new(HTTPX::Session)
|
||||||
|
klient_class2.plugin(TestPlugin, foo: "options-foo-2")
|
||||||
|
session2 = klient_class2.new
|
||||||
|
assert session2.options.foo == "options-foo-2", ":foo option was not overridden"
|
||||||
|
|
||||||
|
return if defined?(RBS)
|
||||||
|
|
||||||
|
# break if receiving something else
|
||||||
|
assert_raises(ArgumentError) { klient_class2.plugin(TestPlugin, :smth) }
|
||||||
|
assert_raises(ArgumentError) { klient_class2.plugin([TestPlugin, TestPlugin]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_session_subplugin
|
def test_session_subplugin
|
||||||
|
Loading…
x
Reference in New Issue
Block a user