faraday 0.8.11 → 0.9.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. data/.document +6 -0
  2. data/CONTRIBUTING.md +36 -0
  3. data/Gemfile +7 -6
  4. data/LICENSE.md +1 -1
  5. data/README.md +38 -51
  6. data/Rakefile +2 -18
  7. data/faraday.gemspec +34 -0
  8. data/lib/faraday.rb +181 -67
  9. data/lib/faraday/adapter.rb +19 -34
  10. data/lib/faraday/adapter/em_http.rb +24 -10
  11. data/lib/faraday/adapter/em_synchrony.rb +1 -15
  12. data/lib/faraday/adapter/excon.rb +6 -12
  13. data/lib/faraday/adapter/httpclient.rb +92 -0
  14. data/lib/faraday/adapter/net_http.rb +2 -3
  15. data/lib/faraday/adapter/net_http_persistent.rb +3 -15
  16. data/lib/faraday/adapter/patron.rb +13 -21
  17. data/lib/faraday/adapter/rack.rb +0 -2
  18. data/lib/faraday/adapter/test.rb +35 -36
  19. data/lib/faraday/adapter/typhoeus.rb +10 -12
  20. data/lib/faraday/autoload.rb +87 -0
  21. data/lib/faraday/connection.rb +196 -99
  22. data/lib/faraday/error.rb +33 -33
  23. data/lib/faraday/options.rb +215 -0
  24. data/lib/faraday/parameters.rb +193 -0
  25. data/lib/faraday/{builder.rb → rack_builder.rb} +78 -21
  26. data/lib/faraday/request.rb +12 -25
  27. data/lib/faraday/request/authorization.rb +3 -3
  28. data/lib/faraday/request/basic_authentication.rb +1 -1
  29. data/lib/faraday/request/instrumentation.rb +38 -0
  30. data/lib/faraday/request/multipart.rb +10 -9
  31. data/lib/faraday/request/retry.rb +70 -6
  32. data/lib/faraday/request/token_authentication.rb +2 -2
  33. data/lib/faraday/request/url_encoded.rb +7 -6
  34. data/lib/faraday/response.rb +17 -22
  35. data/lib/faraday/response/logger.rb +4 -4
  36. data/lib/faraday/response/raise_error.rb +4 -5
  37. data/lib/faraday/utils.rb +54 -67
  38. data/script/console +7 -0
  39. data/script/release +6 -3
  40. data/script/server +3 -1
  41. data/script/test +7 -33
  42. data/test/adapters/em_http_test.rb +6 -1
  43. data/test/adapters/em_synchrony_test.rb +7 -1
  44. data/test/adapters/excon_test.rb +0 -7
  45. data/test/adapters/httpclient_test.rb +16 -0
  46. data/test/adapters/integration.rb +8 -39
  47. data/test/adapters/logger_test.rb +1 -1
  48. data/test/adapters/net_http_test.rb +0 -31
  49. data/test/adapters/patron_test.rb +1 -1
  50. data/test/adapters/rack_test.rb +0 -5
  51. data/test/adapters/test_middleware_test.rb +19 -4
  52. data/test/adapters/typhoeus_test.rb +20 -3
  53. data/test/authentication_middleware_test.rb +7 -7
  54. data/test/connection_test.rb +52 -75
  55. data/test/env_test.rb +33 -24
  56. data/test/helper.rb +15 -13
  57. data/test/live_server.rb +10 -4
  58. data/test/middleware/instrumentation_test.rb +75 -0
  59. data/test/middleware/retry_test.rb +44 -38
  60. data/test/middleware_stack_test.rb +12 -11
  61. data/test/options_test.rb +126 -0
  62. data/test/request_middleware_test.rb +17 -7
  63. data/test/response_middleware_test.rb +2 -4
  64. data/test/strawberry.rb +2 -0
  65. metadata +82 -28
  66. checksums.yaml +0 -7
  67. data/script/proxy-server +0 -41
  68. data/test/multibyte.txt +0 -1
  69. data/test/parameters_test.rb +0 -24
  70. data/test/utils_test.rb +0 -30
