Make sure geocoder errors are reported

This commit is contained in:
Eugene Burmakin 2025-05-13 20:33:04 +02:00
parent 556af7fd02
commit 5fbc1fb884
4 changed files with 23 additions and 21 deletions

View file

@ -31,7 +31,6 @@ gem 'rexml'
gem 'rgeo' gem 'rgeo'
gem 'rgeo-activerecord' gem 'rgeo-activerecord'
gem 'rgeo-geojson' gem 'rgeo-geojson'
gem 'parallel'
gem 'rswag-api' gem 'rswag-api'
gem 'rswag-ui' gem 'rswag-ui'
gem 'sentry-ruby' gem 'sentry-ruby'

View file

@ -506,7 +506,6 @@ DEPENDENCIES
kaminari kaminari
lograge lograge
oj oj
parallel
pg pg
prometheus_exporter prometheus_exporter
pry-byebug pry-byebug

View file

@ -80,5 +80,17 @@ RSpec.describe Trips::Countries do
expect(result.keys.first).to eq('DE') expect(result.keys.first).to eq('DE')
expect(result['DE']).to eq(2) expect(result['DE']).to eq(2)
end 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
end end

View file

@ -4,27 +4,19 @@
RSpec.configure do |config| RSpec.configure do |config|
config.before(:each) do config.before(:each) do
# Create a generic stub for all Geocoder requests # Create a generic stub for all Geocoder requests
stub_request(:any, %r{photon\.dawarich\.app/reverse}).to_return( allow(Geocoder).to receive(:search).and_return(
status: 200, [
body: { double(
type: 'FeatureCollection', data: {
features: [ 'properties' => {
{ 'countrycode' => 'US',
type: 'Feature', 'country' => 'United States',
properties: { 'state' => 'New York',
name: 'Test Location', 'name' => 'Test Location'
countrycode: 'US',
country: 'United States',
state: 'New York'
},
geometry: {
coordinates: [-73.9, 40.7],
type: 'Point'
} }
} }
] )
}.to_json, ]
headers: { 'Content-Type' => 'application/json' }
) )
end end
end end