mirror of
https://github.com/ditkrg/idempotent-request.git
synced 2026-01-22 22:06:44 +00:00
Merge pull request #1 from gomayonqui/cache-succesful-response
Add caching for successful responses
This commit is contained in:
commit
30ee089ffd
@ -19,11 +19,8 @@ module IdempotentRequest
|
||||
def write(*data)
|
||||
status, headers, response = data
|
||||
response = response.body if response.respond_to?(:body)
|
||||
|
||||
return data unless status == 200
|
||||
|
||||
return data unless (200..226).include?(status)
|
||||
storage.write(key, payload(status, headers, response))
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
|
||||
@ -81,6 +81,7 @@ RSpec.describe IdempotentRequest::RequestManager do
|
||||
})
|
||||
end
|
||||
|
||||
describe 'when status 2xx' do
|
||||
context 'when status is 200' do
|
||||
let(:data) do
|
||||
[200, {}, 'body']
|
||||
@ -92,12 +93,24 @@ RSpec.describe IdempotentRequest::RequestManager do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status is 226' do
|
||||
let(:data) do
|
||||
[226, {}, 'body']
|
||||
end
|
||||
|
||||
it 'should be stored' do
|
||||
request_storage.write(*data)
|
||||
expect(memory_storage.read(request.key)).to eq(payload)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status is not 200' do
|
||||
let(:data) do
|
||||
[404, {}, 'body']
|
||||
end
|
||||
|
||||
it 'should be stored' do
|
||||
it 'should not be stored' do
|
||||
request_storage.write(*data)
|
||||
expect(memory_storage.read(request.key)).to be_nil
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user