@@ -8,8 +8,13 @@ module Adapters
8
8
  Integration.apply(self, :Parallel) do
9
9
  # https://github.com/eventmachine/eventmachine/pull/289
10
10
  undef :test_timeout
11
+
12
+ def test_binds_local_socket
13
+ host = '1.2.3.4'
14
+ conn = create_connection :request => { :bind => { :host => host } }
15
+ assert_equal host, conn.options[:bind][:host]
16
+ end
11
17
  end unless jruby? and ssl_mode?
12
18
  # https://github.com/eventmachine/eventmachine/issues/180
13
-
14
19
  end
15
20
  end
@@ -8,7 +8,13 @@ module Adapters
8
8
  Integration.apply(self, :Parallel) do
9
9
  # https://github.com/eventmachine/eventmachine/pull/289
10
10
  undef :test_timeout
11
- end unless RUBY_VERSION < '1.9' or jruby?
12
11
 
12
+ def test_binds_local_socket
13
+ host = '1.2.3.4'
14
+ conn = create_connection :request => { :bind => { :host => host } }
15
+ #put conn.get('/who-am-i').body
16
+ assert_equal host, conn.options[:bind][:host]
17
+ end
18
+ end unless RUBY_VERSION < '1.9' or jruby?
13
19
  end
14
20
  end
@@ -8,13 +8,6 @@ module Adapters
8
8
  Integration.apply(self, :NonParallel) do
9
9
  # https://github.com/geemus/excon/issues/126 ?
10
10
  undef :test_timeout if ssl_mode?
11
-
12
- # Excon lets OpenSSL::SSL::SSLError be raised without any way to
13
- # distinguish whether it happened because of a 407 proxy response
14
- undef :test_proxy_auth_fail if ssl_mode?
15
-
16
- # https://github.com/geemus/excon/issues/358
17
- undef :test_connection_error if RUBY_VERSION >= '2.1.0'
18
11
  end
19
12
  end
20
13
  end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../integration', __FILE__)
2
+
3
+ module Adapters
4
+ class HttpclientTest < Faraday::TestCase
5
+
6
+ def adapter() :httpclient end
7
+
8
+ Integration.apply(self, :NonParallel) do
9
+ def test_binds_local_socket
10
+ host = '1.2.3.4'
11
+ conn = create_connection :request => { :bind => { :host => host } }
12
+ assert_equal host, conn.options[:bind][:host]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,6 @@
1
1
  require 'forwardable'
2
2
  require File.expand_path("../../helper", __FILE__)
3
+ Faraday.require_lib 'autoload'
3
4
 
4
5
  module Adapters
5
6
  # Adapter integration tests. To use, implement two methods:
@@ -57,7 +58,7 @@ module Adapters
57
58
  module Compression
58
59
  def test_GET_handles_compression
59
60
  res = get('echo_header', :name => 'accept-encoding')
60
- assert_match(/gzip;.+\bdeflate\b/, res.body)
61
+ assert_match /gzip;.+\bdeflate\b/, res.body
61
62
  end
62
63
  end
63
64
 
@@ -117,7 +118,7 @@ module Adapters
117
118
  resp = post('file') do |req|
118
119
  req.body = {'uploaded_file' => Faraday::UploadIO.new(__FILE__, 'text/x-ruby')}
119
120
  end
120
- assert_equal "file integration.rb text/x-ruby #{File.size(__FILE__)}", resp.body
121
+ assert_equal "file integration.rb text/x-ruby", resp.body
121
122
  end
122
123
 
123
124
  def test_PUT_send_url_encoded_params
@@ -143,8 +144,7 @@ module Adapters
143
144
  end
144
145
 
145
146
  def test_HEAD_retrieves_no_response_body
