mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-21 18:42:29 +01:00
Handle non-positive amounts (#55)
This commit is contained in:
parent
0a88f09c73
commit
4a419d020f
@ -14,7 +14,10 @@ class Query
|
||||
def amount
|
||||
return unless @params[:amount]
|
||||
|
||||
@params[:amount].to_f
|
||||
value = @params[:amount].to_f
|
||||
raise ArgumentError, "invalid amount" unless value.positive?
|
||||
|
||||
value
|
||||
end
|
||||
|
||||
def base
|
||||
|
@ -23,6 +23,11 @@ describe "the server" do
|
||||
_(last_response).must_be(:unprocessable?)
|
||||
end
|
||||
|
||||
it "will not process an invalid amount" do
|
||||
get "/latest?amount=0&from=USD&to=EUR"
|
||||
_(last_response).must_be(:unprocessable?)
|
||||
end
|
||||
|
||||
it "will not process a date before 2000" do
|
||||
get "/1999-01-01"
|
||||
_(last_response).must_be(:not_found?)
|
||||
|
@ -13,6 +13,11 @@ describe Query do
|
||||
_(query.amount).must_equal(100.0)
|
||||
end
|
||||
|
||||
it "requires a positive amount" do
|
||||
_ { Query.new(amount: "0").to_h }.must_raise(ArgumentError)
|
||||
_ { Query.new(amount: "-1").to_h }.must_raise(ArgumentError)
|
||||
end
|
||||
|
||||
it "defaults amount to nothing" do
|
||||
query = Query.new
|
||||
_(query.amount).must_be_nil
|
||||
|
Loading…
Reference in New Issue
Block a user