2018-03-08 02:05:19 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative 'helper'
|
|
|
|
require 'currency'
|
|
|
|
|
|
|
|
describe Currency do
|
2018-10-03 15:48:30 +02:00
|
|
|
describe '.latest' do
|
|
|
|
it 'returns latest rates' do
|
|
|
|
data = Currency.latest.all
|
|
|
|
data.count.must_be :>, 1
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
2018-10-03 15:48:30 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
describe '.between' do
|
|
|
|
let(:day) do
|
|
|
|
Date.parse('2010-01-01')
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
it 'returns everything up to 90 days' do
|
|
|
|
interval = day..day + 90
|
|
|
|
Currency.between(interval).map(:date).uniq.count.must_be :>, 30
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
|
2020-04-01 12:21:32 +02:00
|
|
|
it 'samples weekly over 90 days' do
|
2018-10-03 15:48:30 +02:00
|
|
|
interval = day..day + 365
|
|
|
|
Currency.between(interval).map(:date).uniq.count.must_be :<=, 52
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
it 'sorts by date' do
|
|
|
|
interval = day..day + 100
|
|
|
|
dates = Currency.between(interval).map(:date)
|
|
|
|
dates.must_equal dates.sort
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-10-03 15:48:30 +02:00
|
|
|
end
|
2018-07-05 21:19:37 +02:00
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
describe '.only' do
|
|
|
|
it 'filters symbols' do
|
|
|
|
iso_codes = %w[CAD USD]
|
|
|
|
data = Currency.latest.only(*iso_codes).all
|
|
|
|
data.map(&:iso_code).sort.must_equal iso_codes
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
it 'returns nothing if no matches' do
|
|
|
|
Currency.only('FOO').all.must_be_empty
|
2018-07-05 21:19:37 +02:00
|
|
|
end
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
end
|