146
- # FIXME: some adapters return empty string, some nil
147
- assert_equal '', head('echo').body.to_s
147
+ assert_equal '', head('echo').body
148
148
  end
149
149
 
150
150
  def test_HEAD_retrieves_the_response_headers
@@ -161,45 +161,14 @@ module Adapters
161
161
 
162
162
  def test_timeout
163
163
  conn = create_connection(:request => {:timeout => 1, :open_timeout => 1})
164
- assert_raise Faraday::Error::TimeoutError do
164
+ assert_raises Faraday::Error::TimeoutError do
165
165
  conn.get '/slow'
166
166
  end
167
167
  end
168
168
 
169
- def test_connection_error
170
- assert_raise Faraday::Error::ConnectionFailed do
171
- get 'http://localhost:4'
172
- end
173
- end
174
-
175
- def test_proxy
176
- proxy_uri = URI(ENV['LIVE_PROXY'])
177
- conn = create_connection(:proxy => proxy_uri)
178
-
179
- res = conn.get '/echo'
180
- assert_equal 'get', res.body
181
-
182
- unless self.class.ssl_mode?
183
- # proxy can't append "Via" header for HTTPS responses
184
- assert_match(/:#{proxy_uri.port}$/, res['via'])
185
- end
186
- end
187
-
188
- def test_proxy_auth_fail
189
- proxy_uri = URI(ENV['LIVE_PROXY'])
190
- proxy_uri.password = 'WRONG'
191
- conn = create_connection(:proxy => proxy_uri)
192
-
193
- err = assert_raise Faraday::Error::ConnectionFailed do
194
- conn.get '/echo'
195
- end
196
-
197
- unless self.class.ssl_mode? && (self.class.jruby? ||
198
- adapter == :em_http || adapter == :em_synchrony)
199
- # JRuby raises "End of file reached" which cannot be distinguished from a 407
200
- # EM raises "connection closed by server" due to https://github.com/igrigorik/em-socksify/pull/19
201
- assert_equal %{407 "Proxy Authentication Required "}, err.message
202
- end
169
+ def test_empty_body_response_represented_as_blank_string
170
+ response = get('204')
171
+ assert_equal '', response.body
203
172
  end
204
173
 
205
174
  def adapter
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
1
+ require File.expand_path('../../helper', __FILE__)
2
2
  require 'stringio'
3
3
  require 'logger'
4
4
 
@@ -1,6 +1,4 @@
1
1
  require File.expand_path('../integration', __FILE__)
2
- require 'ostruct'
3
- require 'uri'
4
2
 
5
3
  module Adapters
6
4
  class NetHttpTest < Faraday::TestCase
@@ -12,34 +10,5 @@ module Adapters
12
10
 
13
11
  Integration.apply(self, *behaviors)
14
12
 
15
- def test_no_explicit_http_port_number
16
- url = URI('http://example.com')
17
- url.port = nil
18
-
19
- adapter = Faraday::Adapter::NetHttp.new
20
- http = adapter.net_http_connection(:url => url, :request => {})
21
-
22
- assert_equal 80, http.port
23
- end
24
-
25
- def test_no_explicit_https_port_number
26
- url = URI('https://example.com')
27
- url.port = nil
28
-
29
- adapter = Faraday::Adapter::NetHttp.new
30
- http = adapter.net_http_connection(:url => url, :request => {})
31
-
32
- assert_equal 443, http.port
33
- end
34
-
35
- def test_explicit_port_number
36
- url = URI('https://example.com:1234')
37
-
38
- adapter = Faraday::Adapter::NetHttp.new
39
- http = adapter.net_http_connection(:url => url, :request => {})
40
-
41
- assert_equal 1234, http.port
42
- end
43
-
44
13
  end
45
14
  end
@@ -11,7 +11,7 @@ module Adapters
11
11
 
12
12
  # https://github.com/toland/patron/issues/52
13
13
  undef :test_GET_with_body
14
- end unless RUBY_VERSION < '1.9' or jruby?
14
+ end unless jruby?
15
15
 
16
16
  end
17
17
  end
@@ -22,10 +22,5 @@ module Adapters
22
22
  rescue Faraday::Error::ClientError
23
23
  end
24
24
  end
25
-
26
- # test not applicable
27
- undef test_connection_error
28
- undef test_proxy
29
- undef test_proxy_auth_fail
30
25
  end
31
26
  end
@@ -1,9 +1,10 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
1
+ require File.expand_path('../../helper', __FILE__)
2
2
 
3
3
  module Adapters
4
4
  class TestMiddleware < Faraday::TestCase
5
+ Stubs = Faraday::Adapter.lookup_middleware(:test)::Stubs
5
6
  def setup
6
- @stubs = Faraday::Adapter::Test::Stubs.new
7
+ @stubs = Stubs.new
7
8
  @conn = Faraday.new do |builder|
8
9
  builder.adapter :test, @stubs
9
10
  end
@@ -36,11 +37,18 @@ module Adapters
36
37
  @stubs.get('/optional?a=1') { [200, {}, 'a'] }
37
38
  assert_equal 'a', @conn.get('/optional?a=1&b=1').body
38
39
  assert_equal 'a', @conn.get('/optional?a=1').body
39
- assert_raise Faraday::Adapter::Test::Stubs::NotFound do
40
+ assert_raises Faraday::Adapter::Test::Stubs::NotFound do
40
41
  @conn.get('/optional')
41
42
  end
42
43
  end
43
44
 
45
+ def test_middleware_with_http_headers
46
+ @stubs.get('/yo', { 'X-HELLO' => 'hello' }) { [200, {}, 'a'] }
47
+ @stubs.get('/yo') { [200, {}, 'b'] }
48
+ assert_equal 'a', @conn.get('/yo') { |env| env.headers['X-HELLO'] = 'hello' }.body
49
+ assert_equal 'b', @conn.get('/yo').body
50
+ end
51
+
44
52
  def test_middleware_allow_different_outcomes_for_the_same_request
45
53
  @stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
46
54
  @stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'world'] }
