From 38bd3661afb91fd34bc89d35cfc2096773212474 Mon Sep 17 00:00:00 2001 From: will-r Date: Thu, 22 Dec 2016 11:22:05 +0000 Subject: [PATCH] tidy up Region test model, add specific test for lat: lon: formatted input --- test/geo_shape_test.rb | 43 +++++++++++++++++++++++++++++++++++++++---- test/test_helper.rb | 19 +++---------------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/test/geo_shape_test.rb b/test/geo_shape_test.rb index 83438f0..9d3b95c 100644 --- a/test/geo_shape_test.rb +++ b/test/geo_shape_test.rb @@ -4,9 +4,30 @@ class GeoShapeTest < Minitest::Test def setup super store [ - {name: "Region A", text: "The witch had a cat", territory: "30,40,35,45,40,40,40,30,30,30,30,40"}, - {name: "Region B", text: "and a very tall hat", territory: "50,60,55,65,60,60,60,50,50,50,50,60"}, - {name: "Region C", text: "and long ginger hair which she wore in a plait", territory: "10,20,15,25,20,20,20,10,10,10,10,20"} + { + name: "Region A", + text: "The witch had a cat", + territory: { + type: "polygon", + coordinates: [[[30,40],[35,45],[40,40],[40,30],[30,30],[30,40]]] + } + }, + { + name: "Region B", + text: "and a very tall hat", + territory: { + type: "polygon", + coordinates: [[[50,60],[55,65],[60,60],[60,50],[50,50],[50,60]]] + } + }, + { + name: "Region C", + text: "and long ginger hair which she wore in a plait", + territory: { + type: "polygon", + coordinates: [[[10,20],[15,25],[20,20],[20,10],[10,10],[10,20]]] + } + } ], Region end @@ -87,7 +108,7 @@ class GeoShapeTest < Minitest::Test geo_shape: { type: "envelope", relation: "within", - coordinates: [[20, 50], [50, 20]] + coordinates: [[20,50], [50,20]] } } } @@ -134,4 +155,18 @@ class GeoShapeTest < Minitest::Test } }, Region end + + def test_latlon + assert_search "*", ["Region A"], { + where: { + territory: { + geo_shape: { + type: "envelope", + coordinates: [{lat: 42, lon: 28}, {lat: 38, lon: 32}] + } + } + } + }, Region + end + end diff --git a/test/test_helper.rb b/test/test_helper.rb index 788b297..6e60988 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -102,7 +102,6 @@ if defined?(Mongoid) field :name field :text - field :territory end class Speaker @@ -161,7 +160,6 @@ elsif defined?(NoBrainer) field :id, type: Object field :name, type: String field :text, type: Text - field :territory, type: Text end class Speaker @@ -258,7 +256,6 @@ else ActiveRecord::Migration.create_table :regions do |t| t.string :name t.text :text - t.text :territory end ActiveRecord::Migration.create_table :speakers do |t| @@ -374,25 +371,15 @@ class Region territory: {tree: "quadtree", precision: "10km"} } + attr_accessor :territory + def search_data { name: name, text: text, - territory: as_geo_json + territory: territory } end - - def as_geo_json - { - type: "polygon", - coordinates: [territory_path] # enclosing array because polygon can also have exclusion paths. - } - end - - def territory_path - path = territory.split(',').map(&:to_f).each_slice(2).to_a - path - end end class Speaker -- libgit2 0.21.0