mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 11:02:30 +01:00
Handle malformed query
This commit is contained in:
parent
814087a602
commit
a73e9ddc7d
@ -26,7 +26,7 @@ helpers do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def halt_with_meaningful_response(status, message)
|
def halt_with_meaningful_response(status, message)
|
||||||
halt status, "#{message}. Please read http://fixer.io."
|
halt status, message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class Snapshot
|
|||||||
def rebase(rates)
|
def rebase(rates)
|
||||||
if base.upcase! != 'EUR'
|
if base.upcase! != 'EUR'
|
||||||
denominator = rates.update('EUR' => 1.0).delete(base)
|
denominator = rates.update('EUR' => 1.0).delete(base)
|
||||||
|
raise ArgumentError, 'Invalid base' unless denominator
|
||||||
|
|
||||||
rates.each do |iso_code, rate|
|
rates.each do |iso_code, rate|
|
||||||
rates[iso_code] = round(rate / denominator)
|
rates[iso_code] = round(rate / denominator)
|
||||||
|
@ -44,4 +44,9 @@ describe 'the API' do
|
|||||||
get '/'
|
get '/'
|
||||||
last_response.status.must_equal 404
|
last_response.status.must_equal 404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'handles malformed queries' do
|
||||||
|
get 'latest?base=USD?callback=?'
|
||||||
|
last_response.must_be :unprocessable?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user