Skip to content
Permalink
Browse files

Treat empty Geocollections as empty

Fixes #845
  • Loading branch information...
nikolai-b committed Apr 7, 2019
1 parent 36cba95 commit c21432cb118103bbd9bcec4b02f6994832396011
@@ -11,6 +11,7 @@ def create
set_flash_message :success
redirect_to action: :index
else
@full_page = true
@start_location = SiteConfig.first.nowhere_location
render :new
end
@@ -1,5 +1,8 @@
# frozen_string_literal: true

module Locatable
extend ActiveSupport::Concern
EMPTY_JSON = '{"type":"FeatureCollection","features":[]}'.freeze

included do
after_create :make_location_valid
@@ -105,7 +108,7 @@ def size_ratio(geom)
end

def loc_json=(json_str)
if json_str.blank?
if json_str.blank? || json_str == EMPTY_JSON
self.location = nil
return
end
@@ -27,6 +27,11 @@
expect(subject).not_to be_valid
end

it 'must have a non empty location' do
subject.loc_json = "{\"type\":\"FeatureCollection\",\"features\":[]}"
expect(subject).not_to be_valid
end

it 'must return an empty geojson string when no location' do
subject.location = nil
expect(subject.loc_json).to be_a(String)

0 comments on commit c21432c

Please sign in to comment.
You can’t perform that action at this time.