mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-21 18:42:29 +01:00
Handle interval where base is missing on older dates
This commit is contained in:
parent
5057365be9
commit
f62426797d
@ -12,7 +12,7 @@ Metrics/BlockLength:
|
||||
ExcludedMethods: ['dataset_module', 'describe', 'helpers']
|
||||
|
||||
Metrics/AbcSize:
|
||||
Max: 20.62
|
||||
Max: 21.79
|
||||
|
||||
Metrics/MethodLength:
|
||||
Max: 13
|
||||
|
@ -66,7 +66,7 @@ module Quote
|
||||
result.each do |date, rates|
|
||||
rates['EUR'] = amount if symbols.nil? || symbols.include?('EUR')
|
||||
divisor = rates.delete(base)
|
||||
if rates.empty?
|
||||
if divisor.nil? || rates.empty?
|
||||
result.delete(date)
|
||||
else
|
||||
result[date] = rates.sort
|
||||
|
@ -28,14 +28,14 @@ describe 'the server' do
|
||||
last_response.must_be :not_found?
|
||||
end
|
||||
|
||||
it 'will not process an invalid base' do
|
||||
it 'will not process an unavailable base' do
|
||||
get '/latest?base=UAH'
|
||||
last_response.must_be :unprocessable?
|
||||
last_response.must_be :not_found?
|
||||
end
|
||||
|
||||
it 'handles malformed queries' do
|
||||
get '/latest?base=USD?callback=?'
|
||||
last_response.must_be :unprocessable?
|
||||
last_response.must_be :not_found?
|
||||
end
|
||||
|
||||
it 'does not return stale dates' do
|
||||
|
@ -6,6 +6,7 @@ require_relative '../config/environment'
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/around/spec'
|
||||
require 'minitest/focus'
|
||||
require 'vcr'
|
||||
require 'webmock'
|
||||
|
||||
|
@ -50,6 +50,27 @@ module Quote
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when rebasing from an unavailable currency' do
|
||||
let(:date) do
|
||||
Date.parse('2000-01-01')
|
||||
end
|
||||
|
||||
let(:quote) do
|
||||
klass.new(date: date, base: 'ILS')
|
||||
end
|
||||
|
||||
before do
|
||||
def quote.fetch_data
|
||||
[{ date: date, iso_code: 'USD', rate: 1 }]
|
||||
end
|
||||
end
|
||||
|
||||
it 'finds nothing' do
|
||||
quote.perform
|
||||
quote.not_found?.must_equal true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when rebasing and converting to an unavailable currency' do
|
||||
let(:date) do
|
||||
Date.today
|
||||
@ -61,7 +82,7 @@ module Quote
|
||||
|
||||
before do
|
||||
def quote.fetch_data
|
||||
[{ date: date, iso_code: 'USD', rate: 1.2 }]
|
||||
[{ date: date, iso_code: 'USD', rate: 1 }]
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user