Skip to content
Permalink
Browse files

Fixed deprecation warnings in Ruby 2.7

  • Loading branch information
ankane committed Dec 26, 2019
1 parent 097d9b7 commit 18f154f40ccbb4a8c1932f92280805a0aee5eff0
Showing with 26 additions and 24 deletions.
  1. +2 −1 CHANGELOG.md
  2. +1 −1 lib/searchkick.rb
  3. +3 −2 lib/searchkick/model.rb
  4. +14 −14 test/aggs_test.rb
  5. +2 −2 test/suggest_test.rb
  6. +4 −4 test/test_helper.rb
@@ -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)

@@ -112,7 +112,7 @@ def self.search(term = "*", model: nil, **options, &block)
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
@@ -41,7 +41,7 @@ def searchkick(**options)

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 @@ def reindex(method_name = nil, **options)
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
@@ -105,7 +105,7 @@ def test_smart_aggs_false
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 @@ def test_aggs_group_by_date
}
}
}
})
)

assert_equal 4, products.aggs["products_per_year"]["buckets"].size
end
@@ -150,35 +150,35 @@ def test_aggs_with_time_zone

def test_aggs_avg
products =
Product.search("*", {
Product.search("*",
aggs: {
avg_price: {
avg: {
field: :price
}
}
}
})
)
assert_equal 16.5, products.aggs["avg_price"]["value"]
end

def test_aggs_cardinality
products =
Product.search("*", {
Product.search("*",
aggs: {
total_stores: {
cardinality: {
field: :store_id
}
}
}
})
)
assert_equal 3, products.aggs["total_stores"]["value"]
end

def test_aggs_min_max
products =
Product.search("*", {
Product.search("*",
aggs: {
min_price: {
min: {
@@ -191,22 +191,22 @@ def test_aggs_min_max
}
}
}
})
)
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: {
field: :price
}
}
}
})
)
assert_equal 66, products.aggs["sum_price"]["value"]
end

@@ -233,7 +233,7 @@ def test_body_options
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,20 +246,20 @@ def search_aggregate_by_day_with_time_zone(query, time_zone = '-8:00')
}
}
}
})
)
end

def buckets_as_hash(agg)
Hash[agg["buckets"].map { |v| [v["key"], v["doc_count"]] }]
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
@@ -94,7 +94,7 @@ def test_star
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 @@ def assert_suggest(term, expected, options = {})

# 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
@@ -84,19 +84,19 @@ def store_names(names, klass = Product)

# 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)

0 comments on commit 18f154f

Please sign in to comment.
You can’t perform that action at this time.