mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 19:12:32 +01:00
68 lines
1.2 KiB
Ruby
68 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative 'helper'
|
|
require 'bank'
|
|
|
|
describe Bank do
|
|
around do |test|
|
|
Day.db.transaction do
|
|
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
|
|
Bank.fetch_all!
|
|
Day.count.must_be :>, 90
|
|
end
|
|
|
|
it 'does not duplicate when fetching all rates' do
|
|
Bank.fetch_all!
|
|
count = Day.count
|
|
Bank.fetch_all!
|
|
Day.count.must_equal count
|
|
end
|
|
|
|
it 'fetches rates for last 90 days' do
|
|
Bank.fetch_ninety_days!
|
|
Day.count.must_be :>, 1
|
|
Day.count.must_be :<, 90
|
|
end
|
|
|
|
it 'seeds rates with saved data' do
|
|
Bank.seed_with_saved_data!
|
|
Day.count.must_be :>, 90
|
|
end
|
|
|
|
it 'does not duplicate when fetching rates for last 90 days' do
|
|
Bank.fetch_ninety_days!
|
|
count = Day.count
|
|
Bank.fetch_ninety_days!
|
|
Day.count.must_equal count
|
|
end
|
|
|
|
it 'fetches current rates' do
|
|
Bank.fetch_current!
|
|
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
|
|
Bank.replace_all!
|
|
Day.count.must_be :>, 90
|
|
end
|
|
end
|