frankfurter/spec/currency_spec.rb
Hakan Ensari cfbb4ac4ac Repack app
I'm moving my company's server to a private location now that I have sold the domain. While prepping for this, I've done some cleanup and also threw in changes I had lingering on my hard drive.

- Run a single database query instead of two
- Fold the gem into the app and use Ox instead of REXML
- Simplify error handling logic
- Relax throttling
2018-03-08 23:51:36 +00:00

41 lines
1016 B
Ruby

# frozen_string_literal: true
require_relative 'helper'
require 'currency'
describe Currency do
around do |test|
Currency.db.transaction do
test.call
raise Sequel::Rollback
end
end
before do
Currency.dataset.delete
@earlier = [
Currency.create(iso_code: 'EUR', rate: 1, date: '2014-01-01'),
Currency.create(iso_code: 'USD', rate: 2, date: '2014-01-01')
]
@later = [
Currency.create(iso_code: 'EUR', rate: 1, date: '2015-01-01'),
Currency.create(iso_code: 'USD', rate: 2, date: '2015-01-01')
]
end
it 'returns latest rates' do
data = Currency.latest.to_a
data.sample.date.must_equal @later.sample.date
end
it 'returns latest rates before given date' do
data = Currency.latest(@later.sample.date - 1).to_a
data.sample.date.must_equal @earlier.sample.date
end
it 'returns nothing if there are no rates before given date' do
data = Currency.latest(@earlier.sample.date - 1).to_a
data.must_be_empty
end
end