Handle interval where base is missing on older dates

This commit is contained in:
Hakan Ensari 2019-05-02 20:36:35 +01:00
parent 5057365be9
commit f62426797d
5 changed files with 28 additions and 6 deletions

View File

@ -12,7 +12,7 @@ Metrics/BlockLength:
ExcludedMethods: ['dataset_module', 'describe', 'helpers']
Metrics/AbcSize:
Max: 20.62
Max: 21.79
Metrics/MethodLength:
Max: 13

View File

@ -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

View File

@ -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

View File

@ -6,6 +6,7 @@ require_relative '../config/environment'
require 'minitest/autorun'
require 'minitest/around/spec'
require 'minitest/focus'
require 'vcr'
require 'webmock'

View File

@ -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