Commit 023ee183541d45d4f4249956076ae60b603146f6

Authored by Andrew Kane
1 parent 94081b28

Ensure options aren't modified, speed up tests, and small style updates

lib/searchkick/index_options.rb
... ... @@ -281,7 +281,7 @@ module Searchkick
281 281 }
282 282 end
283 283  
284   - options[:geo_shapes] = options[:geo_shapes].product([{}]).to_h if options[:geo_shapes].is_a? Array
  284 + options[:geo_shapes] = options[:geo_shapes].product([{}]).to_h if options[:geo_shapes].is_a?(Array)
285 285 (options[:geo_shapes] || {}).each do |field, shape_options|
286 286 mapping[field] = shape_options.merge(type: "geo_shape")
287 287 end
... ...
lib/searchkick/query.rb
... ... @@ -829,13 +829,13 @@ module Searchkick
829 829 }
830 830 }
831 831 when :geo_shape
832   - op_value[:coordinates] = coordinate_array(op_value[:coordinates]) if op_value[:coordinates]
833   - relation = op_value.delete(:relation) || 'intersects'
  832 + shape = op_value.except(:relation)
  833 + shape[:coordinates] = coordinate_array(shape[:coordinates]) if shape[:coordinates]
834 834 filters << {
835 835 geo_shape: {
836 836 field => {
837   - relation: relation,
838   - shape: op_value
  837 + relation: op_value[:relation] || "intersects",
  838 + shape: shape
839 839 }
840 840 }
841 841 }
... ...
test/geo_shape_test.rb
... ... @@ -2,14 +2,14 @@ require_relative &quot;test_helper&quot;
2 2  
3 3 class GeoShapeTest < Minitest::Test
4 4 def setup
5   - super
  5 + Region.destroy_all
6 6 store [
7 7 {
8 8 name: "Region A",
9 9 text: "The witch had a cat",
10 10 territory: {
11 11 type: "polygon",
12   - coordinates: [[[30,40],[35,45],[40,40],[40,30],[30,30],[30,40]]]
  12 + coordinates: [[[30, 40], [35, 45], [40, 40], [40, 30], [30, 30], [30, 40]]]
13 13 }
14 14 },
15 15 {
... ... @@ -17,7 +17,7 @@ class GeoShapeTest &lt; Minitest::Test
17 17 text: "and a very tall hat",
18 18 territory: {
19 19 type: "polygon",
20   - coordinates: [[[50,60],[55,65],[60,60],[60,50],[50,50],[50,60]]]
  20 + coordinates: [[[50, 60], [55, 65], [60, 60], [60, 50], [50, 50], [50, 60]]]
21 21 }
22 22 },
23 23 {
... ... @@ -25,7 +25,7 @@ class GeoShapeTest &lt; Minitest::Test
25 25 text: "and long ginger hair which she wore in a plait",
26 26 territory: {
27 27 type: "polygon",
28   - coordinates: [[[10,20],[15,25],[20,20],[20,10],[10,10],[10,20]]]
  28 + coordinates: [[[10, 20], [15, 25], [20, 20], [20, 10], [10, 10], [10, 20]]]
29 29 }
30 30 }
31 31 ], Region
... ... @@ -149,7 +149,7 @@ class GeoShapeTest &lt; Minitest::Test
149 149 geo_shape: {
150 150 type: "envelope",
151 151 relation: "contains",
152   - coordinates: [[12, 13], [13,12]]
  152 + coordinates: [[12, 13], [13, 12]]
153 153 }
154 154 }
155 155 }
... ...
test/test_helper.rb
... ... @@ -414,8 +414,6 @@ Product.create!(name: &quot;Set mapping&quot;)
414 414 Store.reindex
415 415 Animal.reindex
416 416 Speaker.reindex
417   -
418   -Region.searchkick_index.delete if Region.searchkick_index.exists?
419 417 Region.reindex
420 418  
421 419 class Minitest::Test
... ... @@ -424,7 +422,6 @@ class Minitest::Test
424 422 Store.destroy_all
425 423 Animal.destroy_all
426 424 Speaker.destroy_all
427   - Region.destroy_all
428 425 end
429 426  
430 427 protected
... ...