Improve specs

This commit is contained in:
Hakan Ensari 2019-12-24 14:18:10 +00:00
parent fb4c0d3755
commit af17d699dd
2 changed files with 26 additions and 17 deletions

View File

@ -6,6 +6,7 @@ require 'bank'
describe Bank do
around do |test|
Day.db.transaction do
Day.dataset.delete
test.call
raise Sequel::Rollback
end
@ -20,39 +21,42 @@ describe Bank do
end
it 'fetches all rates' do
Day.dataset.delete
Bank.fetch_all!
Day.count.must_be :positive?
Day.count.must_be :>, 90
end
it 'skips existing records when fetching all rates' do
Day.where { date < '2012-01-01' }.delete
it 'does not duplicate when fetching all rates' do
Bank.fetch_all!
Day.where { date < '2012-01-01' }.count.must_be :positive?
count = Day.count
Bank.fetch_all!
Day.count.must_equal count
end
it 'fetches rates for last 90 days' do
Day.dataset.delete
Bank.fetch_ninety_days!
Day.count.must_be :positive?
Day.count.must_be :>, 1
Day.count.must_be :<, 90
end
it 'skips existing records when fetching rates for last 90 days' do
cutoff = Date.today - 60
Day.where { date < cutoff }.delete
it 'does not duplicate when fetching rates for last 90 days' do
Bank.fetch_ninety_days!
Day.where { date < cutoff }.count.must_be :positive?
count = Day.count
Bank.fetch_ninety_days!
Day.count.must_equal count
end
it 'fetches current rates' do
Day.dataset.delete
Bank.fetch_current!
Day.count.must_be :positive?
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
Day.dataset.delete
Bank.fetch_all!
Day.count.must_be :positive?
Bank.replace_all!
Day.count.must_be :>, 90
end
end

View File

@ -11,7 +11,7 @@ describe 'the server' do
let(:json) { Oj.load(last_response.body) }
let(:headers) { last_response.headers }
it 'redirects to www' do
it 'redirects root to documentation site' do
get '/'
last_response.must_be :redirect?
end
@ -97,4 +97,9 @@ describe 'the server' do
get '/currencies'
json['USD'].must_equal 'United States Dollar'
end
it 'handles JSONP' do
get '/latest?callback=foo'
last_response.body.must_be :start_with?, 'foo'
end
end