From 30cda9b048834419e2a98ede312703c459dcbab5 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Thu, 21 Nov 2024 14:45:44 +0100 Subject: [PATCH] Handle circular conversions (#51) --- lib/query.rb | 6 +++++- spec/edge_cases_spec.rb | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/query.rb b/lib/query.rb index 7f85bc7..c04bb4d 100644 --- a/lib/query.rb +++ b/lib/query.rb @@ -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 diff --git a/spec/edge_cases_spec.rb b/spec/edge_cases_spec.rb index f2492bf..b60e4da 100644 --- a/spec/edge_cases_spec.rb +++ b/spec/edge_cases_spec.rb @@ -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