2018-07-05 21:19:37 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative '../helper'
|
|
|
|
require 'quote/base'
|
|
|
|
|
|
|
|
module Quote
|
|
|
|
describe Base do
|
|
|
|
let(:klass) do
|
|
|
|
Class.new(Base)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:quote) do
|
|
|
|
klass.new(date: Date.today)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requires data' do
|
2020-05-02 18:08:47 +02:00
|
|
|
_ { quote.perform }.must_raise NotImplementedError
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not know how to format result' do
|
2020-05-02 18:08:47 +02:00
|
|
|
_ { quote.formatted }.must_raise NotImplementedError
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not know how to generate a cache key' do
|
2020-05-02 18:08:47 +02:00
|
|
|
_ { quote.cache_key }.must_raise NotImplementedError
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults base to Euro' do
|
2020-05-02 18:08:47 +02:00
|
|
|
_(quote.base).must_equal 'EUR'
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults amount to 1' do
|
2020-05-02 18:08:47 +02:00
|
|
|
_(quote.amount).must_equal 1
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when given data' do
|
2018-09-21 21:20:56 +02:00
|
|
|
before do
|
|
|
|
def quote.fetch_data
|
|
|
|
[]
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'performs' do
|
|
|
|
assert quote.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'performs only once' do
|
|
|
|
quote.perform
|
2023-02-28 17:49:48 +01:00
|
|
|
|
2018-07-05 21:19:37 +02:00
|
|
|
refute quote.perform
|
|
|
|
end
|
|
|
|
end
|
2018-09-21 21:20:56 +02:00
|
|
|
|
2019-05-02 21:36:35 +02:00
|
|
|
describe 'when rebasing from an unavailable currency' do
|
|
|
|
let(:date) do
|
|
|
|
Date.parse('2000-01-01')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:quote) do
|
2023-02-28 17:49:48 +01:00
|
|
|
klass.new(date:, base: 'ILS')
|
2019-05-02 21:36:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
def quote.fetch_data
|
2023-02-28 17:49:48 +01:00
|
|
|
[{ date:, iso_code: 'USD', rate: 1 }]
|
2019-05-02 21:36:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds nothing' do
|
|
|
|
quote.perform
|
2020-05-02 18:08:47 +02:00
|
|
|
_(quote.not_found?).must_equal true
|
2019-05-02 21:36:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-21 21:20:56 +02:00
|
|
|
describe 'when rebasing and converting to an unavailable currency' do
|
|
|
|
let(:date) do
|
|
|
|
Date.today
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:quote) do
|
2023-02-28 17:49:48 +01:00
|
|
|
klass.new(date:, base: 'USD', symbols: ['FOO'])
|
2018-09-21 21:20:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
def quote.fetch_data
|
2023-02-28 17:49:48 +01:00
|
|
|
[{ date:, iso_code: 'USD', rate: 1 }]
|
2018-09-21 21:20:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds nothing' do
|
|
|
|
quote.perform
|
2020-05-02 18:08:47 +02:00
|
|
|
_(quote.not_found?).must_equal true
|
2018-09-21 21:20:56 +02:00
|
|
|
end
|
|
|
|
end
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
end
|