@@ -62,9 +70,16 @@ module Adapters
62
70
  end
63
71
 
64
72
  def test_raises_an_error_if_no_stub_is_found_for_request
65
- assert_raise Faraday::Adapter::Test::Stubs::NotFound do
73
+ assert_raises Stubs::NotFound do
66
74
  @conn.get('/invalid'){ [200, {}, []] }
67
75
  end
68
76
  end
77
+
78
+ def test_raises_an_error_if_no_stub_is_found_for_request_without_this_header
79
+ @stubs.get('/yo', { 'X-HELLO' => 'hello' }) { [200, {}, 'a'] }
80
+ assert_raises Faraday::Adapter::Test::Stubs::NotFound do
81
+ @conn.get('/yo')
82
+ end
83
+ end
69
84
  end
70
85
  end
@@ -13,9 +13,26 @@ module Adapters
13
13
  # which libcurl seems to generate for this particular request:
14
14
  undef :test_POST_sends_files
15
15
 
16
- # inconsistent outcomes ranging from successful response to connection error
17
- undef :test_proxy_auth_fail if ssl_mode?
18
- end unless jruby? or ruby_22_plus?
16
+ def test_binds_local_socket
17
+ host = '1.2.3.4'
18
+ conn = create_connection :request => { :bind => { :host => host } }
19
+ assert_equal host, conn.options[:bind][:host]
20
+ end
19
21
 
22
+ def test_GET_ssl_rejects_bad_hosts
23
+ original_ssl_file = ENV['SSL_FILE']
24
+ begin
25
+ ENV['SSL_FILE'] = 'tmp/faraday-different-ca-cert.crt'
26
+ conn = create_connection
27
+ expected = ''
28
+ response = conn.get('/ssl')
29
+ assert_equal expected, response.body
30
+ ensure
31
+ ENV['SSL_FILE'] = original_ssl_file
32
+ end
33
+ end if ssl_mode?
34
+
35
+ end unless jruby?
20
36
  end
