Handle malformed query

This commit is contained in:
Hakan Ensari 2014-05-13 03:08:33 +01:00
parent 814087a602
commit a73e9ddc7d
3 changed files with 7 additions and 1 deletions

View File

@ -26,7 +26,7 @@ helpers do
end
def halt_with_meaningful_response(status, message)
halt status, "#{message}. Please read http://fixer.io."
halt status, message
end
end

View File

@ -28,6 +28,7 @@ class Snapshot
def rebase(rates)
if base.upcase! != 'EUR'
denominator = rates.update('EUR' => 1.0).delete(base)
raise ArgumentError, 'Invalid base' unless denominator
rates.each do |iso_code, rate|
rates[iso_code] = round(rate / denominator)

View File

@ -44,4 +44,9 @@ describe 'the API' do
get '/'
last_response.status.must_equal 404
end
it 'handles malformed queries' do
get 'latest?base=USD?callback=?'
last_response.must_be :unprocessable?
end
end