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!
_(Day.count).must_be(:>, 90)
end
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
it "fetches rates for last 90 days" do
2018-06-06 17:30:18 +02:00
Bank.fetch_ninety_days!
_(Day.count).must_be(:>, 1)
_(Day.count).must_be(:<, 90)
2018-06-06 17:30:18 +02:00
end
it "seeds rates with saved data" do
2020-04-02 18:13:41 +02:00
Bank.seed_with_saved_data!
_(Day.count).must_be(:>, 90)
2020-04-02 18:13:41 +02:00
end
it "does not duplicate when fetching rates for last 90 days" do
2019-12-24 15:18:10 +01:00
Bank.fetch_ninety_days!
count = Day.count
2018-06-06 17:30:18 +02:00
Bank.fetch_ninety_days!
_(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!
_(Day.count).must_equal(1)
2019-12-24 15:18:10 +01:00
end
it "does not duplicate when fetching current rates" do
2019-12-24 15:18:10 +01:00
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