Revert custom error

This commit is contained in:
Hakan Ensari 2015-09-02 22:11:57 +01:00
parent cfa705764c
commit ddc0439340
3 changed files with 5 additions and 9 deletions

View File

@ -57,6 +57,6 @@ not_found do
halt_with_message 404, 'Not found'
end
error Quote::Invalid do
error ArgumentError do
halt_with_message 422, env['sinatra.error'].message.capitalize
end

View File

@ -4,8 +4,6 @@ require 'currency'
class Quote
include Virtus.value_object
NotValid = Class.new(ArgumentError)
DEFAULT_BASE = 'EUR'
values do
@ -32,7 +30,7 @@ class Quote
def date=(date)
current_date = Currency.current_date_before(date)
fail NotValid, 'Date too old' unless current_date
fail ArgumentError, 'Date too old' unless current_date
super current_date
end
@ -54,7 +52,7 @@ class Quote
def find_rebased_rates
rates = find_default_rates
denominator = rates.update(DEFAULT_BASE => 1.0).delete(base)
fail NotValid, 'Invalid base' unless denominator
fail ArgumentError, 'Invalid base' unless denominator
rates.each do |iso_code, rate|
rates[iso_code] = round_rate(rate / denominator)
end

View File

@ -54,9 +54,7 @@ describe Quote do
let(:quote) { Quote.new(base: 'FOO') }
it 'fails' do
stub_rates 'USD' => 1.25 do |quote|
proc { quote.to_h }.must_raise Quote::NotValid
end
proc { quote.to_h }.must_raise ArgumentError
end
end
@ -65,7 +63,7 @@ describe Quote do
it 'fails' do
Currency.stub :current_date_before, nil do
proc { quote }.must_raise Quote::NotValid
proc { quote }.must_raise ArgumentError
end
end
end