Commit 18f154f40ccbb4a8c1932f92280805a0aee5eff0

Authored by Andrew Kane
1 parent 097d9b73

Fixed deprecation warnings in Ruby 2.7

1 ## 4.2.1 (unreleased) 1 ## 4.2.1 (unreleased)
2 2
3 -- Fixed deprecation warning 3 +- Fixed deprecation warnings with Elasticsearch
  4 +- Fixed deprecation warnings in Ruby 2.7
4 5
5 ## 4.2.0 (2019-12-18) 6 ## 4.2.0 (2019-12-18)
6 7
lib/searchkick.rb
@@ -112,7 +112,7 @@ module Searchkick @@ -112,7 +112,7 @@ module Searchkick
112 end 112 end
113 113
114 options = options.merge(block: block) if block 114 options = options.merge(block: block) if block
115 - query = Searchkick::Query.new(klass, term, options) 115 + query = Searchkick::Query.new(klass, term, **options)
116 if options[:execute] == false 116 if options[:execute] == false
117 query 117 query
118 else 118 else
lib/searchkick/model.rb
@@ -41,7 +41,7 @@ module Searchkick @@ -41,7 +41,7 @@ module Searchkick
41 41
42 class << self 42 class << self
43 def searchkick_search(term = "*", **options, &block) 43 def searchkick_search(term = "*", **options, &block)
44 - Searchkick.search(term, {model: self}.merge(options), &block) 44 + Searchkick.search(term, model: self, **options, &block)
45 end 45 end
46 alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name 46 alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name
47 47
@@ -79,8 +79,9 @@ module Searchkick @@ -79,8 +79,9 @@ module Searchkick
79 RecordIndexer.new(self).reindex(method_name, **options) 79 RecordIndexer.new(self).reindex(method_name, **options)
80 end unless method_defined?(:reindex) 80 end unless method_defined?(:reindex)
81 81
  82 + # TODO switch to keyword arguments
