frankfurter/spec/currency_spec.rb

49 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require_relative 'helper'
require 'currency'
2020-05-02 18:08:47 +02:00
require 'minitest/autorun'
describe Currency do
describe '.latest' do
it 'returns latest rates' do
data = Currency.latest.all
2020-05-02 18:08:47 +02:00
_(data.count).must_be :>, 1
end
end
describe '.between' do
let(:day) do
Date.parse('2010-01-01')
end
2020-05-02 16:18:52 +02:00
it 'returns everything up to a year' do
interval = day..day + 365
2020-05-02 18:08:47 +02:00
_(Currency.between(interval).map(:date).uniq.count).must_be :>, 52
end
2020-05-02 16:18:52 +02:00
it 'samples weekly over a year' do
interval = day..day + 366
2020-05-02 18:08:47 +02:00
_(Currency.between(interval).map(:date).uniq.count).must_be :<, 54
end
2020-05-02 19:34:38 +02:00
it 'sorts by date when sampling' do
interval = day..day + 366
dates = Currency.between(interval).map(:date)
2020-05-02 18:08:47 +02:00
_(dates).must_equal dates.sort
end
end
describe '.only' do
it 'filters symbols' do
iso_codes = %w[CAD USD]
data = Currency.latest.only(*iso_codes).all
2020-05-02 18:08:47 +02:00
_(data.map(&:iso_code).sort).must_equal iso_codes
end
it 'returns nothing if no matches' do
2020-05-02 18:08:47 +02:00
_(Currency.only('FOO').all).must_be_empty
end
end
end