mirror of
https://github.com/Freika/dawarich.git
synced 2025-12-30 17:59:42 -06:00
Fix PlaceFinder to only consider global places when finding existing places
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user