faraday 0.2.3 → 0.2.4
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.
- data/VERSION +1 -1
- data/faraday.gemspec +3 -3
- data/lib/faraday/adapter/test.rb +1 -1
- data/test/adapters/live_test.rb +91 -122
- data/test/adapters/test_middleware_test.rb +15 -17
- data/test/adapters/typhoeus_test.rb +17 -19
- data/test/connection_app_test.rb +10 -14
- data/test/connection_test.rb +129 -135
- data/test/env_test.rb +23 -25
- data/test/helper.rb +5 -1
- data/test/request_middleware_test.rb +17 -12
- data/test/response_middleware_test.rb +28 -36
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/faraday.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{faraday}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["rick"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-18}
|
13
13
|
s.description = %q{HTTP/REST API client library with pluggable components}
|
14
14
|
s.email = %q{technoweenie@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/faraday/adapter/test.rb
CHANGED
data/test/adapters/live_test.rb
CHANGED
@@ -4,152 +4,121 @@ if Faraday::TestCase::LIVE_SERVER
|
|
4
4
|
module Adapters
|
5
5
|
class LiveTest < Faraday::TestCase
|
6
6
|
Faraday::Adapter.all_loaded_constants.each do |adapter|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
use adapter
|
11
|
-
end
|
12
|
-
end
|
7
|
+
define_method "test_#{adapter}_GET_retrieves_the_response_body" do
|
8
|
+
assert_equal 'hello world', create_connection(adapter).get('hello_world').body
|
9
|
+
end
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
define_method "test_#{adapter}_GET_send_url_encoded_params" do
|
12
|
+
resp = create_connection(adapter).get do |req|
|
13
|
+
req.url 'hello', 'name' => 'zack'
|
14
|
+
end
|
15
|
+
assert_equal('hello zack', resp.body)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
define_method "test_#{adapter}_GET_retrieves_the_response_headers" do
|
19
|
+
assert_equal 'text/html', create_connection(adapter).get('hello_world').headers['content-type']
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
define_method "test_#{adapter}_POST_send_url_encoded_params" do
|
23
|
+
resp = create_connection(adapter).post do |req|
|
24
|
+
req.url 'echo_name'
|
25
|
+
req.body = {'name' => 'zack'}
|
26
|
+
end
|
27
|
+
assert_equal %("zack"), resp.body
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
define_method "test_#{adapter}_POST_send_url_encoded_nested_params" do
|
31
|
+
resp = create_connection(adapter).post do |req|
|
32
|
+
req.url 'echo_name'
|
33
|
+
req.body = {'name' => {'first' => 'zack'}}
|
33
34
|
end
|
35
|
+
assert_equal %({"first"=>"zack"}), resp.body
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
38
|
+
define_method "test_#{adapter}_POST_retrieves_the_response_headers" do
|
39
|
+
assert_equal 'text/html', create_connection(adapter).post('echo_name').headers['content-type']
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
# http://github.com/toland/patron/issues/#issue/9
|
43
|
+
if ENV['FORCE'] || adapter != Faraday::Adapter::Patron
|
44
|
+
define_method "test_#{adapter}_PUT_send_url_encoded_params" do
|
45
|
+
resp = create_connection(adapter).put do |req|
|
46
|
+
req.url 'echo_name'
|
47
|
+
req.body = {'name' => 'zack'}
|
46
48
|
end
|
49
|
+
assert_equal %("zack"), resp.body
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
assert_equal %({"first"=>"zack"}), resp.body
|
52
|
+
define_method "test_#{adapter}_PUT_send_url_encoded_nested_params" do
|
53
|
+
resp = create_connection(adapter).put do |req|
|
54
|
+
req.url 'echo_name'
|
55
|
+
req.body = {'name' => {'first' => 'zack'}}
|
54
56
|
end
|
57
|
+
assert_equal %({"first"=>"zack"}), resp.body
|
58
|
+
end
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
end
|
60
|
+
define_method "test_#{adapter}_PUT_retrieves_the_response_headers" do
|
61
|
+
assert_equal 'text/html', create_connection(adapter).put('echo_name').headers['content-type']
|
59
62
|
end
|
63
|
+
end
|
60
64
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
it "send url-encoded params" do
|
69
|
-
resp = @connection.put do |req|
|
70
|
-
req.url 'echo_name'
|
71
|
-
req.body = {'name' => 'zack'}
|
72
|
-
end
|
73
|
-
assert_equal %("zack"), resp.body
|
74
|
-
end
|
75
|
-
|
76
|
-
it "send url-encoded nested params" do
|
77
|
-
resp = @connection.put do |req|
|
78
|
-
req.url 'echo_name'
|
79
|
-
req.body = {'name' => {'first' => 'zack'}}
|
80
|
-
end
|
81
|
-
assert_equal %({"first"=>"zack"}), resp.body
|
82
|
-
end
|
83
|
-
|
84
|
-
it "retrieves the response headers" do
|
85
|
-
assert_equal 'text/html', @connection.put('echo_name').headers['content-type']
|
86
|
-
end
|
65
|
+
# http://github.com/pauldix/typhoeus/issues#issue/7
|
66
|
+
if ENV['FORCE'] || adapter != Faraday::Adapter::Typhoeus
|
67
|
+
define_method "test_#{adapter}_HEAD_send_url_encoded_params" do
|
68
|
+
resp = create_connection(adapter).head do |req|
|
69
|
+
req.url 'hello', 'name' => 'zack'
|
87
70
|
end
|
71
|
+
assert_equal 'text/html', resp.headers['content-type']
|
88
72
|
end
|
89
73
|
|
90
|
-
#
|
91
|
-
|
92
|
-
describe "#head" do
|
93
|
-
it "raises on 404" do
|
94
|
-
assert_raise(Faraday::Error::ResourceNotFound) { @connection.head('/nothing') }
|
95
|
-
end
|
96
|
-
|
97
|
-
it "send url-encoded params" do
|
98
|
-
resp = @connection.head do |req|
|
99
|
-
req.url 'hello', 'name' => 'zack'
|
100
|
-
end
|
101
|
-
assert_equal 'text/html', resp.headers['content-type']
|
102
|
-
end
|
103
|
-
|
104
|
-
it "retrieves no response body" do
|
105
|
-
assert_equal '', @connection.head('hello_world').body.to_s
|
106
|
-
end
|
107
|
-
|
108
|
-
it "retrieves the response headers" do
|
109
|
-
assert_equal 'text/html', @connection.head('hello_world').headers['content-type']
|
110
|
-
end
|
111
|
-
end
|
74
|
+
define_method "test_#{adapter}_HEAD_retrieves_no_response_body" do
|
75
|
+
assert_equal '', create_connection(adapter).head('hello_world').body.to_s
|
112
76
|
end
|
113
77
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
78
|
+
define_method "test_#{adapter}_HEAD_retrieves_the_response_headers" do
|
79
|
+
assert_equal 'text/html', create_connection(adapter).head('hello_world').headers['content-type']
|
80
|
+
end
|
81
|
+
end
|
118
82
|
|
119
|
-
|
120
|
-
|
121
|
-
|
83
|
+
define_method "test_#{adapter}_DELETE_retrieves_the_response_headers" do
|
84
|
+
assert_equal 'text/html', create_connection(adapter).delete('delete_with_json').headers['content-type']
|
85
|
+
end
|
122
86
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
87
|
+
define_method "test_#{adapter}_DELETE_retrieves_the_body" do
|
88
|
+
assert_match /deleted/, create_connection(adapter).delete('delete_with_json').body
|
89
|
+
end
|
127
90
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
91
|
+
define_method "test_#{adapter}_async_requests_clear_parallel_manager_after_running_a_single_request" do
|
92
|
+
connection = create_connection(adapter)
|
93
|
+
assert !connection.in_parallel?
|
94
|
+
resp = connection.get('hello_world')
|
95
|
+
assert !connection.in_parallel?
|
96
|
+
assert_equal 'hello world', connection.get('hello_world').body
|
97
|
+
end
|
98
|
+
|
99
|
+
define_method "test_#{adapter}_async_requests_uses_parallel_manager_to_run_multiple_json_requests" do
|
100
|
+
resp1, resp2 = nil, nil
|
135
101
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
assert_nil resp2.body
|
146
|
-
end
|
147
|
-
end
|
148
|
-
assert !@connection.in_parallel?
|
149
|
-
assert_equal '[1,2,3]', resp1.body
|
150
|
-
assert_equal '[1,2,3]', resp2.body
|
102
|
+
connection = create_connection(adapter)
|
103
|
+
|
104
|
+
connection.in_parallel(adapter.setup_parallel_manager) do
|
105
|
+
resp1 = connection.get('json')
|
106
|
+
resp2 = connection.get('json')
|
107
|
+
if adapter.supports_parallel_requests?
|
108
|
+
assert connection.in_parallel?
|
109
|
+
assert_nil resp1.body
|
110
|
+
assert_nil resp2.body
|
151
111
|
end
|
152
112
|
end
|
113
|
+
assert !connection.in_parallel?
|
114
|
+
assert_equal '[1,2,3]', resp1.body
|
115
|
+
assert_equal '[1,2,3]', resp2.body
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def create_connection(adapter)
|
120
|
+
Faraday::Connection.new LIVE_SERVER do |b|
|
121
|
+
b.use adapter
|
153
122
|
end
|
154
123
|
end
|
155
124
|
end
|
@@ -2,27 +2,25 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
|
|
2
2
|
|
3
3
|
module Adapters
|
4
4
|
class TestMiddleware < Faraday::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
builder.adapter :test, @stubs
|
10
|
-
end
|
11
|
-
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
|
12
|
-
@resp = @conn.get('/hello')
|
5
|
+
def setup
|
6
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
7
|
+
@conn = Faraday::Connection.new do |builder|
|
8
|
+
builder.adapter :test, @stubs
|
13
9
|
end
|
10
|
+
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
|
11
|
+
@resp = @conn.get('/hello')
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def test_middleware_with_simple_path_sets_status
|
15
|
+
assert_equal 200, @resp.status
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def test_middleware_with_simple_path_sets_headers
|
19
|
+
assert_equal 'text/html', @resp.headers['Content-Type']
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
def test_middleware_with_simple_path_sets_body
|
23
|
+
assert_equal 'hello', @resp.body
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -3,25 +3,23 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
|
|
3
3
|
if Faraday::Adapter::Typhoeus.loaded?
|
4
4
|
module Adapters
|
5
5
|
class TestTyphoeus < Faraday::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
assert_equal 'http://sushi.com/', headers['location']
|
24
|
-
end
|
6
|
+
def setup
|
7
|
+
@adapter = Faraday::Adapter::Typhoeus.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_parse_response_headers_leaves_http_status_line_out
|
11
|
+
headers = @adapter.parse_response_headers("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")
|
12
|
+
assert_equal %w(content-type), headers.keys
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_parse_response_headers_parses_lower_cased_header_name_and_value
|
16
|
+
headers = @adapter.parse_response_headers("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n")
|
17
|
+
assert_equal 'text/html', headers['content-type']
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_parse_response_headers_parses_lower_cased_header_name_and_value_with_colon
|
21
|
+
headers = @adapter.parse_response_headers("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nLocation: http://sushi.com/\r\n\r\n")
|
22
|
+
assert_equal 'http://sushi.com/', headers['location']
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
data/test/connection_app_test.rb
CHANGED
@@ -22,28 +22,24 @@ class TestConnectionApps < Faraday::TestCase
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
def setup
|
26
26
|
@conn = Faraday::Connection.new do |b|
|
27
27
|
b.use TestMiddleWare
|
28
28
|
b.use TestAdapter
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
32
|
+
def test_builder_is_built_from_faraday_connection
|
33
|
+
assert_kind_of Faraday::Builder, @conn.builder
|
34
|
+
assert_equal 3, @conn.builder.handlers.size
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
37
|
+
def test_builder_adds_middleware_to_builder_stack
|
38
|
+
assert_kind_of TestMiddleWare, @conn.builder.handlers[2].call(nil)
|
39
|
+
assert_kind_of TestAdapter, @conn.builder.handlers[1].call(nil)
|
42
40
|
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
assert @conn.to_app.respond_to?(:call)
|
47
|
-
end
|
42
|
+
def test_to_app_returns_rack_object
|
43
|
+
assert @conn.to_app.respond_to?(:call)
|
48
44
|
end
|
49
45
|
end
|
data/test/connection_test.rb
CHANGED
@@ -1,167 +1,161 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
2
|
|
3
3
|
class TestConnection < Faraday::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
def test_initialize_parses_host_out_of_given_url
|
5
|
+
conn = Faraday::Connection.new "http://sushi.com"
|
6
|
+
assert_equal 'sushi.com', conn.host
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
def test_initialize_parses_nil_port_out_of_given_url
|
10
|
+
conn = Faraday::Connection.new "http://sushi.com"
|
11
|
+
assert_nil conn.port
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def test_initialize_parses_scheme_out_of_given_url
|
15
|
+
conn = Faraday::Connection.new "http://sushi.com"
|
16
|
+
assert_equal 'http', conn.scheme
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def test_initialize_parses_port_out_of_given_url
|
20
|
+
conn = Faraday::Connection.new "http://sushi.com:815"
|
21
|
+
assert_equal 815, conn.port
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def test_initialize_parses_nil_path_prefix_out_of_given_url
|
25
|
+
conn = Faraday::Connection.new "http://sushi.com"
|
26
|
+
assert_equal '/', conn.path_prefix
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def test_initialize_parses_path_prefix_out_of_given_url
|
30
|
+
conn = Faraday::Connection.new "http://sushi.com/fish"
|
31
|
+
assert_equal '/fish', conn.path_prefix
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def test_initialize_parses_path_prefix_out_of_given_url_option
|
35
|
+
conn = Faraday::Connection.new :url => "http://sushi.com/fish"
|
36
|
+
assert_equal '/fish', conn.path_prefix
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
def test_initialize_stores_default_params_from_options
|
40
|
+
conn = Faraday::Connection.new :params => {:a => 1}
|
41
|
+
assert_equal 1, conn.params['a']
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
def test_initialize_stores_default_params_from_uri
|
45
|
+
conn = Faraday::Connection.new "http://sushi.com/fish?a=1", :params => {'b' => '2'}
|
46
|
+
assert_equal '1', conn.params['a']
|
47
|
+
assert_equal '2', conn.params['b']
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
50
|
+
def test_initialize_stores_default_headers_from_options
|
51
|
+
conn = Faraday::Connection.new :headers => {:a => 1}
|
52
|
+
assert_equal '1', conn.headers['A']
|
55
53
|
end
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
55
|
+
def test_build_url_uses_connection_host_as_default_uri_host
|
56
|
+
conn = Faraday::Connection.new
|
57
|
+
conn.host = 'sushi.com'
|
58
|
+
uri = conn.build_url("/sake.html")
|
59
|
+
assert_equal 'sushi.com', uri.host
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
def test_build_url_uses_connection_port_as_default_uri_port
|
63
|
+
conn = Faraday::Connection.new
|
64
|
+
conn.port = 23
|
65
|
+
uri = conn.build_url("http://sushi.com")
|
66
|
+
assert_equal 23, uri.port
|
67
|
+
end
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
69
|
+
def test_build_url_uses_connection_scheme_as_default_uri_scheme
|
70
|
+
conn = Faraday::Connection.new 'http://sushi.com'
|
71
|
+
uri = conn.build_url("/sake.html")
|
72
|
+
assert_equal 'http', uri.scheme
|
73
|
+
end
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
75
|
+
def test_build_url_uses_connection_path_prefix_to_customize_path
|
76
|
+
conn = Faraday::Connection.new
|
77
|
+
conn.path_prefix = '/fish'
|
78
|
+
uri = conn.build_url("sake.html")
|
79
|
+
assert_equal '/fish/sake.html', uri.path
|
80
|
+
end
|
84
81
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
82
|
+
def test_build_url_uses_root_connection_path_prefix_to_customize_path
|
83
|
+
conn = Faraday::Connection.new
|
84
|
+
conn.path_prefix = '/'
|
85
|
+
uri = conn.build_url("sake.html")
|
86
|
+
assert_equal '/sake.html', uri.path
|
87
|
+
end
|
91
88
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
def test_build_url_forces_connection_path_prefix_to_be_absolute
|
90
|
+
conn = Faraday::Connection.new
|
91
|
+
conn.path_prefix = 'fish'
|
92
|
+
uri = conn.build_url("sake.html")
|
93
|
+
assert_equal '/fish/sake.html', uri.path
|
94
|
+
end
|
98
95
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
96
|
+
def test_build_url_ignores_connection_path_prefix_trailing_slash
|
97
|
+
conn = Faraday::Connection.new
|
98
|
+
conn.path_prefix = '/fish/'
|
99
|
+
uri = conn.build_url("sake.html")
|
100
|
+
assert_equal '/fish/sake.html', uri.path
|
101
|
+
end
|
105
102
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
103
|
+
def test_build_url_allows_absolute_uri_to_ignore_connection_path_prefix
|
104
|
+
conn = Faraday::Connection.new
|
105
|
+
conn.path_prefix = '/fish'
|
106
|
+
uri = conn.build_url("/sake.html")
|
107
|
+
assert_equal '/sake.html', uri.path
|
108
|
+
end
|
112
109
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
110
|
+
def test_build_url_parses_url_params_into_path
|
111
|
+
conn = Faraday::Connection.new
|
112
|
+
uri = conn.build_url("http://sushi.com/sake.html")
|
113
|
+
assert_equal '/sake.html', uri.path
|
114
|
+
end
|
118
115
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
116
|
+
def test_build_url_parses_url_params_into_query
|
117
|
+
conn = Faraday::Connection.new
|
118
|
+
uri = conn.build_url("http://sushi.com/sake.html", 'a[b]' => '1 + 2')
|
119
|
+
assert_equal "a%5Bb%5D=1%20%2B%202", uri.query
|
120
|
+
end
|
124
121
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
122
|
+
def test_build_url_mashes_default_and_given_params_together
|
123
|
+
conn = Faraday::Connection.new 'http://sushi.com/api?token=abc', :params => {'format' => 'json'}
|
124
|
+
url = conn.build_url("nigiri?page=1", :limit => 5)
|
125
|
+
assert_match /limit=5/, url.query
|
126
|
+
assert_match /page=1/, url.query
|
127
|
+
assert_match /format=json/, url.query
|
128
|
+
assert_match /token=abc/, url.query
|
129
|
+
end
|
133
130
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
131
|
+
def test_build_url_overrides_default_params_with_given_params
|
132
|
+
conn = Faraday::Connection.new 'http://sushi.com/api?token=abc', :params => {'format' => 'json'}
|
133
|
+
url = conn.build_url("nigiri?page=1", :limit => 5, :token => 'def', :format => 'xml')
|
134
|
+
assert_match /limit=5/, url.query
|
135
|
+
assert_match /page=1/, url.query
|
136
|
+
assert_match /format=xml/, url.query
|
137
|
+
assert_match /token=def/, url.query
|
138
|
+
assert_no_match /format=json/, url.query
|
139
|
+
assert_no_match /token=abc/, url.query
|
140
|
+
end
|
144
141
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
142
|
+
def test_build_url_parses_url_into_host
|
143
|
+
conn = Faraday::Connection.new
|
144
|
+
uri = conn.build_url("http://sushi.com/sake.html")
|
145
|
+
assert_equal "sushi.com", uri.host
|
146
|
+
end
|
150
147
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
148
|
+
def test_build_url_parses_url_into_port
|
149
|
+
conn = Faraday::Connection.new
|
150
|
+
uri = conn.build_url("http://sushi.com/sake.html")
|
151
|
+
assert_nil uri.port
|
156
152
|
end
|
157
153
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
public :build_query
|
163
|
-
end
|
164
|
-
assert_equal "a%5Bb%5D=1%20%2B%202", conn.build_query('a[b]' => '1 + 2')
|
154
|
+
def test_params_to_query_converts_hash_of_params_to_uri_escaped_query_string
|
155
|
+
conn = Faraday::Connection.new
|
156
|
+
class << conn
|
157
|
+
public :build_query
|
165
158
|
end
|
159
|
+
assert_equal "a%5Bb%5D=1%20%2B%202", conn.build_query('a[b]' => '1 + 2')
|
166
160
|
end
|
167
161
|
end
|
data/test/env_test.rb
CHANGED
@@ -1,35 +1,33 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
2
|
|
3
3
|
class TestEnv < Faraday::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
req.body = @input[:body]
|
14
|
-
end
|
15
|
-
@env = @env_setup.to_env_hash(@conn, :get)
|
4
|
+
def setup
|
5
|
+
@conn = Faraday::Connection.new :url => 'http://sushi.com/api', :headers => {'Mime-Version' => '1.0'}
|
6
|
+
@input = {
|
7
|
+
:body => 'abc',
|
8
|
+
:headers => {'Server' => 'Faraday'}}
|
9
|
+
@env_setup = Faraday::Request.create do |req|
|
10
|
+
req.url 'foo.json', 'a' => 1
|
11
|
+
req['Server'] = 'Faraday'
|
12
|
+
req.body = @input[:body]
|
16
13
|
end
|
14
|
+
@env = @env_setup.to_env_hash(@conn, :get)
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def test_request_create_stores_method
|
18
|
+
assert_equal :get, @env[:method]
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def test_request_create_stores_addressable_uri
|
22
|
+
assert_equal 'http://sushi.com/api/foo.json?a=1', @env[:url].to_s
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
def test_request_create_stores_headers
|
26
|
+
assert_kind_of Rack::Utils::HeaderHash, @env[:request_headers]
|
27
|
+
assert_equal @input[:headers].merge('Mime-Version' => '1.0'), @env[:request_headers]
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
30
|
+
def test_request_create_stores_body
|
31
|
+
assert_equal @input[:body], @env[:body]
|
34
32
|
end
|
35
33
|
end
|
data/test/helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'test/unit'
|
3
3
|
if ENV['LEFTRIGHT']
|
4
4
|
require 'leftright'
|
5
5
|
end
|
@@ -21,5 +21,9 @@ module Faraday
|
|
21
21
|
when nil then nil
|
22
22
|
else 'http://localhost:4567'
|
23
23
|
end
|
24
|
+
|
25
|
+
def test_default
|
26
|
+
assert true
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
@@ -1,18 +1,23 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
2
|
|
3
3
|
class RequestMiddlewareTest < Faraday::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
[:yajl, :rails_json].each do |key|
|
5
|
+
encoder = Faraday::Request.lookup_module(key)
|
6
|
+
next if !encoder.loaded?
|
7
|
+
|
8
|
+
define_method "test_encodes_json_with_#{key}" do
|
9
|
+
raw_json = create_json_connection(encoder).post('echo_body', :a => 1).body
|
10
|
+
raw_json.gsub! /: 1/, ':1' # sometimes rails_json adds a space
|
11
|
+
assert_equal %({"a":1}), raw_json
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def create_json_connection(encoder)
|
17
|
+
Faraday::Connection.new do |b|
|
18
|
+
b.use encoder
|
19
|
+
b.adapter :test do |stub|
|
20
|
+
stub.post('echo_body') { |env| [200, {'Content-Type' => 'text/html'}, env[:body]] }
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
@@ -1,45 +1,37 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
2
|
|
3
3
|
class ResponseMiddlewareTest < Faraday::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
b.use parser
|
14
|
-
end
|
15
|
-
response = @connection.get('json')
|
16
|
-
assert response.success?
|
17
|
-
assert_equal [1,2,3], response.body
|
18
|
-
end
|
4
|
+
[:yajl, :rails_json].each do |key|
|
5
|
+
encoder = Faraday::Response.lookup_module(key)
|
6
|
+
next if !encoder.loaded?
|
7
|
+
|
8
|
+
define_method "test_uses_#{key}_to_parse_json_content" do
|
9
|
+
response = create_json_connection(encoder).get('json')
|
10
|
+
assert response.success?
|
11
|
+
assert_equal [1,2,3], response.body
|
12
|
+
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
14
|
+
define_method "test_uses_#{key}_to_skip_blank_content" do
|
15
|
+
response = create_json_connection(encoder).get('blank')
|
16
|
+
assert response.success?
|
17
|
+
assert !response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method "test_uses_#{key}_to_skip_nil_content" do
|
21
|
+
response = create_json_connection(encoder).get('nil')
|
22
|
+
assert response.success?
|
23
|
+
assert !response.body
|
24
|
+
end
|
25
|
+
end
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
response = @connection.get('nil')
|
40
|
-
assert response.success?
|
41
|
-
assert_equal nil, response.body
|
27
|
+
def create_json_connection(encoder)
|
28
|
+
Faraday::Connection.new do |b|
|
29
|
+
b.adapter :test do |stub|
|
30
|
+
stub.get('json') { [200, {'Content-Type' => 'text/html'}, "[1,2,3]"] }
|
31
|
+
stub.get('blank') { [200, {'Content-Type' => 'text/html'}, ''] }
|
32
|
+
stub.get('nil') { [200, {'Content-Type' => 'text/html'}, nil] }
|
42
33
|
end
|
34
|
+
b.use encoder
|
43
35
|
end
|
44
36
|
end
|
45
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rick
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|