21
37
  end
38
+
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class AuthenticationMiddlewareTest < Faraday::TestCase
4
4
  def conn
@@ -37,9 +37,9 @@ class AuthenticationMiddlewareTest < Faraday::TestCase
37
37
  response = conn { |b|
38
38
  b.request :token_auth, 'baz', :foo => 42
39
39
  }.get('/auth-echo')
40
- assert_match(/^Token /, response.body)
41
- assert_match(/token="baz"/, response.body)
42
- assert_match(/foo="42"/, response.body)
40
+ assert_match /^Token /, response.body
41
+ assert_match /token="baz"/, response.body
42
+ assert_match /foo="42"/, response.body
43
43
  end
44
44
 
45
45
  def test_token_middleware_does_not_interfere_with_existing_authorization
@@ -52,14 +52,14 @@ class AuthenticationMiddlewareTest < Faraday::TestCase
52
52
  response = conn { |b|
53
53
  b.request :authorization, 'custom', 'abc def'
54
54
  }.get('/auth-echo')
55
- assert_match(/^custom abc def$/, response.body)
55
+ assert_match /^custom abc def$/, response.body
56
56
  end
57
57
 
58
58
  def test_authorization_middleware_with_hash
59
59
  response = conn { |b|
60
60
  b.request :authorization, 'baz', :foo => 42
61
61
  }.get('/auth-echo')
62
- assert_match(/^baz /, response.body)
63
- assert_match(/foo="42"/, response.body)
62
+ assert_match /^baz /, response.body
63
+ assert_match /foo="42"/, response.body
64
64
  end
65
65
  end
@@ -1,8 +1,12 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
1
+ require File.expand_path('../helper', __FILE__)
2
2
  require 'uri'
3
3
 
4
4
  class TestConnection < Faraday::TestCase
5
5
 
6
+ def teardown
7
+ Faraday::Utils.default_params_encoder = nil
8
+ end
9
+
6
10
  def with_env(key, proxy)
7
11
  old_value = ENV.fetch(key, false)
8
12
  ENV[key] = proxy
@@ -191,6 +195,19 @@ class TestConnection < Faraday::TestCase
191
195
  assert_equal "a%5Bb%5D=c", uri.query
192
196
  end
193
197
 
198
+ def test_build_url_bracketizes_repeated_params_in_query
199
+ conn = Faraday::Connection.new
200
+ uri = conn.build_url("http://sushi.com/sake.html", 'a' => [1, 2])
201
+ assert_equal "a%5B%5D=1&a%5B%5D=2", uri.query
202
+ end
203
+
204
+ def test_build_url_without_braketizing_repeated_params_in_query
205
+ conn = Faraday::Connection.new
206
+ conn.options.params_encoder = Faraday::FlatParamsEncoder
207
+ uri = conn.build_url("http://sushi.com/sake.html", 'a' => [1, 2])
208
+ assert_equal "a=1&a=2", uri.query
209
+ end
210
+
194
211
  def test_build_url_parses_url
195
212
  conn = Faraday::Connection.new
196
213
  uri = conn.build_url("http://sushi.com/sake.html")
@@ -212,26 +229,11 @@ class TestConnection < Faraday::TestCase
212
229
  assert_equal '/sake.html', uri.path
213
230
  end
214
231
 
215
- def test_request_header_change_does_not_modify_connection_header
216
- connection = Faraday.new(:url => "https://asushi.com/sake.html")
217
- connection.headers = { "Authorization"=>"token abc123" }
218
-
219
- request = connection.build_request(:get)
220
- request.headers.delete("Authorization")
221
-
222
- assert_equal connection.headers.keys.sort, ["Authorization"]
223
- assert connection.headers.include?("Authorization")
224
-
225
- assert_equal request.headers.keys.sort, []
226
- assert !request.headers.include?("Authorization")
227
- end
228
-
229
232
  def test_proxy_accepts_string
