frankfurter/spec/bank_spec.rb

68 lines
1.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require_relative 'helper'
require 'bank'
describe Bank do
around do |test|
Day.db.transaction do
2019-12-24 15:18:10 +01:00
Day.dataset.delete
test.call
raise Sequel::Rollback
end
end
before do
VCR.insert_cassette 'feed'
end
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
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
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
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
end
it 'replaces all rates' do
2019-12-24 15:18:10 +01:00
Bank.replace_all!
Day.count.must_be :>, 90
end
end