mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 11:02:30 +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']
|
ExcludedMethods: ['dataset_module', 'describe', 'helpers']
|
||||||
|
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 20.62
|
Max: 21.79
|
||||||
|
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Max: 13
|
Max: 13
|
||||||
|
@ -66,7 +66,7 @@ module Quote
|
|||||||
result.each do |date, rates|
|
result.each do |date, rates|
|
||||||
rates['EUR'] = amount if symbols.nil? || symbols.include?('EUR')
|
rates['EUR'] = amount if symbols.nil? || symbols.include?('EUR')
|
||||||
divisor = rates.delete(base)
|
divisor = rates.delete(base)
|
||||||
if rates.empty?
|
if divisor.nil? || rates.empty?
|
||||||
result.delete(date)
|
result.delete(date)
|
||||||
else
|
else
|
||||||
result[date] = rates.sort
|
result[date] = rates.sort
|
||||||
|
@ -28,14 +28,14 @@ describe 'the server' do
|
|||||||
last_response.must_be :not_found?
|
last_response.must_be :not_found?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not process an invalid base' do
|
it 'will not process an unavailable base' do
|
||||||
get '/latest?base=UAH'
|
get '/latest?base=UAH'
|
||||||
last_response.must_be :unprocessable?
|
last_response.must_be :not_found?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles malformed queries' do
|
it 'handles malformed queries' do
|
||||||
get '/latest?base=USD?callback=?'
|
get '/latest?base=USD?callback=?'
|
||||||
last_response.must_be :unprocessable?
|
last_response.must_be :not_found?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not return stale dates' do
|
it 'does not return stale dates' do
|
||||||
|
@ -6,6 +6,7 @@ require_relative '../config/environment'
|
|||||||
|
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
require 'minitest/around/spec'
|
require 'minitest/around/spec'
|
||||||
|
require 'minitest/focus'
|
||||||
require 'vcr'
|
require 'vcr'
|
||||||
require 'webmock'
|
require 'webmock'
|
||||||
|
|
||||||
|
@ -50,6 +50,27 @@ module Quote
|
|||||||
end
|
end
|
||||||
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
|
describe 'when rebasing and converting to an unavailable currency' do
|
||||||
let(:date) do
|
let(:date) do
|
||||||
Date.today
|
Date.today
|
||||||
@ -61,7 +82,7 @@ module Quote
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
def quote.fetch_data
|
def quote.fetch_data
|
||||||
[{ date: date, iso_code: 'USD', rate: 1.2 }]
|
[{ date: date, iso_code: 'USD', rate: 1 }]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user