230
233
  with_env 'http_proxy', "http://duncan.proxy.com:80" do
231
234
  conn = Faraday::Connection.new
232
235
  conn.proxy 'http://proxy.com'
233
- assert_equal 'proxy.com', conn.proxy[:uri].host
234
- assert_equal [:uri], conn.proxy.keys
236
+ assert_equal 'proxy.com', conn.proxy.host
235
237
  end
236
238
  end
237
239
 
@@ -239,8 +241,7 @@ class TestConnection < Faraday::TestCase
239
241
  with_env 'http_proxy', "http://duncan.proxy.com:80" do
240
242
  conn = Faraday::Connection.new
241
243
  conn.proxy URI.parse('http://proxy.com')
242
- assert_equal 'proxy.com', conn.proxy[:uri].host
243
- assert_equal [:uri], conn.proxy.keys
244
+ assert_equal 'proxy.com', conn.proxy.host
244
245
  end
245
246
  end
246
247
 
@@ -248,8 +249,8 @@ class TestConnection < Faraday::TestCase
248
249
  with_env 'http_proxy', "http://duncan.proxy.com:80" do
249
250
  conn = Faraday::Connection.new
250
251
  conn.proxy :uri => 'http://proxy.com', :user => 'rick'
251
- assert_equal 'proxy.com', conn.proxy[:uri].host
252
- assert_equal 'rick', conn.proxy[:user]
252
+ assert_equal 'proxy.com', conn.proxy.host
253
+ assert_equal 'rick', conn.proxy.user
253
254
  end
254
255
  end
255
256
 
@@ -257,59 +258,23 @@ class TestConnection < Faraday::TestCase
257
258
  with_env 'http_proxy', "http://duncan.proxy.com:80" do
258
259
  conn = Faraday::Connection.new
259
260
  conn.proxy :uri => URI.parse('http://proxy.com'), :user => 'rick'
260
- assert_equal 'proxy.com', conn.proxy[:uri].host
261
- assert_equal 'rick', conn.proxy[:user]
261
+ assert_equal 'proxy.com', conn.proxy.host
262
+ assert_equal 'rick', conn.proxy.user
262
263
  end
263
264
  end
264
265
 
265
266
  def test_proxy_accepts_http_env
266
267
  with_env 'http_proxy', "http://duncan.proxy.com:80" do
267
268
  conn = Faraday::Connection.new
268
- assert_equal 'duncan.proxy.com', conn.proxy[:uri].host
269
+ assert_equal 'duncan.proxy.com', conn.proxy.host
269
270
  end
270
271
  end
271
272
 
272
273
  def test_proxy_accepts_http_env_with_auth
273
274
  with_env 'http_proxy', "http://a%40b:my%20pass@duncan.proxy.com:80" do
274
275
  conn = Faraday::Connection.new
275
- assert_equal 'a@b', conn.proxy[:user]
276
- assert_equal 'my pass', conn.proxy[:password]
277
- end
278
- end
279
-
280
- def test_proxy_accepts_env_without_scheme
281
- with_env 'http_proxy', "localhost:8888" do
282
- uri = Faraday::Connection.new.proxy[:uri]
283
- assert_equal 'localhost', uri.host
284
- assert_equal 8888, uri.port
285
- end
286
- end
287
-
288
- def test_no_proxy_from_env
289
- with_env 'http_proxy', nil do
290
- conn = Faraday::Connection.new
291
- assert_equal nil, conn.proxy
292
- end
293
- end
294
-
295
- def test_no_proxy_from_blank_env
296
- with_env 'http_proxy', '' do
297
- conn = Faraday::Connection.new
298
- assert_equal nil, conn.proxy
299
- end
300
- end
301
-
302
- def test_proxy_doesnt_accept_uppercase_env
303
- with_env 'HTTP_PROXY', "http://localhost:8888/" do
304
- conn = Faraday::Connection.new
305
- assert_nil conn.proxy
306
- end
307
- end
308
-
309
- def test_proxy_requires_uri
310
- conn = Faraday::Connection.new
311
- assert_raises ArgumentError do
312
- conn.proxy :uri => :bad_uri, :user => 'rick'
276
+ assert_equal 'a@b', conn.proxy.user
277
+ assert_equal 'my pass', conn.proxy.password
313
278
  end
