diff --git a/app/services/visits/place_finder.rb b/app/services/visits/place_finder.rb index e2f3a3ab..541e67a0 100644 --- a/app/services/visits/place_finder.rb +++ b/app/services/visits/place_finder.rb @@ -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 diff --git a/spec/services/visits/place_finder_spec.rb b/spec/services/visits/place_finder_spec.rb index 3da17828..e4158981 100644 --- a/spec/services/visits/place_finder_spec.rb +++ b/spec/services/visits/place_finder_spec.rb @@ -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)