From 18f154f40ccbb4a8c1932f92280805a0aee5eff0 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 26 Dec 2019 04:28:43 -0500 Subject: [PATCH] Fixed deprecation warnings in Ruby 2.7 --- CHANGELOG.md | 3 ++- lib/searchkick.rb | 2 +- lib/searchkick/model.rb | 5 +++-- test/aggs_test.rb | 28 ++++++++++++++-------------- test/suggest_test.rb | 4 ++-- test/test_helper.rb | 8 ++++---- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 665c88f..9d0b3f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 4.2.1 (unreleased) -- Fixed deprecation warning +- Fixed deprecation warnings with Elasticsearch +- Fixed deprecation warnings in Ruby 2.7 ## 4.2.0 (2019-12-18) diff --git a/lib/searchkick.rb b/lib/searchkick.rb index 28e8695..dfce437 100644 --- a/lib/searchkick.rb +++ b/lib/searchkick.rb @@ -112,7 +112,7 @@ module Searchkick end options = options.merge(block: block) if block - query = Searchkick::Query.new(klass, term, options) + query = Searchkick::Query.new(klass, term, **options) if options[:execute] == false query else diff --git a/lib/searchkick/model.rb b/lib/searchkick/model.rb index 8df42f7..8f29fe1 100644 --- a/lib/searchkick/model.rb +++ b/lib/searchkick/model.rb @@ -41,7 +41,7 @@ module Searchkick class << self def searchkick_search(term = "*", **options, &block) - Searchkick.search(term, {model: self}.merge(options), &block) + Searchkick.search(term, model: self, **options, &block) end alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name @@ -79,8 +79,9 @@ module Searchkick RecordIndexer.new(self).reindex(method_name, **options) end unless method_defined?(:reindex) + # TODO switch to keyword arguments def similar(options = {}) - self.class.searchkick_index.similar_record(self, options) + self.class.searchkick_index.similar_record(self, **options) end unless method_defined?(:similar) def search_data diff --git a/test/aggs_test.rb b/test/aggs_test.rb index ad27714..fb0ef3f 100644 --- a/test/aggs_test.rb +++ b/test/aggs_test.rb @@ -105,7 +105,7 @@ class AggsTest < Minitest::Test def test_aggs_group_by_date store [{name: "Old Product", created_at: 3.years.ago}] products = - Product.search("Product", { + Product.search("Product", where: { created_at: {lt: Time.now} }, @@ -117,7 +117,7 @@ class AggsTest < Minitest::Test } } } - }) + ) assert_equal 4, products.aggs["products_per_year"]["buckets"].size end @@ -150,7 +150,7 @@ class AggsTest < Minitest::Test def test_aggs_avg products = - Product.search("*", { + Product.search("*", aggs: { avg_price: { avg: { @@ -158,13 +158,13 @@ class AggsTest < Minitest::Test } } } - }) + ) assert_equal 16.5, products.aggs["avg_price"]["value"] end def test_aggs_cardinality products = - Product.search("*", { + Product.search("*", aggs: { total_stores: { cardinality: { @@ -172,13 +172,13 @@ class AggsTest < Minitest::Test } } } - }) + ) assert_equal 3, products.aggs["total_stores"]["value"] end def test_aggs_min_max products = - Product.search("*", { + Product.search("*", aggs: { min_price: { min: { @@ -191,14 +191,14 @@ class AggsTest < Minitest::Test } } } - }) + ) assert_equal 5, products.aggs["min_price"]["value"] assert_equal 25, products.aggs["max_price"]["value"] end def test_aggs_sum products = - Product.search("*", { + Product.search("*", aggs: { sum_price: { sum: { @@ -206,7 +206,7 @@ class AggsTest < Minitest::Test } } } - }) + ) assert_equal 66, products.aggs["sum_price"]["value"] end @@ -233,7 +233,7 @@ class AggsTest < Minitest::Test protected def search_aggregate_by_day_with_time_zone(query, time_zone = '-8:00') - Product.search(query, { + Product.search(query, where: { created_at: {lt: Time.now} }, @@ -246,7 +246,7 @@ class AggsTest < Minitest::Test } } } - }) + ) end def buckets_as_hash(agg) @@ -254,12 +254,12 @@ class AggsTest < Minitest::Test end def store_agg(options, agg_key = "store_id") - buckets = Product.search("Product", options).aggs[agg_key] + buckets = Product.search("Product", **options).aggs[agg_key] buckets_as_hash(buckets) end def store_multiple_aggs(options) - Hash[Product.search("Product", options).aggs.map do |field, filtered_agg| + Hash[Product.search("Product", **options).aggs.map do |field, filtered_agg| [field, buckets_as_hash(filtered_agg)] end] end diff --git a/test/suggest_test.rb b/test/suggest_test.rb index ed5f709..316b252 100644 --- a/test/suggest_test.rb +++ b/test/suggest_test.rb @@ -94,7 +94,7 @@ class SuggestTest < Minitest::Test protected def assert_suggest(term, expected, options = {}) - result = Product.search(term, options.merge(suggest: true)).suggestions.first + result = Product.search(term, suggest: true, **options).suggestions.first if expected.nil? assert_nil result else @@ -104,6 +104,6 @@ class SuggestTest < Minitest::Test # any order def assert_suggest_all(term, expected, options = {}) - assert_equal expected.sort, Product.search(term, options.merge(suggest: true)).suggestions.sort + assert_equal expected.sort, Product.search(term, suggest: true, **options).suggestions.sort end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0ca5bb3..82d8161 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -84,19 +84,19 @@ class Minitest::Test # no order def assert_search(term, expected, options = {}, klass = Product) - assert_equal expected.sort, klass.search(term, options).map(&:name).sort + assert_equal expected.sort, klass.search(term, **options).map(&:name).sort end def assert_order(term, expected, options = {}, klass = Product) - assert_equal expected, klass.search(term, options).map(&:name) + assert_equal expected, klass.search(term, **options).map(&:name) end def assert_equal_scores(term, options = {}, klass = Product) - assert_equal 1, klass.search(term, options).hits.map { |a| a["_score"] }.uniq.size + assert_equal 1, klass.search(term, **options).hits.map { |a| a["_score"] }.uniq.size end def assert_first(term, expected, options = {}, klass = Product) - assert_equal expected, klass.search(term, options).map(&:name).first + assert_equal expected, klass.search(term, **options).map(&:name).first end def assert_misspellings(term, expected, misspellings = {}, klass = Product) -- libgit2 0.21.0