mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-08 00:03:41 -04:00
handle default connection options set with hash (#629)
* handle default connection options set with hash
This commit is contained in:
parent
d2f000be48
commit
e66210bd9d
@ -34,9 +34,6 @@ module Faraday
|
||||
# Faraday.get "https://faraday.com"
|
||||
attr_writer :default_connection
|
||||
|
||||
# Public: Sets the default options used when calling Faraday#new.
|
||||
attr_writer :default_connection_options
|
||||
|
||||
# Public: Initializes a new Faraday::Connection.
|
||||
#
|
||||
# url - The optional String base URL to use as a prefix for all
|
||||
@ -122,6 +119,11 @@ module Faraday
|
||||
@default_connection_options ||= ConnectionOptions.new
|
||||
end
|
||||
|
||||
# Public: Sets the default options used when calling Faraday#new.
|
||||
def self.default_connection_options=(options)
|
||||
@default_connection_options = ConnectionOptions.from(options)
|
||||
end
|
||||
|
||||
unless const_defined? :Timer
|
||||
require 'timeout'
|
||||
Timer = Timeout
|
||||
|
@ -2,6 +2,10 @@ require File.expand_path('../helper', __FILE__)
|
||||
|
||||
class TestConnection < Faraday::TestCase
|
||||
|
||||
def teardown
|
||||
Faraday.default_connection_options = nil
|
||||
end
|
||||
|
||||
def with_env(key, proxy)
|
||||
old_value = ENV.fetch(key, false)
|
||||
ENV[key] = proxy
|
||||
@ -428,6 +432,24 @@ class TestConnection < Faraday::TestCase
|
||||
assert_equal 10, conn.options.timeout
|
||||
end
|
||||
|
||||
def test_default_connection_options_as_hash
|
||||
Faraday.default_connection_options = { request: { timeout: 10 } }
|
||||
conn = Faraday.new 'http://sushi.com/foo'
|
||||
assert_equal 10, conn.options.timeout
|
||||
end
|
||||
|
||||
def test_default_connection_options_as_hash_without_url
|
||||
Faraday.default_connection_options = { request: { timeout: 10 } }
|
||||
conn = Faraday.new :url => 'http://sushi.com/foo'
|
||||
assert_equal 10, conn.options.timeout
|
||||
end
|
||||
|
||||
def test_default_connection_options_as_hash_with_instance_connection_options
|
||||
Faraday.default_connection_options = { request: { timeout: 10 } }
|
||||
conn = Faraday.new 'http://sushi.com/foo', request: { open_timeout: 1 }
|
||||
assert_equal 1, conn.options.open_timeout
|
||||
end
|
||||
|
||||
def env_url(url, params)
|
||||
conn = Faraday::Connection.new(url, :params => params)
|
||||
yield(conn) if block_given?
|
||||
|
Loading…
x
Reference in New Issue
Block a user