82 def similar(options = {}) 83 def similar(options = {})
83 - self.class.searchkick_index.similar_record(self, options) 84 + self.class.searchkick_index.similar_record(self, **options)
84 end unless method_defined?(:similar) 85 end unless method_defined?(:similar)
85 86
86 def search_data 87 def search_data
test/aggs_test.rb
@@ -105,7 +105,7 @@ class AggsTest &lt; Minitest::Test @@ -105,7 +105,7 @@ class AggsTest &lt; Minitest::Test
105 def test_aggs_group_by_date 105 def test_aggs_group_by_date
106 store [{name: "Old Product", created_at: 3.years.ago}] 106 store [{name: "Old Product", created_at: 3.years.ago}]
107 products = 107 products =
108 - Product.search("Product", { 108 + Product.search("Product",
109 where: { 109 where: {
110 created_at: {lt: Time.now} 110 created_at: {lt: Time.now}
111 }, 111 },
@@ -117,7 +117,7 @@ class AggsTest &lt; Minitest::Test @@ -117,7 +117,7 @@ class AggsTest &lt; Minitest::Test
117 } 117 }
118 } 118 }
119 } 119 }
120 - }) 120 + )
121 121
122 assert_equal 4, products.aggs["products_per_year"]["buckets"].size 122 assert_equal 4, products.aggs["products_per_year"]["buckets"].size
123 end 123 end
@@ -150,7 +150,7 @@ class AggsTest &lt; Minitest::Test @@ -150,7 +150,7 @@ class AggsTest &lt; Minitest::Test
150 150
151 def test_aggs_avg 151 def test_aggs_avg
152 products = 152 products =
153 - Product.search("*", { 153 + Product.search("*",
154 aggs: { 154 aggs: {
155 avg_price: { 155 avg_price: {
156 avg: { 156 avg: {
@@ -158,13 +158,13 @@ class AggsTest &lt; Minitest::Test @@ -158,13 +158,13 @@ class AggsTest &lt; Minitest::Test
158 } 158 }
159 } 159 }
160 } 160 }
161 - }) 161 + )
162 assert_equal 16.5, products.aggs["avg_price"]["value"] 162 assert_equal 16.5, products.aggs["avg_price"]["value"]
163 end 163 end
164 164
165 def test_aggs_cardinality 165 def test_aggs_cardinality
166 products = 166 products =
167 - Product.search("*", { 167 + Product.search("*",
168 aggs: { 168 aggs: {
169 total_stores: { 169 total_stores: {
170 cardinality: { 170 cardinality: {
@@ -172,13 +172,13 @@ class AggsTest &lt; Minitest::Test @@ -172,13 +172,13 @@ class AggsTest &lt; Minitest::Test
172 } 172 }
173 } 173 }
174 } 174 }
175 - }) 175 + )
176 assert_equal 3, products.aggs["total_stores"]["value"] 176 assert_equal 3, products.aggs["total_stores"]["value"]
177 end 177 end
178 178
179 def test_aggs_min_max 179 def test_aggs_min_max
180 products = 180 products =
181 - Product.search("*", { 181 + Product.search("*",
182 aggs: { 182 aggs: {
183 min_price: { 183 min_price: {
184 min: { 184 min: {
@@ -191,14 +191,14 @@ class AggsTest &lt; Minitest::Test @@ -191,14 +191,14 @@ class AggsTest &lt; Minitest::Test
191 } 191 }
192 } 192 }
193 } 193 }
194 - }) 194 + )
195 assert_equal 5, products.aggs["min_price"]["value"] 195 assert_equal 5, products.aggs["min_price"]["value"]
196 assert_equal 25, products.aggs["max_price"]["value"] 196 assert_equal 25, products.aggs["max_price"]["value"]
197 end 197 end
198 198
199 def test_aggs_sum 199 def test_aggs_sum
200 products = 200 products =
201 - Product.search("*", { 201 + Product.search("*",
202 aggs: { 202 aggs: {
203 sum_price: { 203 sum_price: {
204 sum: { 204 sum: {
@@ -206,7 +206,7 @@ class AggsTest &lt; Minitest::Test @@ -206,7 +206,7 @@ class AggsTest &lt; Minitest::Test
206 } 206 }
207 } 207 }
208 } 208 }
209 - }) 209 + )
210 assert_equal 66, products.aggs["sum_price"]["value"] 210 assert_equal 66, products.aggs["sum_price"]["value"]
211 end 211 end
212 212
@@ -233,7 +233,7 @@ class AggsTest &lt; Minitest::Test @@ -233,7 +233,7 @@ class AggsTest &lt; Minitest::Test
233 protected 233 protected
234 234
235 def search_aggregate_by_day_with_time_zone(query, time_zone = '-8:00') 235 def search_aggregate_by_day_with_time_zone(query, time_zone = '-8:00')
236 - Product.search(query, { 236 + Product.search(query,
237 where: { 237 where: {
238 created_at: {lt: Time.now} 238 created_at: {lt: Time.now}
239 }, 239 },
@@ -246,7 +246,7 @@ class AggsTest &lt; Minitest::Test @@ -246,7 +246,7 @@ class AggsTest &lt; Minitest::Test
246 } 246 }
247 } 247 }
248 } 248 }
249 - }) 249 + )
250 end 250 end
251 251
252 def buckets_as_hash(agg) 252 def buckets_as_hash(agg)
@@ -254,12 +254,12 @@ class AggsTest &lt; Minitest::Test @@ -254,12 +254,12 @@ class AggsTest &lt; Minitest::Test
254 end 254 end
255 255
256 def store_agg(options, agg_key = "store_id") 256 def store_agg(options, agg_key = "store_id")
257 - buckets = Product.search("Product", options).aggs[agg_key] 257 + buckets = Product.search("Product", **options).aggs[agg_key]
258 buckets_as_hash(buckets) 258 buckets_as_hash(buckets)
259 end 259 end
260 260
261 def store_multiple_aggs(options) 261 def store_multiple_aggs(options)
262 - Hash[Product.search("Product", options).aggs.map do |field, filtered_agg| 262 + Hash[Product.search("Product", **options).aggs.map do |field, filtered_agg|
263 [field, buckets_as_hash(filtered_agg)] 263 [field, buckets_as_hash(filtered_agg)]
264 end] 264 end]
265 end 265 end
test/suggest_test.rb
@@ -94,7 +94,7 @@ class SuggestTest &lt; Minitest::Test @@ -94,7 +94,7 @@ class SuggestTest &lt; Minitest::Test
94 protected 94 protected
95 95
96 def assert_suggest(term, expected, options = {}) 96 def assert_suggest(term, expected, options = {})
97 - result = Product.search(term, options.merge(suggest: true)).suggestions.first 97 + result = Product.search(term, suggest: true, **options).suggestions.first
98 if expected.nil? 98 if expected.nil?
99 assert_nil result 99 assert_nil result
100 else 100 else
@@ -104,6 +104,6 @@ class SuggestTest &lt; Minitest::Test @@ -104,6 +104,6 @@ class SuggestTest &lt; Minitest::Test
104 104
105 # any order 105 # any order
106 def assert_suggest_all(term, expected, options = {}) 106 def assert_suggest_all(term, expected, options = {})
107 - assert_equal expected.sort, Product.search(term, options.merge(suggest: true)).suggestions.sort 107 + assert_equal expected.sort, Product.search(term, suggest: true, **options).suggestions.sort
108 end 108 end
109 end 109 end
test/test_helper.rb
@@ -84,19 +84,19 @@ class Minitest::Test @@ -84,19 +84,19 @@ class Minitest::Test
84 84
85 # no order 85 # no order
86 def assert_search(term, expected, options = {}, klass = Product) 86 def assert_search(term, expected, options = {}, klass = Product)
87 - assert_equal expected.sort, klass.search(term, options).map(&:name).sort 87 + assert_equal expected.sort, klass.search(term, **options).map(&:name).sort
88 end 88 end
89 89
90 def assert_order(term, expected, options = {}, klass = Product) 90 def assert_order(term, expected, options = {}, klass = Product)
91 - assert_equal expected, klass.search(term, options).map(&:name) 91 + assert_equal expected, klass.search(term, **options).map(&:name)
92 end 92 end
93 93
94 def assert_equal_scores(term, options = {}, klass = Product) 94 def assert_equal_scores(term, options = {}, klass = Product)
95 - assert_equal 1, klass.search(term, options).hits.map { |a| a["_score"] }.uniq.size 95 + assert_equal 1, klass.search(term, **options).hits.map { |a| a["_score"] }.uniq.size
96 end 96 end
97 97
98 def assert_first(term, expected, options = {}, klass = Product) 98 def assert_first(term, expected, options = {}, klass = Product)
99 - assert_equal expected, klass.search(term, options).map(&:name).first 99 + assert_equal expected, klass.search(term, **options).map(&:name).first
100 end 100 end
101 101
102 def assert_misspellings(term, expected, misspellings = {}, klass = Product) 102 def assert_misspellings(term, expected, misspellings = {}, klass = Product)