Fix spatial queries to use correct geography column

This commit is contained in:
Eugene Burmakin 2025-09-03 18:22:39 +02:00
parent 83fc3106a0
commit e3e5770843
2 changed files with 13 additions and 21 deletions

View file

@ -28,7 +28,7 @@ FactoryBot.define do
course { nil } course { nil }
course_accuracy { nil } course_accuracy { nil }
external_track_id { nil } external_track_id { nil }
lonlat { "POINT(#{FFaker::Geolocation.lng} #{FFaker::Geolocation.lat})" } lonlat { "POINT(#{longitude} #{latitude})" }
user user
country_id { nil } country_id { nil }

View file

@ -13,8 +13,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
let!(:near_point) do let!(:near_point) do
create(:point, create(:point,
user: user, user: user,
latitude: 52.5201, lonlat: "POINT(13.4051 52.5201)",
longitude: 13.4051,
timestamp: 1.hour.ago.to_i, timestamp: 1.hour.ago.to_i,
city: 'Berlin', city: 'Berlin',
country: 'Germany', country: 'Germany',
@ -26,8 +25,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
let!(:far_point) do let!(:far_point) do
create(:point, create(:point,
user: user, user: user,
latitude: 52.6000, # ~9km away lonlat: "POINT(13.5000 52.6000)",
longitude: 13.5000,
timestamp: 2.hours.ago.to_i timestamp: 2.hours.ago.to_i
) )
end end
@ -35,8 +33,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
let!(:other_user_point) do let!(:other_user_point) do
create(:point, create(:point,
user: create(:user), user: create(:user),
latitude: 52.5201, lonlat: "POINT(13.4051 52.5201)",
longitude: 13.4051,
timestamp: 30.minutes.ago.to_i timestamp: 30.minutes.ago.to_i
) )
end end
@ -77,7 +74,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
expect(point).to include( expect(point).to include(
id: near_point.id, id: near_point.id,
timestamp: near_point.timestamp, timestamp: near_point.timestamp,
coordinates: [near_point.latitude.to_f, near_point.longitude.to_f], coordinates: [52.5201, 13.4051],
city: 'Berlin', city: 'Berlin',
country: 'Germany', country: 'Germany',
altitude: 100, altitude: 100,
@ -95,8 +92,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
# Create another nearby point with older timestamp # Create another nearby point with older timestamp
older_point = create(:point, older_point = create(:point,
user: user, user: user,
latitude: 52.5199, lonlat: "POINT(13.4049 52.5199)",
longitude: 13.4049,
timestamp: 3.hours.ago.to_i timestamp: 3.hours.ago.to_i
) )
@ -118,8 +114,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
let!(:old_point) do let!(:old_point) do
create(:point, create(:point,
user: user, user: user,
latitude: 52.5201, lonlat: "POINT(13.4051 52.5201)",
longitude: 13.4051,
timestamp: 1.week.ago.to_i timestamp: 1.week.ago.to_i
) )
end end
@ -177,8 +172,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
# Create point with negative coordinates # Create point with negative coordinates
negative_point = create(:point, negative_point = create(:point,
user: user, user: user,
latitude: -33.8688, # Sydney lonlat: "POINT(151.2093 -33.8688)",
longitude: 151.2093,
timestamp: 1.hour.ago.to_i timestamp: 1.hour.ago.to_i
) )
@ -192,8 +186,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
# Create point near north pole # Create point near north pole
polar_point = create(:point, polar_point = create(:point,
user: user, user: user,
latitude: 89.0, lonlat: "POINT(0.0 89.0)",
longitude: 0.0,
timestamp: 1.hour.ago.to_i timestamp: 1.hour.ago.to_i
) )
@ -210,8 +203,7 @@ RSpec.describe LocationSearch::SpatialMatcher do
50.times do |i| 50.times do |i|
create(:point, create(:point,
user: user, user: user,
latitude: latitude + (i * 0.0001), # Spread points slightly lonlat: "POINT(#{longitude + (i * 0.0001)} #{latitude + (i * 0.0001)})", # Spread points slightly
longitude: longitude + (i * 0.0001),
timestamp: i.hours.ago.to_i timestamp: i.hours.ago.to_i
) )
end end