From 5fbc1fb884fa80b5fe6362798db6eab696e39e1c Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Tue, 13 May 2025 20:33:04 +0200 Subject: [PATCH] Make sure geocoder errors are reported --- Gemfile | 1 - Gemfile.lock | 1 - spec/services/trips/countries_spec.rb | 12 +++++++++++ spec/support/geocoder_stubs.rb | 30 ++++++++++----------------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 1759ef3f..c8fa08c2 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,6 @@ gem 'rexml' gem 'rgeo' gem 'rgeo-activerecord' gem 'rgeo-geojson' -gem 'parallel' gem 'rswag-api' gem 'rswag-ui' gem 'sentry-ruby' diff --git a/Gemfile.lock b/Gemfile.lock index 284b3dba..523f8e9f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -506,7 +506,6 @@ DEPENDENCIES kaminari lograge oj - parallel pg prometheus_exporter pry-byebug diff --git a/spec/services/trips/countries_spec.rb b/spec/services/trips/countries_spec.rb index d2e4638a..6da3829c 100644 --- a/spec/services/trips/countries_spec.rb +++ b/spec/services/trips/countries_spec.rb @@ -80,5 +80,17 @@ RSpec.describe Trips::Countries do expect(result.keys.first).to eq('DE') expect(result['DE']).to eq(2) end + + context 'when an error occurs' do + before do + allow(Geocoder).to receive(:search).and_raise(Geocoder::Error, 'Error') + end + + it 'calls the exception reporter' do + expect(ExceptionReporter).to receive(:call).with(Geocoder::Error).at_least(3).times + + described_class.new(trip).call + end + end end end diff --git a/spec/support/geocoder_stubs.rb b/spec/support/geocoder_stubs.rb index 8e34dc2d..617b263d 100644 --- a/spec/support/geocoder_stubs.rb +++ b/spec/support/geocoder_stubs.rb @@ -4,27 +4,19 @@ RSpec.configure do |config| config.before(:each) do # Create a generic stub for all Geocoder requests - stub_request(:any, %r{photon\.dawarich\.app/reverse}).to_return( - status: 200, - body: { - type: 'FeatureCollection', - features: [ - { - type: 'Feature', - properties: { - name: 'Test Location', - countrycode: 'US', - country: 'United States', - state: 'New York' - }, - geometry: { - coordinates: [-73.9, 40.7], - type: 'Point' + allow(Geocoder).to receive(:search).and_return( + [ + double( + data: { + 'properties' => { + 'countrycode' => 'US', + 'country' => 'United States', + 'state' => 'New York', + 'name' => 'Test Location' } } - ] - }.to_json, - headers: { 'Content-Type' => 'application/json' } + ) + ] ) end end