mirror of
https://github.com/Freika/dawarich.git
synced 2025-12-21 13:00:20 -06:00
Fix some specs
This commit is contained in:
@@ -70,9 +70,9 @@ module Api
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tag_ids
|
def tag_ids
|
||||||
ids = params.dig(:place, :tag_ids)
|
ids = params.dig(:place, :tag_ids)
|
||||||
Array(ids).compact
|
Array(ids).compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_tags
|
def add_tags
|
||||||
return if tag_ids.empty?
|
return if tag_ids.empty?
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ReverseGeocoding::Places::FetchData
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
places = reverse_geocoded_places
|
places = geocoder_places
|
||||||
first_place = places.shift
|
first_place = places.shift
|
||||||
update_place(first_place)
|
update_place(first_place)
|
||||||
|
|
||||||
@@ -82,6 +82,7 @@ class ReverseGeocoding::Places::FetchData
|
|||||||
|
|
||||||
def find_existing_places(osm_ids)
|
def find_existing_places(osm_ids)
|
||||||
Place.where("geodata->'properties'->>'osm_id' IN (?)", osm_ids)
|
Place.where("geodata->'properties'->>'osm_id' IN (?)", osm_ids)
|
||||||
|
.where(user_id: nil)
|
||||||
.index_by { |p| p.geodata.dig('properties', 'osm_id').to_s }
|
.index_by { |p| p.geodata.dig('properties', 'osm_id').to_s }
|
||||||
.compact
|
.compact
|
||||||
end
|
end
|
||||||
@@ -145,7 +146,7 @@ class ReverseGeocoding::Places::FetchData
|
|||||||
"POINT(#{coordinates[0]} #{coordinates[1]})"
|
"POINT(#{coordinates[0]} #{coordinates[1]})"
|
||||||
end
|
end
|
||||||
|
|
||||||
def reverse_geocoded_places
|
def geocoder_places
|
||||||
data = Geocoder.search(
|
data = Geocoder.search(
|
||||||
[place.lat, place.lon],
|
[place.lat, place.lon],
|
||||||
limit: 10,
|
limit: 10,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ FactoryBot.define do
|
|||||||
latitude { 54.2905245 }
|
latitude { 54.2905245 }
|
||||||
longitude { 13.0948638 }
|
longitude { 13.0948638 }
|
||||||
# lonlat is auto-generated by before_validation callback in Place model
|
# lonlat is auto-generated by before_validation callback in Place model
|
||||||
association :user
|
# association :user
|
||||||
|
|
||||||
trait :with_geodata do
|
trait :with_geodata do
|
||||||
geodata do
|
geodata do
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ RSpec.describe ReverseGeocoding::Places::FetchData do
|
|||||||
it 'updates the original place and creates others' do
|
it 'updates the original place and creates others' do
|
||||||
service.call
|
service.call
|
||||||
|
|
||||||
created_place = Place.where.not(id: place.id).first
|
created_place = Place.where(user_id: nil).where.not(id: place.id).first
|
||||||
expect(created_place.name).to include('Second Place')
|
expect(created_place.name).to include('Second Place')
|
||||||
expect(created_place.city).to eq('Hamburg')
|
expect(created_place.city).to eq('Hamburg')
|
||||||
end
|
end
|
||||||
@@ -584,15 +584,15 @@ RSpec.describe ReverseGeocoding::Places::FetchData do
|
|||||||
place # Force place creation
|
place # Force place creation
|
||||||
expect { service.call }.to change { Place.count }.by(1)
|
expect { service.call }.to change { Place.count }.by(1)
|
||||||
|
|
||||||
created_place = Place.where.not(id: place.id).first
|
created_place = Place.where(user_id: nil).where.not(id: place.id).first
|
||||||
expect(created_place.latitude).to eq(54.0)
|
expect(created_place.latitude).to eq(54.0)
|
||||||
expect(created_place.longitude).to eq(13.0)
|
expect(created_place.longitude).to eq(13.0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when lonlat is already present on existing place' do
|
context 'when lonlat is already present on existing place' do
|
||||||
let!(:existing_place) { create(:place, :with_geodata, lonlat: 'POINT(10.0 50.0)') }
|
let!(:existing_place) { create(:place, :with_geodata, lonlat: 'POINT(10.0 50.0)', latitude: 50.0, longitude: 10.0) }
|
||||||
let(:existing_data) do
|
let(:mock_data) do
|
||||||
double(
|
double(
|
||||||
data: {
|
data: {
|
||||||
'geometry' => { 'coordinates' => [15.0, 55.0] },
|
'geometry' => { 'coordinates' => [15.0, 55.0] },
|
||||||
@@ -605,7 +605,7 @@ RSpec.describe ReverseGeocoding::Places::FetchData do
|
|||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(Geocoder).to receive(:search).and_return([mock_geocoded_place, existing_data])
|
allow(Geocoder).to receive(:search).and_return([mock_geocoded_place, mock_data])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not override existing coordinates when updating geodata' do
|
it 'does not override existing coordinates when updating geodata' do
|
||||||
|
|||||||
Reference in New Issue
Block a user