Browse Source

Fall back to "null island" when no centerpoint is given in index.

feature/region-slug-gone
Bèr Kessels 5 months ago
parent
commit
a48d263c02
3 changed files with 18 additions and 1 deletions
  1. 9
    1
      app/models/place_index.rb
  2. 5
    0
      test/models/place_index_test.rb
  3. 4
    0
      test/support/location_helpers.rb

+ 9
- 1
app/models/place_index.rb View File

@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'georuby'

require_relative 'base_collection.rb'
require_relative 'place.rb'

@@ -22,7 +24,13 @@ module Hours

def initialize(dataset, paginator = nil, centerpoint = nil)
super(dataset, paginator)
@centerpoint = centerpoint
@centerpoint = centerpoint || null_island
end

private

def null_island
GeoRuby::SimpleFeatures::Point.from_xy(0, 0)
end
end
end

+ 5
- 0
test/models/place_index_test.rb View File

@@ -19,4 +19,9 @@ describe Hours::Models::PlaceIndex do
subject = Hours::Models::PlaceIndex.new(dataset, nil, centerpoint)
assert_equal centerpoint, subject.centerpoint
end

it 'has a default centerpoint' do
subject = Hours::Models::PlaceIndex.new(dataset, nil, nil)
assert_equal null_island, subject.centerpoint
end
end

+ 4
- 0
test/support/location_helpers.rb View File

@@ -7,6 +7,10 @@ module LocationHelpers

DISTANCE_DELTA = 0.001 # Translates to 79-111 meter.

def null_island
GeoRuby::SimpleFeatures::Point.from_xy(0,0)
end

def assert_nearby(expected, actual, delta = DISTANCE_DELTA, message = nil)
[0, 1].each do |index|
vector = index.zero? ? 'lat' : 'lon'

Loading…
Cancel
Save