From 023ee183541d45d4f4249956076ae60b603146f6 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 23 Dec 2016 13:50:07 -0800 Subject: [PATCH] Ensure options aren't modified, speed up tests, and small style updates --- lib/searchkick/index_options.rb | 2 +- lib/searchkick/query.rb | 8 ++++---- test/geo_shape_test.rb | 10 +++++----- test/test_helper.rb | 3 --- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/searchkick/index_options.rb b/lib/searchkick/index_options.rb index ea3ed1b..3815216 100644 --- a/lib/searchkick/index_options.rb +++ b/lib/searchkick/index_options.rb @@ -281,7 +281,7 @@ module Searchkick } end - options[:geo_shapes] = options[:geo_shapes].product([{}]).to_h if options[:geo_shapes].is_a? Array + options[:geo_shapes] = options[:geo_shapes].product([{}]).to_h if options[:geo_shapes].is_a?(Array) (options[:geo_shapes] || {}).each do |field, shape_options| mapping[field] = shape_options.merge(type: "geo_shape") end diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 3a2f813..eba5ebd 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -829,13 +829,13 @@ module Searchkick } } when :geo_shape - op_value[:coordinates] = coordinate_array(op_value[:coordinates]) if op_value[:coordinates] - relation = op_value.delete(:relation) || 'intersects' + shape = op_value.except(:relation) + shape[:coordinates] = coordinate_array(shape[:coordinates]) if shape[:coordinates] filters << { geo_shape: { field => { - relation: relation, - shape: op_value + relation: op_value[:relation] || "intersects", + shape: shape } } } diff --git a/test/geo_shape_test.rb b/test/geo_shape_test.rb index 9d3b95c..2d15ef5 100644 --- a/test/geo_shape_test.rb +++ b/test/geo_shape_test.rb @@ -2,14 +2,14 @@ require_relative "test_helper" class GeoShapeTest < Minitest::Test def setup - super + Region.destroy_all store [ { 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]]] + coordinates: [[[30, 40], [35, 45], [40, 40], [40, 30], [30, 30], [30, 40]]] } }, { @@ -17,7 +17,7 @@ class GeoShapeTest < Minitest::Test text: "and a very tall hat", territory: { type: "polygon", - coordinates: [[[50,60],[55,65],[60,60],[60,50],[50,50],[50,60]]] + coordinates: [[[50, 60], [55, 65], [60, 60], [60, 50], [50, 50], [50, 60]]] } }, { @@ -25,7 +25,7 @@ class GeoShapeTest < Minitest::Test 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]]] + coordinates: [[[10, 20], [15, 25], [20, 20], [20, 10], [10, 10], [10, 20]]] } } ], Region @@ -149,7 +149,7 @@ class GeoShapeTest < Minitest::Test geo_shape: { type: "envelope", relation: "contains", - coordinates: [[12, 13], [13,12]] + coordinates: [[12, 13], [13, 12]] } } } diff --git a/test/test_helper.rb b/test/test_helper.rb index 9c0c0f2..b97b2a3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -414,8 +414,6 @@ Product.create!(name: "Set mapping") Store.reindex Animal.reindex Speaker.reindex - -Region.searchkick_index.delete if Region.searchkick_index.exists? Region.reindex class Minitest::Test @@ -424,7 +422,6 @@ class Minitest::Test Store.destroy_all Animal.destroy_all Speaker.destroy_all - Region.destroy_all end protected -- libgit2 0.21.0