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