mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 04:22:28 +01:00
cfbb4ac4ac
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
41 lines
1016 B
Ruby
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
|