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
|
describe Bank do
|
||||||
around do |test|
|
around do |test|
|
||||||
Day.db.transaction do
|
Day.db.transaction do
|
||||||
|
Day.dataset.delete
|
||||||
test.call
|
test.call
|
||||||
raise Sequel::Rollback
|
raise Sequel::Rollback
|
||||||
end
|
end
|
||||||
@ -20,39 +21,42 @@ describe Bank do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'fetches all rates' do
|
it 'fetches all rates' do
|
||||||
Day.dataset.delete
|
|
||||||
Bank.fetch_all!
|
Bank.fetch_all!
|
||||||
Day.count.must_be :positive?
|
Day.count.must_be :>, 90
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'skips existing records when fetching all rates' do
|
it 'does not duplicate when fetching all rates' do
|
||||||
Day.where { date < '2012-01-01' }.delete
|
|
||||||
Bank.fetch_all!
|
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
|
end
|
||||||
|
|
||||||
it 'fetches rates for last 90 days' do
|
it 'fetches rates for last 90 days' do
|
||||||
Day.dataset.delete
|
|
||||||
Bank.fetch_ninety_days!
|
Bank.fetch_ninety_days!
|
||||||
Day.count.must_be :positive?
|
Day.count.must_be :>, 1
|
||||||
|
Day.count.must_be :<, 90
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'skips existing records when fetching rates for last 90 days' do
|
it 'does not duplicate when fetching rates for last 90 days' do
|
||||||
cutoff = Date.today - 60
|
|
||||||
Day.where { date < cutoff }.delete
|
|
||||||
Bank.fetch_ninety_days!
|
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
|
end
|
||||||
|
|
||||||
it 'fetches current rates' do
|
it 'fetches current rates' do
|
||||||
Day.dataset.delete
|
|
||||||
Bank.fetch_current!
|
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
|
end
|
||||||
|
|
||||||
it 'replaces all rates' do
|
it 'replaces all rates' do
|
||||||
Day.dataset.delete
|
Bank.replace_all!
|
||||||
Bank.fetch_all!
|
Day.count.must_be :>, 90
|
||||||
Day.count.must_be :positive?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ describe 'the server' do
|
|||||||
let(:json) { Oj.load(last_response.body) }
|
let(:json) { Oj.load(last_response.body) }
|
||||||
let(:headers) { last_response.headers }
|
let(:headers) { last_response.headers }
|
||||||
|
|
||||||
it 'redirects to www' do
|
it 'redirects root to documentation site' do
|
||||||
get '/'
|
get '/'
|
||||||
last_response.must_be :redirect?
|
last_response.must_be :redirect?
|
||||||
end
|
end
|
||||||
@ -97,4 +97,9 @@ describe 'the server' do
|
|||||||
get '/currencies'
|
get '/currencies'
|
||||||
json['USD'].must_equal 'United States Dollar'
|
json['USD'].must_equal 'United States Dollar'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'handles JSONP' do
|
||||||
|
get '/latest?callback=foo'
|
||||||
|
last_response.body.must_be :start_with?, 'foo'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user