mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 11:02:30 +01:00
07781b6d76
Warming up -------------------------------------- json 16.465k i/100ms yajl 18.574k i/100ms oj 34.073k i/100ms Calculating ------------------------------------- json 182.828k (± 7.8%) i/s - 922.040k in 5.075699s yajl 196.839k (± 4.5%) i/s - 984.422k in 5.011087s oj 384.813k (± 5.9%) i/s - 1.942M in 5.065475s Comparison: oj: 384813.2 i/s yajl: 196839.0 i/s - 1.95x slower json: 182827.5 i/s - 2.10x slower
51 lines
1.1 KiB
Ruby
51 lines
1.1 KiB
Ruby
require_relative 'helper'
|
|
require 'rack/test'
|
|
require 'api'
|
|
|
|
describe 'the API' do
|
|
include Rack::Test::Methods
|
|
|
|
let(:app) { Sinatra::Application }
|
|
let(:json) { Oj.load(last_response.body) }
|
|
|
|
it 'handles unfound pages' do
|
|
get '/foo'
|
|
last_response.status.must_equal 404
|
|
json.wont_be_empty
|
|
end
|
|
|
|
it 'will not process an invalid date' do
|
|
get '/2010-31-01'
|
|
last_response.must_be :unprocessable?
|
|
json.wont_be_empty
|
|
end
|
|
|
|
it 'will not process a date before 2000' do
|
|
get '/1999-01-01'
|
|
last_response.must_be :unprocessable?
|
|
json.wont_be_empty
|
|
end
|
|
|
|
it 'will not process an invalid base' do
|
|
get '/latest?base=UAH'
|
|
last_response.must_be :unprocessable?
|
|
json.wont_be_empty
|
|
end
|
|
|
|
it 'handles malformed queries' do
|
|
get '/latest?base=USD?callback=?'
|
|
last_response.must_be :unprocessable?
|
|
json.wont_be_empty
|
|
end
|
|
|
|
it 'returns fresh dates' do
|
|
Currency.db.transaction do
|
|
new_date = Currency.current_date + 1
|
|
Currency.create(date: new_date, iso_code: 'FOO', rate: 1)
|
|
get '/latest'
|
|
json['date'].must_equal new_date.to_s
|
|
raise Sequel::Rollback
|
|
end
|
|
end
|
|
end
|