Handle circular conversions (#51)

This commit is contained in:
Hakan Ensari 2024-11-21 14:45:44 +01:00
parent 9bd9e4dd95
commit 30cda9b048
No known key found for this signature in database
2 changed files with 12 additions and 1 deletions

View File

@ -1,9 +1,13 @@
# frozen_string_literal: true
# FIXME: Validations are all over. Clean up!
class Query
class << self
def build(params)
new(params).to_h
query = new(params).to_h
raise ArgumentError, "bad currency pair" if [query[:base]] == query[:symbols]
query
end
end

View File

@ -53,4 +53,11 @@ describe "the server" do
raise Sequel::Rollback
end
end
it "will not process circular conversions" do
get "/latest?from=EUR&to=EUR"
_(last_response).must_be(:unprocessable?)
get "/latest?from=USD&to=USD"
_(last_response).must_be(:unprocessable?)
end
end