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-activerecord'
gem 'rgeo-geojson'
gem 'parallel'
gem 'rswag-api'
gem 'rswag-ui'
gem 'sentry-ruby'

View File

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

View File

@@ -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

View File

@@ -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