2017-12-31 17:44:08 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
require_relative "helper"
|
|
|
|
require "bank"
|
2017-12-31 17:44:08 +01:00
|
|
|
|
|
|
|
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
|
2024-11-19 20:06:47 +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
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "fetches all rates" do
|
2018-06-06 17:30:18 +02:00
|
|
|
Bank.fetch_all!
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Day.count).must_be(:>, 90)
|
2018-03-08 02:05:19 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +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!
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Day.count).must_equal(count)
|
2018-03-22 09:49:32 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "fetches rates for last 90 days" do
|
2018-06-06 17:30:18 +02:00
|
|
|
Bank.fetch_ninety_days!
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Day.count).must_be(:>, 1)
|
|
|
|
_(Day.count).must_be(:<, 90)
|
2018-06-06 17:30:18 +02:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "seeds rates with saved data" do
|
2020-04-02 18:13:41 +02:00
|
|
|
Bank.seed_with_saved_data!
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Day.count).must_be(:>, 90)
|
2020-04-02 18:13:41 +02:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
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!
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Day.count).must_equal(count)
|
2018-06-06 17:30:18 +02:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "fetches current rates" do
|
2018-06-06 17:30:18 +02:00
|
|
|
Bank.fetch_current!
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Day.count).must_equal(1)
|
2019-12-24 15:18:10 +01:00
|
|
|
end
|
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "does not duplicate when fetching current rates" do
|
2019-12-24 15:18:10 +01:00
|
|
|
2.times { Bank.fetch_current! }
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Day.count).must_equal(1)
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|
2018-03-22 09:49:32 +01:00
|
|
|
|
2024-11-19 20:06:47 +01:00
|
|
|
it "replaces all rates" do
|
2019-12-24 15:18:10 +01:00
|
|
|
Bank.replace_all!
|
2024-11-19 20:06:47 +01:00
|
|
|
_(Day.count).must_be(:>, 90)
|
2018-03-22 09:49:32 +01:00
|
|
|
end
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|