diff --git a/.rubocop.yml b/.rubocop.yml index 32e8cb5..4ae6173 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,7 +12,7 @@ Metrics/BlockLength: ExcludedMethods: ['dataset_module', 'describe', 'helpers'] Metrics/AbcSize: - Max: 20.62 + Max: 21.79 Metrics/MethodLength: Max: 13 diff --git a/lib/quote/base.rb b/lib/quote/base.rb index d178369..83a0ca1 100644 --- a/lib/quote/base.rb +++ b/lib/quote/base.rb @@ -66,7 +66,7 @@ module Quote result.each do |date, rates| rates['EUR'] = amount if symbols.nil? || symbols.include?('EUR') divisor = rates.delete(base) - if rates.empty? + if divisor.nil? || rates.empty? result.delete(date) else result[date] = rates.sort diff --git a/spec/edge_cases_spec.rb b/spec/edge_cases_spec.rb index 4962ea8..88e147e 100644 --- a/spec/edge_cases_spec.rb +++ b/spec/edge_cases_spec.rb @@ -28,14 +28,14 @@ describe 'the server' do last_response.must_be :not_found? end - it 'will not process an invalid base' do + it 'will not process an unavailable base' do get '/latest?base=UAH' - last_response.must_be :unprocessable? + last_response.must_be :not_found? end it 'handles malformed queries' do get '/latest?base=USD?callback=?' - last_response.must_be :unprocessable? + last_response.must_be :not_found? end it 'does not return stale dates' do diff --git a/spec/helper.rb b/spec/helper.rb index 10aa3f2..79b4d83 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -6,6 +6,7 @@ require_relative '../config/environment' require 'minitest/autorun' require 'minitest/around/spec' +require 'minitest/focus' require 'vcr' require 'webmock' diff --git a/spec/quote/base_spec.rb b/spec/quote/base_spec.rb index 039b1d2..708701e 100644 --- a/spec/quote/base_spec.rb +++ b/spec/quote/base_spec.rb @@ -50,6 +50,27 @@ module Quote end end + describe 'when rebasing from an unavailable currency' do + let(:date) do + Date.parse('2000-01-01') + end + + let(:quote) do + klass.new(date: date, base: 'ILS') + end + + before do + def quote.fetch_data + [{ date: date, iso_code: 'USD', rate: 1 }] + end + end + + it 'finds nothing' do + quote.perform + quote.not_found?.must_equal true + end + end + describe 'when rebasing and converting to an unavailable currency' do let(:date) do Date.today @@ -61,7 +82,7 @@ module Quote before do def quote.fetch_data - [{ date: date, iso_code: 'USD', rate: 1.2 }] + [{ date: date, iso_code: 'USD', rate: 1 }] end end