314
279
  end
315
280
 
@@ -317,8 +282,7 @@ class TestConnection < Faraday::TestCase
317
282
  conn = Faraday::Connection.new 'http://sushi.com/foo',
318
283
  :ssl => { :verify => :none },
319
284
  :headers => {'content-type' => 'text/plain'},
320
- :params => {'a'=>'1'},
321
- :request => {:timeout => 5}
285
+ :params => {'a'=>'1'}
322
286
 
323
287
  other = conn.dup
324
288
 
@@ -329,14 +293,11 @@ class TestConnection < Faraday::TestCase
329
293
  other.basic_auth('', '')
330
294
  other.headers['content-length'] = 12
331
295
  other.params['b'] = '2'
332
- other.options[:open_timeout] = 10
333
296
 
334
297
  assert_equal 2, other.builder.handlers.size
335
298
  assert_equal 2, conn.builder.handlers.size
336
299
  assert !conn.headers.key?('content-length')
337
300
  assert !conn.params.key?('b')
338
- assert_equal 5, other.options[:timeout]
339
- assert_nil conn.options[:open_timeout]
340
301
  end
341
302
 
342
303
  def test_init_with_block
@@ -359,20 +320,13 @@ class TestRequestParams < Faraday::TestCase
359
320
  def create_connection(*args)
360
321
  @conn = Faraday::Connection.new(*args) do |conn|
361
322
  yield conn if block_given?
362
- class << conn
323
+ class << conn.builder
363
324
  undef app
364
325
  def app() lambda { |env| env } end
365
326
  end
366
327
  end
367
328
  end
368
329
 
369
- def get(*args)
370
- env = @conn.get(*args) do |req|
371
- yield req if block_given?
372
- end
373
- env[:url].query
374
- end
375
-
376
330
  def assert_query_equal(expected, query)
377
331
  assert_equal expected, query.split('&').sort
378
332
  end
@@ -433,14 +387,37 @@ class TestRequestParams < Faraday::TestCase
433
387
  end
434
388
 
435
389
  def test_array_params_in_url
390
+ Faraday::Utils.default_params_encoder = nil
436
391
  create_connection 'http://a.co/page1?color[]=red&color[]=blue'
437
392
  query = get
438
393
  assert_equal "color%5B%5D=red&color%5B%5D=blue", query
439
394
  end
440
395
 
441
396
  def test_array_params_in_params
397
+ Faraday::Utils.default_params_encoder = nil
442
398
  create_connection 'http://a.co/page1', :params => {:color => ['red', 'blue']}
443
399
  query = get
444
400
  assert_equal "color%5B%5D=red&color%5B%5D=blue", query
445
401
  end
402
+
403
+ def test_array_params_in_url_with_flat_params
404
+ Faraday::Utils.default_params_encoder = Faraday::FlatParamsEncoder
405
+ create_connection 'http://a.co/page1?color=red&color=blue'
406
+ query = get
407
+ assert_equal "color=red&color=blue", query
408
+ end
409
+
410
+ def test_array_params_in_params_with_flat_params
411
+ Faraday::Utils.default_params_encoder = Faraday::FlatParamsEncoder
412
+ create_connection 'http://a.co/page1', :params => {:color => ['red', 'blue']}
413
+ query = get
414
+ assert_equal "color=red&color=blue", query
415
+ end
416
+
417
+ def get(*args)
418
+ env = @conn.get(*args) do |req|
419
+ yield req if block_given?
420
+ end
421
+ env[:url].query
422
+ end
446
423
  end