Commit 38bd3661afb91fd34bc89d35cfc2096773212474
1 parent
9bdb4158
Exists in
master
and in
21 other branches
tidy up Region test model, add specific test for lat: lon: formatted input
Showing
2 changed files
with
42 additions
and
20 deletions
Show diff stats
test/geo_shape_test.rb
... | ... | @@ -4,9 +4,30 @@ class GeoShapeTest < Minitest::Test |
4 | 4 | def setup |
5 | 5 | super |
6 | 6 | store [ |
7 | - {name: "Region A", text: "The witch had a cat", territory: "30,40,35,45,40,40,40,30,30,30,30,40"}, | |
8 | - {name: "Region B", text: "and a very tall hat", territory: "50,60,55,65,60,60,60,50,50,50,50,60"}, | |
9 | - {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"} | |
7 | + { | |
8 | + name: "Region A", | |
9 | + text: "The witch had a cat", | |
10 | + territory: { | |
11 | + type: "polygon", | |
12 | + coordinates: [[[30,40],[35,45],[40,40],[40,30],[30,30],[30,40]]] | |
13 | + } | |
14 | + }, | |
15 | + { | |
16 | + name: "Region B", | |
17 | + text: "and a very tall hat", | |
18 | + territory: { | |
19 | + type: "polygon", | |
20 | + coordinates: [[[50,60],[55,65],[60,60],[60,50],[50,50],[50,60]]] | |
21 | + } | |
22 | + }, | |
23 | + { | |
24 | + name: "Region C", | |
25 | + text: "and long ginger hair which she wore in a plait", | |
26 | + territory: { | |
27 | + type: "polygon", | |
28 | + coordinates: [[[10,20],[15,25],[20,20],[20,10],[10,10],[10,20]]] | |
29 | + } | |
30 | + } | |
10 | 31 | ], Region |
11 | 32 | end |
12 | 33 | |
... | ... | @@ -87,7 +108,7 @@ class GeoShapeTest < Minitest::Test |
87 | 108 | geo_shape: { |
88 | 109 | type: "envelope", |
89 | 110 | relation: "within", |
90 | - coordinates: [[20, 50], [50, 20]] | |
111 | + coordinates: [[20,50], [50,20]] | |
91 | 112 | } |
92 | 113 | } |
93 | 114 | } |
... | ... | @@ -134,4 +155,18 @@ class GeoShapeTest < Minitest::Test |
134 | 155 | } |
135 | 156 | }, Region |
136 | 157 | end |
158 | + | |
159 | + def test_latlon | |
160 | + assert_search "*", ["Region A"], { | |
161 | + where: { | |
162 | + territory: { | |
163 | + geo_shape: { | |
164 | + type: "envelope", | |
165 | + coordinates: [{lat: 42, lon: 28}, {lat: 38, lon: 32}] | |
166 | + } | |
167 | + } | |
168 | + } | |
169 | + }, Region | |
170 | + end | |
171 | + | |
137 | 172 | end | ... | ... |
test/test_helper.rb
... | ... | @@ -102,7 +102,6 @@ if defined?(Mongoid) |
102 | 102 | |
103 | 103 | field :name |
104 | 104 | field :text |
105 | - field :territory | |
106 | 105 | end |
107 | 106 | |
108 | 107 | class Speaker |
... | ... | @@ -161,7 +160,6 @@ elsif defined?(NoBrainer) |
161 | 160 | field :id, type: Object |
162 | 161 | field :name, type: String |
163 | 162 | field :text, type: Text |
164 | - field :territory, type: Text | |
165 | 163 | end |
166 | 164 | |
167 | 165 | class Speaker |
... | ... | @@ -258,7 +256,6 @@ else |
258 | 256 | ActiveRecord::Migration.create_table :regions do |t| |
259 | 257 | t.string :name |
260 | 258 | t.text :text |
261 | - t.text :territory | |
262 | 259 | end |
263 | 260 | |
264 | 261 | ActiveRecord::Migration.create_table :speakers do |t| |
... | ... | @@ -374,25 +371,15 @@ class Region |
374 | 371 | territory: {tree: "quadtree", precision: "10km"} |
375 | 372 | } |
376 | 373 | |
374 | + attr_accessor :territory | |
375 | + | |
377 | 376 | def search_data |
378 | 377 | { |
379 | 378 | name: name, |
380 | 379 | text: text, |
381 | - territory: as_geo_json | |
380 | + territory: territory | |
382 | 381 | } |
383 | 382 | end |
384 | - | |
385 | - def as_geo_json | |
386 | - { | |
387 | - type: "polygon", | |
388 | - coordinates: [territory_path] # enclosing array because polygon can also have exclusion paths. | |
389 | - } | |
390 | - end | |
391 | - | |
392 | - def territory_path | |
393 | - path = territory.split(',').map(&:to_f).each_slice(2).to_a | |
394 | - path | |
395 | - end | |
396 | 383 | end |
397 | 384 | |
398 | 385 | class Speaker | ... | ... |