frankfurter/spec/bank_spec.rb

68 lines
1.3 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!
2020-05-02 18:08:47 +02: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!
2020-05-02 18:08:47 +02:00
_(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!
2020-05-02 18:08:47 +02: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!
2020-05-02 18:08:47 +02:00
_(Day.count).must_be :>, 90
2020-04-02 18:13:41 +02:00
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!
2020-05-02 18:08:47 +02: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!
2020-05-02 18:08:47 +02:00
_(Day.count).must_equal 1
2019-12-24 15:18:10 +01:00
end
it 'does not duplicate when fetching current rates' do
2.times { Bank.fetch_current! }
2020-05-02 18:08:47 +02:00
_(Day.count).must_equal 1
end
it 'replaces all rates' do
2019-12-24 15:18:10 +01:00
Bank.replace_all!
2020-05-02 18:08:47 +02:00
_(Day.count).must_be :>, 90
end
end