Fix some specs

This commit is contained in:
Eugene Burmakin
2025-11-22 18:27:54 +01:00
parent 1e2c709047
commit 02cbf65781
4 changed files with 12 additions and 11 deletions

View File

@@ -70,9 +70,9 @@ module Api
end
def tag_ids
ids = params.dig(:place, :tag_ids)
Array(ids).compact
end
ids = params.dig(:place, :tag_ids)
Array(ids).compact
end
def add_tags
return if tag_ids.empty?

View File

@@ -15,7 +15,7 @@ class ReverseGeocoding::Places::FetchData
return
end
places = reverse_geocoded_places
places = geocoder_places
first_place = places.shift
update_place(first_place)
@@ -82,6 +82,7 @@ class ReverseGeocoding::Places::FetchData
def find_existing_places(osm_ids)
Place.where("geodata->'properties'->>'osm_id' IN (?)", osm_ids)
.where(user_id: nil)
.index_by { |p| p.geodata.dig('properties', 'osm_id').to_s }
.compact
end
@@ -145,7 +146,7 @@ class ReverseGeocoding::Places::FetchData
"POINT(#{coordinates[0]} #{coordinates[1]})"
end
def reverse_geocoded_places
def geocoder_places
data = Geocoder.search(
[place.lat, place.lon],
limit: 10,

View File

@@ -6,7 +6,7 @@ FactoryBot.define do
latitude { 54.2905245 }
longitude { 13.0948638 }
# lonlat is auto-generated by before_validation callback in Place model
association :user
# association :user
trait :with_geodata do
geodata do

View File

@@ -98,7 +98,7 @@ RSpec.describe ReverseGeocoding::Places::FetchData do
it 'updates the original place and creates others' do
service.call
created_place = Place.where.not(id: place.id).first
created_place = Place.where(user_id: nil).where.not(id: place.id).first
expect(created_place.name).to include('Second Place')
expect(created_place.city).to eq('Hamburg')
end
@@ -584,15 +584,15 @@ RSpec.describe ReverseGeocoding::Places::FetchData do
place # Force place creation
expect { service.call }.to change { Place.count }.by(1)
created_place = Place.where.not(id: place.id).first
created_place = Place.where(user_id: nil).where.not(id: place.id).first
expect(created_place.latitude).to eq(54.0)
expect(created_place.longitude).to eq(13.0)
end
end
context 'when lonlat is already present on existing place' do
let!(:existing_place) { create(:place, :with_geodata, lonlat: 'POINT(10.0 50.0)') }
let(:existing_data) do
let!(:existing_place) { create(:place, :with_geodata, lonlat: 'POINT(10.0 50.0)', latitude: 50.0, longitude: 10.0) }
let(:mock_data) do
double(
data: {
'geometry' => { 'coordinates' => [15.0, 55.0] },
@@ -605,7 +605,7 @@ RSpec.describe ReverseGeocoding::Places::FetchData do
end
before do
allow(Geocoder).to receive(:search).and_return([mock_geocoded_place, existing_data])
allow(Geocoder).to receive(:search).and_return([mock_geocoded_place, mock_data])
end
it 'does not override existing coordinates when updating geodata' do