diff --git a/lib/api.rb b/lib/api.rb index 6303e48..f5ba937 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -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 diff --git a/lib/snapshot.rb b/lib/snapshot.rb index 42a4e3d..c1fb0a6 100644 --- a/lib/snapshot.rb +++ b/lib/snapshot.rb @@ -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) diff --git a/spec/api_spec.rb b/spec/api_spec.rb index a6de438..a111a2f 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -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