Fix PlaceFinder to only consider global places when finding existing places

This commit is contained in:
Eugene Burmakin
2025-11-22 18:32:26 +01:00
parent 02cbf65781
commit b18fc392cc
2 changed files with 5 additions and 3 deletions

View File

@@ -47,7 +47,7 @@ module Visits
# Step 1: Find existing place
def find_existing_place(lat, lon, name)
# Try to find existing place by location first
existing_by_location = Place.near([lat, lon], SIMILARITY_RADIUS, :m).first
existing_by_location = Place.where(user_id: nil).near([lat, lon], SIMILARITY_RADIUS, :m).first
return existing_by_location if existing_by_location
# Then try by name if available

View File

@@ -20,7 +20,7 @@ RSpec.describe Visits::PlaceFinder do
end
context 'when an existing place is found' do
let!(:existing_place) { create(:place, latitude: latitude, longitude: longitude) }
let!(:existing_place) { create(:place, latitude: latitude, longitude: longitude, lonlat: "POINT(#{longitude} #{latitude})") }
it 'returns the existing place as main_place' do
result = subject.find_or_create_place(visit_data)
@@ -40,7 +40,9 @@ RSpec.describe Visits::PlaceFinder do
similar_named_place = create(:place,
name: 'Test Place',
latitude: latitude + 0.0001,
longitude: longitude + 0.0001)
longitude: longitude + 0.0001,
lonlat: "POINT(#{longitude + 0.0001} #{latitude + 0.0001})"
)
allow(subject).to receive(:find_existing_place).and_return(similar_named_place)