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