2017-12-31 17:44:08 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative 'helper'
|
|
|
|
require 'bank'
|
|
|
|
|
|
|
|
describe Bank do
|
|
|
|
around do |test|
|
2018-10-03 15:48:30 +02:00
|
|
|
Day.db.transaction do
|
2019-12-24 15:18:10 +01:00
|
|
|
Day.dataset.delete
|
2017-12-31 17:44:08 +01:00
|
|
|
test.call
|
|
|
|
raise Sequel::Rollback
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-03-08 02:05:19 +01:00
|
|
|
VCR.insert_cassette 'feed'
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|
|
|
|
|
2018-03-08 02:05:19 +01:00
|
|
|
after do
|
|
|
|
VCR.eject_cassette
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches all rates' do
|
2018-06-06 17:30:18 +02:00
|
|
|
Bank.fetch_all!
|
2019-12-24 15:18:10 +01:00
|
|
|
Day.count.must_be :>, 90
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2019-12-24 15:18:10 +01:00
|
|
|
it 'does not duplicate when fetching all rates' do
|
2018-06-06 17:30:18 +02:00
|
|
|
Bank.fetch_all!
|
2019-12-24 15:18:10 +01:00
|
|
|
count = Day.count
|
|
|
|
Bank.fetch_all!
|
|
|
|
Day.count.must_equal count
|
2018-03-22 09:49:32 +01:00
|
|
|
end
|
|
|
|
|
2018-06-06 17:30:18 +02:00
|
|
|
it 'fetches rates for last 90 days' do
|
|
|
|
Bank.fetch_ninety_days!
|
2019-12-24 15:18:10 +01:00
|
|
|
Day.count.must_be :>, 1
|
|
|
|
Day.count.must_be :<, 90
|
2018-06-06 17:30:18 +02:00
|
|
|
end
|
|
|
|
|
2020-04-02 18:13:41 +02:00
|
|
|
it 'seeds rates with saved data' do
|
|
|
|
Bank.seed_with_saved_data!
|
|
|
|
Day.count.must_be :>, 90
|
|
|
|
end
|
|
|
|
|
2019-12-24 15:18:10 +01:00
|
|
|
it 'does not duplicate when fetching rates for last 90 days' do
|
|
|
|
Bank.fetch_ninety_days!
|
|
|
|
count = Day.count
|
2018-06-06 17:30:18 +02:00
|
|
|
Bank.fetch_ninety_days!
|
2019-12-24 15:18:10 +01:00
|
|
|
Day.count.must_equal count
|
2018-06-06 17:30:18 +02:00
|
|
|
end
|
|
|
|
|
2017-12-31 17:44:08 +01:00
|
|
|
it 'fetches current rates' do
|
2018-06-06 17:30:18 +02:00
|
|
|
Bank.fetch_current!
|
2019-12-24 15:18:10 +01:00
|
|
|
Day.count.must_equal 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not duplicate when fetching current rates' do
|
|
|
|
2.times { Bank.fetch_current! }
|
|
|
|
Day.count.must_equal 1
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|
2018-03-22 09:49:32 +01:00
|
|
|
|
|
|
|
it 'replaces all rates' do
|
2019-12-24 15:18:10 +01:00
|
|
|
Bank.replace_all!
|
|
|
|
Day.count.must_be :>, 90
|
2018-03-22 09:49:32 +01:00
|
|
|
end
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|