faraday-http-cache 0.2.1 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +32 -8
- data/lib/faraday/http_cache.rb +85 -20
- data/lib/faraday/http_cache/response.rb +5 -4
- data/lib/faraday/http_cache/storage.rb +16 -7
- data/spec/binary_spec.rb +18 -0
- data/spec/cache_control_spec.rb +43 -43
- data/spec/json_spec.rb +6 -8
- data/spec/middleware_spec.rb +100 -73
- data/spec/response_spec.rb +89 -89
- data/spec/spec_helper.rb +3 -0
- data/spec/storage_spec.rb +38 -19
- data/spec/support/empty.png +0 -0
- data/spec/support/test_app.rb +24 -13
- data/spec/support/test_server.rb +5 -5
- metadata +9 -4
data/spec/json_spec.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Faraday::HttpCache do
|
4
|
-
let(:logger) { double('a Logger object', :debug => nil) }
|
5
|
-
|
6
4
|
let(:client) do
|
7
|
-
Faraday.new(:
|
8
|
-
stack.response :json, :
|
9
|
-
stack.use :http_cache
|
5
|
+
Faraday.new(url: ENV['FARADAY_SERVER']) do |stack|
|
6
|
+
stack.response :json, content_type: /\bjson$/
|
7
|
+
stack.use :http_cache
|
10
8
|
adapter = ENV['FARADAY_ADAPTER']
|
11
9
|
stack.headers['X-Faraday-Adapter'] = adapter
|
12
10
|
stack.adapter adapter.to_sym
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
it
|
14
|
+
it 'works fine with other middlewares' do
|
17
15
|
client.get('clear')
|
18
|
-
client.get('json').body['count'].
|
19
|
-
client.get('json').body['count'].
|
16
|
+
expect(client.get('json').body['count']).to eq(1)
|
17
|
+
expect(client.get('json').body['count']).to eq(1)
|
20
18
|
end
|
21
19
|
end
|
data/spec/middleware_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Faraday::HttpCache do
|
4
|
-
let(:logger) { double('a Logger object', :
|
4
|
+
let(:logger) { double('a Logger object', debug: nil) }
|
5
5
|
|
6
6
|
let(:client) do
|
7
|
-
Faraday.new(:
|
8
|
-
stack.use Faraday::HttpCache, :
|
7
|
+
Faraday.new(url: ENV['FARADAY_SERVER']) do |stack|
|
8
|
+
stack.use Faraday::HttpCache, logger: logger
|
9
9
|
adapter = ENV['FARADAY_ADAPTER']
|
10
10
|
stack.headers['X-Faraday-Adapter'] = adapter
|
11
11
|
stack.adapter adapter.to_sym
|
@@ -16,154 +16,181 @@ describe Faraday::HttpCache do
|
|
16
16
|
client.get('clear')
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'does not cache POST requests' do
|
20
20
|
client.post('post').body
|
21
|
-
client.post('post').body.
|
21
|
+
expect(client.post('post').body).to eq('2')
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
logger.
|
24
|
+
it 'logs that a POST request is unacceptable' do
|
25
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [POST /post] unacceptable')
|
26
26
|
client.post('post').body
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'does not cache responses with invalid status code' do
|
30
30
|
client.get('broken')
|
31
|
-
client.get('broken').body.
|
31
|
+
expect(client.get('broken').body).to eq('2')
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
logger.
|
34
|
+
it 'logs that a response with a bad status code is invalid' do
|
35
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /broken] miss, invalid')
|
36
36
|
client.get('broken')
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'does not cache requests with a private cache control' do
|
40
40
|
client.get('private')
|
41
|
-
client.get('private').body.
|
41
|
+
expect(client.get('private').body).to eq('2')
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
45
|
-
logger.
|
44
|
+
it 'logs that a private response is invalid' do
|
45
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /private] miss, invalid')
|
46
46
|
client.get('private')
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'does not cache requests with a explicit no-store directive' do
|
50
50
|
client.get('dontstore')
|
51
|
-
client.get('dontstore').body.
|
51
|
+
expect(client.get('dontstore').body).to eq('2')
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
55
|
-
logger.
|
54
|
+
it 'logs that a response with a no-store directive is invalid' do
|
55
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /dontstore] miss, invalid')
|
56
56
|
client.get('dontstore')
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it 'caches multiple responses when the headers differ' do
|
60
60
|
client.get('get', nil, 'HTTP_ACCEPT' => 'text/html')
|
61
|
-
client.get('get', nil, 'HTTP_ACCEPT' => 'text/html').body.
|
62
|
-
|
63
|
-
client.get('get', nil, 'HTTP_ACCEPT' => 'application/json').body.should == "2"
|
61
|
+
expect(client.get('get', nil, 'HTTP_ACCEPT' => 'text/html').body).to eq('1')
|
62
|
+
expect(client.get('get', nil, 'HTTP_ACCEPT' => 'application/json').body).to eq('2')
|
64
63
|
end
|
65
64
|
|
66
|
-
it
|
65
|
+
it 'caches requests with the "Expires" header' do
|
67
66
|
client.get('expires')
|
68
|
-
client.get('expires').body.
|
67
|
+
expect(client.get('expires').body).to eq('1')
|
69
68
|
end
|
70
69
|
|
71
|
-
it
|
72
|
-
logger.
|
70
|
+
it 'logs that a request with the "Expires" is fresh and stored' do
|
71
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /expires] miss, store')
|
73
72
|
client.get('expires')
|
74
73
|
end
|
75
74
|
|
76
|
-
it
|
75
|
+
it 'caches GET responses' do
|
77
76
|
client.get('get')
|
78
|
-
client.get('get').body.
|
77
|
+
expect(client.get('get').body).to eq('1')
|
79
78
|
end
|
80
79
|
|
81
|
-
it
|
82
|
-
logger.
|
80
|
+
it 'logs that a GET response is stored' do
|
81
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /get] miss, store')
|
83
82
|
client.get('get')
|
84
83
|
end
|
85
84
|
|
86
|
-
it
|
87
|
-
logger.
|
88
|
-
logger.
|
85
|
+
it 'differs requests with different query strings in the log' do
|
86
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /get] miss, store')
|
87
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /get?q=what] miss, store')
|
89
88
|
client.get('get')
|
90
|
-
client.get('get', :
|
89
|
+
client.get('get', q: 'what')
|
91
90
|
end
|
92
91
|
|
93
|
-
it
|
92
|
+
it 'logs that a stored GET response is fresh' do
|
94
93
|
client.get('get')
|
95
|
-
logger.
|
94
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /get] fresh')
|
96
95
|
client.get('get')
|
97
96
|
end
|
98
97
|
|
99
|
-
it
|
98
|
+
it 'sends the "Last-Modified" header on response validation' do
|
100
99
|
client.get('timestamped')
|
101
|
-
client.get('timestamped').body.
|
100
|
+
expect(client.get('timestamped').body).to eq('1')
|
102
101
|
end
|
103
102
|
|
104
|
-
it
|
103
|
+
it 'logs that the request with "Last-Modified" was revalidated' do
|
105
104
|
client.get('timestamped')
|
106
|
-
logger.
|
107
|
-
client.get('timestamped').body.
|
105
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /timestamped] valid, store')
|
106
|
+
expect(client.get('timestamped').body).to eq('1')
|
108
107
|
end
|
109
108
|
|
110
|
-
it
|
109
|
+
it 'sends the "If-None-Match" header on response validation' do
|
111
110
|
client.get('etag')
|
112
|
-
client.get('etag').body.
|
111
|
+
expect(client.get('etag').body).to eq('1')
|
113
112
|
end
|
114
113
|
|
115
|
-
it
|
114
|
+
it 'logs that the request with "ETag" was revalidated' do
|
116
115
|
client.get('etag')
|
117
|
-
logger.
|
118
|
-
client.get('etag').body.
|
116
|
+
expect(logger).to receive(:debug).with('HTTP Cache: [GET /etag] valid, store')
|
117
|
+
expect(client.get('etag').body).to eq('1')
|
119
118
|
end
|
120
119
|
|
121
|
-
it
|
122
|
-
|
123
|
-
client.get('get').headers['Date']
|
120
|
+
it 'maintains the "Date" header for cached responses' do
|
121
|
+
first_date = client.get('get').headers['Date']
|
122
|
+
second_date = client.get('get').headers['Date']
|
123
|
+
expect(first_date).to eq(second_date)
|
124
124
|
end
|
125
125
|
|
126
|
-
it
|
126
|
+
it 'preserves an old "Date" header if present' do
|
127
127
|
date = client.get('yesterday').headers['Date']
|
128
|
-
date.
|
128
|
+
expect(date).to match(/^\w{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/)
|
129
129
|
end
|
130
130
|
|
131
|
-
it
|
132
|
-
|
133
|
-
client.get('etag').headers['Cache-Control']
|
131
|
+
it 'updates the "Cache-Control" header when a response is validated' do
|
132
|
+
first_cache_control = client.get('etag').headers['Cache-Control']
|
133
|
+
second_cache_control = client.get('etag').headers['Cache-Control']
|
134
|
+
expect(first_cache_control).not_to eql(second_cache_control)
|
134
135
|
end
|
135
136
|
|
136
|
-
it
|
137
|
-
|
138
|
-
client.get('etag').headers['Date']
|
137
|
+
it 'updates the "Date" header when a response is validated' do
|
138
|
+
first_date = client.get('etag').headers['Date']
|
139
|
+
second_date = client.get('etag').headers['Date']
|
140
|
+
expect(first_date).not_to eql(second_date)
|
139
141
|
end
|
140
142
|
|
141
|
-
it
|
142
|
-
|
143
|
-
client.get('etag').headers['Expires']
|
143
|
+
it 'updates the "Expires" header when a response is validated' do
|
144
|
+
first_expires = client.get('etag').headers['Expires']
|
145
|
+
second_expires = client.get('etag').headers['Expires']
|
146
|
+
expect(first_expires).not_to eql(second_expires)
|
144
147
|
end
|
145
|
-
|
146
|
-
it
|
147
|
-
|
148
|
-
client.get('etag').headers['Vary']
|
148
|
+
|
149
|
+
it 'updates the "Vary" header when a response is validated' do
|
150
|
+
first_vary = client.get('etag').headers['Vary']
|
151
|
+
second_vary = client.get('etag').headers['Vary']
|
152
|
+
expect(first_vary).not_to eql(second_vary)
|
149
153
|
end
|
150
154
|
|
151
155
|
describe 'Configuration options' do
|
152
|
-
let(:app) { double(
|
156
|
+
let(:app) { double('it is an app!') }
|
153
157
|
|
154
158
|
it 'uses the options to create a Cache Store' do
|
155
|
-
ActiveSupport::Cache.
|
156
|
-
Faraday::HttpCache.new(app, :file_store, 'tmp')
|
159
|
+
expect(ActiveSupport::Cache).to receive(:lookup_store).with(:file_store, ['tmp'])
|
160
|
+
Faraday::HttpCache.new(app, store: :file_store, store_options: ['tmp'])
|
157
161
|
end
|
158
162
|
|
159
163
|
it 'accepts a Hash option' do
|
160
|
-
ActiveSupport::Cache.
|
161
|
-
Faraday::HttpCache.new(app, :memory_store, :size
|
164
|
+
expect(ActiveSupport::Cache).to receive(:lookup_store).with(:memory_store, [{ size: 1024 }])
|
165
|
+
Faraday::HttpCache.new(app, store: :memory_store, store_options: [size: 1024])
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'consumes the "logger" key' do
|
169
|
+
expect(ActiveSupport::Cache).to receive(:lookup_store).with(:memory_store, nil)
|
170
|
+
Faraday::HttpCache.new(app, store: :memory_store, logger: logger)
|
162
171
|
end
|
163
172
|
|
164
|
-
|
165
|
-
|
166
|
-
|
173
|
+
context 'with deprecated options format' do
|
174
|
+
it 'uses the options to create a Cache Store' do
|
175
|
+
expect(ActiveSupport::Cache).to receive(:lookup_store).with(:file_store, ['tmp'])
|
176
|
+
Faraday::HttpCache.new(app, :file_store, 'tmp')
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'accepts a Hash option' do
|
180
|
+
expect(ActiveSupport::Cache).to receive(:lookup_store).with(:memory_store, [{ size: 1024 }])
|
181
|
+
Faraday::HttpCache.new(app, :memory_store, size: 1024)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'consumes the "logger" key' do
|
185
|
+
expect(ActiveSupport::Cache).to receive(:lookup_store).with(:memory_store, [{}])
|
186
|
+
Faraday::HttpCache.new(app, :memory_store, logger: logger)
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'warns the user about the deprecated options' do
|
190
|
+
expect(ActiveSupport::Deprecation).to receive(:warn)
|
191
|
+
|
192
|
+
Faraday::HttpCache.new(app, :memory_store, logger: logger)
|
193
|
+
end
|
167
194
|
end
|
168
195
|
end
|
169
196
|
end
|
data/spec/response_spec.rb
CHANGED
@@ -1,156 +1,157 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Faraday::HttpCache::Response do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
headers = {
|
7
|
-
response = Faraday::HttpCache::Response.new(:
|
4
|
+
describe 'cacheable?' do
|
5
|
+
it 'the response is not cacheable if the response is marked as private' do
|
6
|
+
headers = { 'Cache-Control' => 'private' }
|
7
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
8
8
|
|
9
|
-
response.
|
9
|
+
expect(response).not_to be_cacheable
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
13
|
-
headers = {
|
14
|
-
response = Faraday::HttpCache::Response.new(:
|
12
|
+
it 'the response is not cacheable if it should not be stored' do
|
13
|
+
headers = { 'Cache-Control' => 'no-store' }
|
14
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
15
15
|
|
16
|
-
response.
|
16
|
+
expect(response).not_to be_cacheable
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
headers = {
|
21
|
-
response = Faraday::HttpCache::Response.new(:
|
22
|
-
response.
|
19
|
+
it 'the response is not cacheable when the status code is not acceptable' do
|
20
|
+
headers = { 'Cache-Control' => 'max-age=400' }
|
21
|
+
response = Faraday::HttpCache::Response.new(status: 503, response_headers: headers)
|
22
|
+
expect(response).not_to be_cacheable
|
23
23
|
end
|
24
24
|
|
25
25
|
[200, 203, 300, 301, 302, 404, 410].each do |status|
|
26
26
|
it "the response is cacheable if the status code is #{status} and the response is fresh" do
|
27
|
-
headers = {
|
28
|
-
response = Faraday::HttpCache::Response.new(:
|
27
|
+
headers = { 'Cache-Control' => 'max-age=400' }
|
28
|
+
response = Faraday::HttpCache::Response.new(status: status, response_headers: headers)
|
29
29
|
|
30
|
-
response.
|
30
|
+
expect(response).to be_cacheable
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe
|
36
|
-
it
|
35
|
+
describe 'freshness' do
|
36
|
+
it 'is fresh if the response still has some time to live' do
|
37
37
|
date = 200.seconds.ago.httpdate
|
38
|
-
headers = {
|
39
|
-
response = Faraday::HttpCache::Response.new(:
|
38
|
+
headers = { 'Cache-Control' => 'max-age=400', 'Date' => date }
|
39
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
40
40
|
|
41
|
-
response.
|
41
|
+
expect(response).to be_fresh
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'is not fresh when the ttl has expired' do
|
45
45
|
date = 500.seconds.ago.httpdate
|
46
|
-
headers = {
|
47
|
-
response = Faraday::HttpCache::Response.new(:
|
46
|
+
headers = { 'Cache-Control' => 'max-age=400', 'Date' => date }
|
47
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
48
48
|
|
49
|
-
response.
|
49
|
+
expect(response).not_to be_fresh
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'sets the "Date" header if is not present' do
|
54
54
|
headers = { 'Date' => nil }
|
55
|
-
response = Faraday::HttpCache::Response.new(:
|
55
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
56
56
|
|
57
|
-
response.date.
|
57
|
+
expect(response.date).to be
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
61
|
-
response = Faraday::HttpCache::Response.new(:
|
62
|
-
response.
|
60
|
+
it 'the response is not modified if the status code is 304' do
|
61
|
+
response = Faraday::HttpCache::Response.new(status: 304)
|
62
|
+
expect(response).to be_not_modified
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
headers = {
|
67
|
-
response = Faraday::HttpCache::Response.new(:
|
68
|
-
response.last_modified.
|
65
|
+
it 'returns the "Last-Modified" header on the #last_modified method' do
|
66
|
+
headers = { 'Last-Modified' => '123' }
|
67
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
68
|
+
expect(response.last_modified).to eq('123')
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
headers = {
|
73
|
-
response = Faraday::HttpCache::Response.new(:
|
74
|
-
response.etag.
|
71
|
+
it 'returns the "ETag" header on the #etag method' do
|
72
|
+
headers = { 'ETag' => 'tag' }
|
73
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
74
|
+
expect(response.etag).to eq('tag')
|
75
75
|
end
|
76
76
|
|
77
|
-
describe
|
78
|
-
it
|
79
|
-
headers = {
|
80
|
-
response = Faraday::HttpCache::Response.new(:
|
81
|
-
response.max_age.
|
77
|
+
describe 'max age calculation' do
|
78
|
+
it 'uses the shared max age directive when present' do
|
79
|
+
headers = { 'Cache-Control' => 's-maxage=200, max-age=0' }
|
80
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
81
|
+
expect(response.max_age).to be(200)
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
85
|
-
headers = {
|
86
|
-
response = Faraday::HttpCache::Response.new(:
|
87
|
-
response.max_age.
|
84
|
+
it 'uses the max age directive when present' do
|
85
|
+
headers = { 'Cache-Control' => 'max-age=200' }
|
86
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
87
|
+
expect(response.max_age).to be(200)
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
91
|
-
headers = {
|
92
|
-
response = Faraday::HttpCache::Response.new(:
|
93
|
-
|
94
|
-
response.max_age.
|
90
|
+
it 'fallsback to the expiration date leftovers' do
|
91
|
+
headers = { 'Expires' => (Time.now + 100).httpdate, 'Date' => Time.now.httpdate }
|
92
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
93
|
+
|
94
|
+
expect(response.max_age).to be < 100
|
95
|
+
expect(response.max_age).to be > 98
|
95
96
|
end
|
96
97
|
|
97
|
-
it
|
98
|
+
it 'returns nil when there is no information to calculate the max age' do
|
98
99
|
response = Faraday::HttpCache::Response.new
|
99
|
-
response.max_age.
|
100
|
+
expect(response.max_age).to be_nil
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
|
-
describe
|
104
|
-
it
|
105
|
-
response = Faraday::HttpCache::Response.new(:
|
106
|
-
response.age.
|
104
|
+
describe 'age calculation' do
|
105
|
+
it 'uses the "Age" header if it is present' do
|
106
|
+
response = Faraday::HttpCache::Response.new(response_headers: { 'Age' => '3' })
|
107
|
+
expect(response.age).to eq(3)
|
107
108
|
end
|
108
109
|
|
109
|
-
it
|
110
|
+
it 'calculates the time from the "Date" header' do
|
110
111
|
date = 3.seconds.ago.httpdate
|
111
|
-
response = Faraday::HttpCache::Response.new(:
|
112
|
-
response.age.
|
112
|
+
response = Faraday::HttpCache::Response.new(response_headers: { 'Date' => date })
|
113
|
+
expect(response.age).to eq(3)
|
113
114
|
end
|
114
115
|
|
115
|
-
it
|
116
|
-
response = Faraday::HttpCache::Response.new(:
|
117
|
-
response.age.
|
116
|
+
it 'returns 0 if there is no "Age" or "Date" header present' do
|
117
|
+
response = Faraday::HttpCache::Response.new(response_headers: {})
|
118
|
+
expect(response.age).to eq(0)
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
121
|
-
describe
|
122
|
-
it
|
122
|
+
describe 'time to live calculation' do
|
123
|
+
it 'returns the time to live based on the max age limit' do
|
123
124
|
date = 200.seconds.ago.httpdate
|
124
|
-
headers = {
|
125
|
-
response = Faraday::HttpCache::Response.new(:
|
126
|
-
response.ttl.
|
125
|
+
headers = { 'Cache-Control' => 'max-age=400', 'Date' => date }
|
126
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
127
|
+
expect(response.ttl).to eq(200)
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
130
|
-
describe
|
131
|
-
subject { described_class.new(:
|
131
|
+
describe 'response unboxing' do
|
132
|
+
subject { described_class.new(status: 200, response_headers: {}, body: 'Hi!') }
|
132
133
|
|
133
|
-
let(:env) { { :
|
134
|
+
let(:env) { { method: :get } }
|
134
135
|
let(:response) { subject.to_response(env) }
|
135
136
|
|
136
|
-
it
|
137
|
-
response.env[:method].
|
137
|
+
it 'merges the supplied env object with the response data' do
|
138
|
+
expect(response.env[:method]).to be
|
138
139
|
end
|
139
140
|
|
140
|
-
it
|
141
|
-
response.
|
141
|
+
it 'returns a Faraday::Response' do
|
142
|
+
expect(response).to be_a(Faraday::Response)
|
142
143
|
end
|
143
144
|
|
144
|
-
it
|
145
|
-
response.status.
|
145
|
+
it 'merges the status code' do
|
146
|
+
expect(response.status).to eq(200)
|
146
147
|
end
|
147
148
|
|
148
|
-
it
|
149
|
-
response.headers.
|
149
|
+
it 'merges the headers' do
|
150
|
+
expect(response.headers).to be_a(Faraday::Utils::Headers)
|
150
151
|
end
|
151
152
|
|
152
|
-
it
|
153
|
-
response.body.
|
153
|
+
it 'merges the body' do
|
154
|
+
expect(response.body).to eq('Hi!')
|
154
155
|
end
|
155
156
|
end
|
156
157
|
|
@@ -163,13 +164,12 @@ describe Faraday::HttpCache::Response do
|
|
163
164
|
'Expires' => 37.seconds.from_now.httpdate,
|
164
165
|
'Last-Modified' => 300.seconds.ago.httpdate
|
165
166
|
}
|
166
|
-
response = Faraday::HttpCache::Response.new(:
|
167
|
-
response.
|
167
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
168
|
+
expect(response).to be_fresh
|
168
169
|
|
169
170
|
response.serializable_hash
|
170
|
-
response.max_age.
|
171
|
-
response.
|
171
|
+
expect(response.max_age).to eq(34)
|
172
|
+
expect(response).not_to be_fresh
|
172
173
|
end
|
173
174
|
end
|
174
|
-
|
175
175
|
end
|