mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 02:52:49 +01:00
Improve specs
This commit is contained in:
parent
fb4c0d3755
commit
af17d699dd
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user