mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Fix PlaceFinder to only consider global places when finding existing places
This commit is contained in:
parent
02cbf65781
commit
b18fc392cc
2 changed files with 5 additions and 3 deletions
|
|
@ -47,7 +47,7 @@ module Visits
|
||||||
# Step 1: Find existing place
|
# Step 1: Find existing place
|
||||||
def find_existing_place(lat, lon, name)
|
def find_existing_place(lat, lon, name)
|
||||||
# Try to find existing place by location first
|
# 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
|
return existing_by_location if existing_by_location
|
||||||
|
|
||||||
# Then try by name if available
|
# Then try by name if available
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ RSpec.describe Visits::PlaceFinder do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when an existing place is found' do
|
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
|
it 'returns the existing place as main_place' do
|
||||||
result = subject.find_or_create_place(visit_data)
|
result = subject.find_or_create_place(visit_data)
|
||||||
|
|
@ -40,7 +40,9 @@ RSpec.describe Visits::PlaceFinder do
|
||||||
similar_named_place = create(:place,
|
similar_named_place = create(:place,
|
||||||
name: 'Test Place',
|
name: 'Test Place',
|
||||||
latitude: latitude + 0.0001,
|
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)
|
allow(subject).to receive(:find_existing_place).and_return(similar_named_place)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue