From 7a24684bb470abd5ceca7a40b21d28584b910a4c Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sat, 28 Feb 2015 18:35:11 -0800 Subject: [PATCH] Style updates --- Gemfile | 2 +- Rakefile | 2 +- lib/searchkick.rb | 4 ++-- lib/searchkick/index.rb | 30 +++++++++++++++--------------- lib/searchkick/logging.rb | 2 +- lib/searchkick/model.rb | 10 +++++----- lib/searchkick/query.rb | 38 +++++++++++++++++++------------------- lib/searchkick/results.rb | 16 ++++++++-------- lib/searchkick/tasks.rb | 6 +++--- searchkick.gemspec | 10 +++++----- test/facets_test.rb | 2 +- test/index_test.rb | 10 +++++----- test/reindex_v2_job_test.rb | 2 +- test/sql_test.rb | 8 ++++---- test/suggest_test.rb | 4 ++-- test/test_helper.rb | 8 ++++---- 16 files changed, 77 insertions(+), 77 deletions(-) diff --git a/Gemfile b/Gemfile index 13e303a..2f782b5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in searchkick.gemspec gemspec diff --git a/Rakefile b/Rakefile index 8553350..5cda719 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ require "bundler/gem_tasks" require "rake/testtask" -task :default => :test +task default: :test Rake::TestTask.new do |t| t.libs << "test" t.pattern = "test/**/*_test.rb" diff --git a/lib/searchkick.rb b/lib/searchkick.rb index 6290a94..e4f6d67 100644 --- a/lib/searchkick.rb +++ b/lib/searchkick.rb @@ -44,8 +44,8 @@ module Searchkick ) end - def self.client=(client) - @client = client + class << self + attr_writer :client end def self.server_version diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index a3048c0..37a3d0d 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -34,7 +34,7 @@ module Searchkick rescue Elasticsearch::Transport::Transport::Errors::NotFound [] end - actions = old_indices.map{|old_name| {remove: {index: old_name, alias: name}} } + [{add: {index: new_name, alias: name}}] + actions = old_indices.map { |old_name| {remove: {index: old_name, alias: name}} } + [{add: {index: new_name, alias: name}}] client.indices.update_aliases body: {actions: actions} end @@ -58,11 +58,11 @@ module Searchkick end def import(records) - records.group_by{|r| document_type(r) }.each do |type, batch| + records.group_by { |r| document_type(r) }.each do |type, batch| client.bulk( index: name, type: type, - body: batch.map{|r| {index: {_id: search_id(r), data: search_data(r)}} } + body: batch.map { |r| {index: {_id: search_id(r), data: search_data(r)}} } ) end end @@ -89,7 +89,7 @@ module Searchkick def reindex_record_async(record) if defined?(Searchkick::ReindexV2Job) - Searchkick::ReindexV2Job.perform_later(record.class.name, record.id.to_s) + Searchkick::ReindexV2Job.perform_later(record.class.name, record.id.to_s) else Delayed::Job.enqueue Searchkick::ReindexJob.new(record.class.name, record.id.to_s) end @@ -97,7 +97,7 @@ module Searchkick def similar_record(record, options = {}) like_text = retrieve(record).to_hash - .keep_if{|k,v| !options[:fields] || options[:fields].map(&:to_s).include?(k) } + .keep_if { |k, v| !options[:fields] || options[:fields].map(&:to_s).include?(k) } .values.compact.join(" ") # TODO deep merge method @@ -136,7 +136,7 @@ module Searchkick # remove old indices that start w/ index_name def clean_indices all_indices = client.indices.get_aliases - indices = all_indices.select{|k, v| (v.empty? || v["aliases"].empty?) && k =~ /\A#{Regexp.escape(name)}_\d{14,17}\z/ }.keys + indices = all_indices.select { |k, v| (v.empty? || v["aliases"].empty?) && k =~ /\A#{Regexp.escape(name)}_\d{14,17}\z/ }.keys indices.each do |index| Searchkick::Index.new(index).delete end @@ -180,7 +180,7 @@ module Searchkick scope = scope.search_import if scope.respond_to?(:search_import) if scope.respond_to?(:find_in_batches) scope.find_in_batches batch_size: batch_size do |batch| - import batch.select{|item| item.should_index? } + import batch.select(&:should_index?) end else # https://github.com/karmi/tire/blob/master/lib/tire/model/import.rb @@ -333,7 +333,7 @@ module Searchkick if synonyms.any? settings[:analysis][:filter][:searchkick_synonym] = { type: "synonym", - synonyms: synonyms.select{|s| s.size > 1 }.map{|s| s.join(",") } + synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.join(",") } } # choosing a place for the synonym filter when stemming is not easy # https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8 @@ -361,7 +361,7 @@ module Searchkick if options[:special_characters] == false settings[:analysis][:analyzer].each do |analyzer, analyzer_settings| - analyzer_settings[:filter].reject!{|f| f == "asciifolding" } + analyzer_settings[:filter].reject! { |f| f == "asciifolding" } end end @@ -380,7 +380,7 @@ module Searchkick mapping_options = Hash[ [:autocomplete, :suggest, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight] - .map{|type| [type, (options[type] || []).map(&:to_s)] } + .map { |type| [type, (options[type] || []).map(&:to_s)] } ] mapping_options.values.flatten.uniq.each do |field| @@ -457,7 +457,7 @@ module Searchkick # other def tokens(text, options = {}) - client.indices.analyze({text: text, index: name}.merge(options))["tokens"].map{|t| t["token"] } + client.indices.analyze({text: text, index: name}.merge(options))["tokens"].map { |t| t["token"] } end def klass_document_type(klass) @@ -488,24 +488,24 @@ module Searchkick # stringify fields # remove _id since search_id is used instead - source = source.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}.except("_id") + source = source.inject({}) { |memo, (k, v)| memo[k.to_s] = v; memo }.except("_id") # conversions conversions_field = options[:conversions] if conversions_field && source[conversions_field] - source[conversions_field] = source[conversions_field].map{|k, v| {query: k, count: v} } + source[conversions_field] = source[conversions_field].map { |k, v| {query: k, count: v} } end # hack to prevent generator field doesn't exist error (options[:suggest] || []).map(&:to_s).each do |field| - source[field] = nil if !source[field] + source[field] = nil unless source[field] end # locations (options[:locations] || []).map(&:to_s).each do |field| if source[field] if source[field].first.is_a?(Array) # array of arrays - source[field] = source[field].map{|a| a.map(&:to_f).reverse } + source[field] = source[field].map { |a| a.map(&:to_f).reverse } else source[field] = source[field].map(&:to_f).reverse end diff --git a/lib/searchkick/logging.rb b/lib/searchkick/logging.rb index 565cd4c..5c371b7 100644 --- a/lib/searchkick/logging.rb +++ b/lib/searchkick/logging.rb @@ -77,7 +77,7 @@ module Searchkick # no easy way to tell which host the client will use host = Searchkick.client.transport.hosts.first - debug " #{color(name, YELLOW, true)} curl #{host[:protocol]}://#{host[:host]}:#{host[:port]}/#{CGI.escape(index)}#{type ? "/#{type.map{|t| CGI.escape(t) }.join(",")}" : ""}/_search?pretty -d '#{payload[:query][:body].to_json}'" + debug " #{color(name, YELLOW, true)} curl #{host[:protocol]}://#{host[:host]}:#{host[:port]}/#{CGI.escape(index)}#{type ? "/#{type.map { |t| CGI.escape(t) }.join(',')}" : ''}/_search?pretty -d '#{payload[:query][:body].to_json}'" end def request(event) diff --git a/lib/searchkick/model.rb b/lib/searchkick/model.rb index d5cb008..b1c633f 100644 --- a/lib/searchkick/model.rb +++ b/lib/searchkick/model.rb @@ -11,14 +11,14 @@ module Searchkick class_eval do cattr_reader :searchkick_options, :searchkick_klass - callbacks = options.has_key?(:callbacks) ? options[:callbacks] : true + callbacks = options.key?(:callbacks) ? options[:callbacks] : true class_variable_set :@@searchkick_options, options.dup class_variable_set :@@searchkick_klass, self class_variable_set :@@searchkick_callbacks, callbacks class_variable_set :@@searchkick_index, options[:index_name] || [options[:index_prefix], model_name.plural, Searchkick.env].compact.join("_") - define_singleton_method(Searchkick.search_method_name) do |term = nil, options={}, &block| + define_singleton_method(Searchkick.search_method_name) do |term = nil, options = {}, &block| searchkick_index.search_model(self, term, options, &block) end extend Searchkick::Reindex # legacy for Searchjoy @@ -68,10 +68,10 @@ module Searchkick if callbacks callback_name = callbacks == :async ? :reindex_async : :reindex if respond_to?(:after_commit) - after_commit callback_name, if: proc{ self.class.search_callbacks? } + after_commit callback_name, if: proc { self.class.search_callbacks? } else - after_save callback_name, if: proc{ self.class.search_callbacks? } - after_destroy callback_name, if: proc{ self.class.search_callbacks? } + after_save callback_name, if: proc { self.class.search_callbacks? } + after_destroy callback_name, if: proc { self.class.search_callbacks? } end end diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 6c37362..fe4fedd 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -22,19 +22,19 @@ module Searchkick fields = if options[:fields] if options[:autocomplete] - options[:fields].map{|f| "#{f}.autocomplete" } + options[:fields].map { |f| "#{f}.autocomplete" } else options[:fields].map do |value| k, v = value.is_a?(Hash) ? value.to_a.first : [value, :word] k2, boost = k.to_s.split("^", 2) - field = "#{k2}.#{v == :word ? "analyzed" : v}" + field = "#{k2}.#{v == :word ? 'analyzed' : v}" boost_fields[field] = boost.to_f if boost field end end else if options[:autocomplete] - (searchkick_options[:autocomplete] || []).map{|f| "#{f}.autocomplete" } + (searchkick_options[:autocomplete] || []).map { |f| "#{f}.autocomplete" } else ["_all"] end @@ -44,7 +44,7 @@ module Searchkick # pagination page = [options[:page].to_i, 1].max - per_page = (options[:limit] || options[:per_page] || 100000).to_i + per_page = (options[:limit] || options[:per_page] || 100_000).to_i padding = [options[:padding].to_i, 0].max offset = options[:offset] || (page - 1) * per_page + padding @@ -104,7 +104,7 @@ module Searchkick shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search"), shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search2") ] - misspellings = options.has_key?(:misspellings) ? options[:misspellings] : options[:mispellings] # why not? + misspellings = options.key?(:misspellings) ? options[:misspellings] : options[:mispellings] # why not? if misspellings != false edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1 qs.concat [ @@ -120,7 +120,7 @@ module Searchkick qs << shared_options.merge(analyzer: analyzer) end - queries.concat(qs.map{|q| {match: {field => q}} }) + queries.concat(qs.map { |q| {match: {field => q}} }) end payload = { @@ -167,7 +167,7 @@ module Searchkick boost_by = options[:boost_by] || {} if boost_by.is_a?(Array) - boost_by = Hash[ boost_by.map{|f| [f, {factor: 1}] } ] + boost_by = Hash[boost_by.map { |f| [f, {factor: 1}] }] end if options[:boost] boost_by[options[:boost]] = {factor: 1} @@ -218,7 +218,7 @@ module Searchkick if !boost_by_distance[:field] || !boost_by_distance[:origin] raise ArgumentError, "boost_by_distance requires :field and :origin" end - function_params = boost_by_distance.select{|k,v| [:origin, :scale, :offset, :decay].include?(k) } + function_params = boost_by_distance.select { |k, v| [:origin, :scale, :offset, :decay].include?(k) } function_params[:origin] = function_params[:origin].reverse custom_filters << { boost_by_distance[:function] => { @@ -248,7 +248,7 @@ module Searchkick if options[:order] order = options[:order].is_a?(Enumerable) ? options[:order] : {options[:order] => :asc} # TODO id transformation for arrays - payload[:sort] = order.is_a?(Array) ? order : Hash[ order.map{|k, v| [k.to_s == "id" ? :_id : k, v] } ] + payload[:sort] = order.is_a?(Array) ? order : Hash[order.map { |k, v| [k.to_s == "id" ? :_id : k, v] }] end # filters @@ -263,14 +263,14 @@ module Searchkick if options[:facets] facets = options[:facets] || {} if facets.is_a?(Array) # convert to more advanced syntax - facets = Hash[ facets.map{|f| [f, {}] } ] + facets = Hash[facets.map { |f| [f, {}] }] end payload[:facets] = {} facets.each do |field, facet_options| # ask for extra facets due to # https://github.com/elasticsearch/elasticsearch/issues/1305 - size = facet_options[:limit] ? facet_options[:limit] + 150 : 100000 + size = facet_options[:limit] ? facet_options[:limit] + 150 : 100_000 if facet_options[:ranges] payload[:facets][field] = { @@ -300,7 +300,7 @@ module Searchkick # offset is not possible # http://elasticsearch-users.115913.n3.nabble.com/Is-pagination-possible-in-termsStatsFacet-td3422943.html - facet_options.deep_merge!(where: options[:where].reject{|k| k == field}) if options[:smart_facets] == true + facet_options.deep_merge!(where: options[:where].reject { |k| k == field }) if options[:smart_facets] == true facet_filters = where_filters(facet_options[:where]) if facet_filters.any? payload[:facets][field][:facet_filter] = { @@ -318,7 +318,7 @@ module Searchkick # intersection if options[:fields] - suggest_fields = suggest_fields & options[:fields].map{|v| (v.is_a?(Hash) ? v.keys.first : v).to_s.split("^", 2).first } + suggest_fields &= options[:fields].map { |v| (v.is_a?(Hash) ? v.keys.first : v).to_s.split("^", 2).first } end if suggest_fields.any? @@ -336,11 +336,11 @@ module Searchkick # highlight if options[:highlight] payload[:highlight] = { - fields: Hash[ fields.map{|f| [f, {}] } ] + fields: Hash[fields.map { |f| [f, {}] }] } if options[:highlight].is_a?(Hash) - if tag = options[:highlight][:tag] + if (tag = options[:highlight][:tag]) payload[:highlight][:pre_tags] = [tag] payload[:highlight][:post_tags] = [tag.to_s.gsub(/\A range_query}} diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index a436461..44e77fe 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -21,7 +21,7 @@ module Searchkick # results can have different types results = {} - hits.group_by{|hit, i| hit["_type"] }.each do |type, grouped_hits| + hits.group_by { |hit, i| hit["_type"] }.each do |type, grouped_hits| records = type.camelize.constantize if options[:includes] if defined?(NoBrainer::Document) && records < NoBrainer::Document @@ -35,7 +35,7 @@ module Searchkick # sort hits.map do |hit| - results[hit["_type"]].find{|r| r.id.to_s == hit["_id"].to_s } + results[hit["_type"]].find { |r| r.id.to_s == hit["_id"].to_s } end.compact else hits.map do |hit| @@ -54,7 +54,7 @@ module Searchkick def suggestions if response["suggest"] - response["suggest"].values.flat_map{|v| v.first["options"] }.sort_by{|o| -o["score"] }.map{|o| o["text"] }.uniq + response["suggest"].values.flat_map { |v| v.first["options"] }.sort_by { |o| -o["score"] }.map { |o| o["text"] }.uniq else raise "Pass `suggest: true` to the search method for suggestions" end @@ -68,7 +68,7 @@ module Searchkick each_with_hit.map do |model, hit| details = {} if hit["highlight"] - details[:highlight] = Hash[ hit["highlight"].map{|k, v| [(options[:json] ? k : k.sub(/\.analyzed\z/, "")).to_sym, v.first] } ] + details[:highlight] = Hash[hit["highlight"].map { |k, v| [(options[:json] ? k : k.sub(/\.analyzed\z/, "")).to_sym, v.first] }] end [model, details] end @@ -140,16 +140,16 @@ module Searchkick def results_query(records, grouped_hits) if records.respond_to?(:primary_key) && records.primary_key # ActiveRecord - records.where(records.primary_key => grouped_hits.map{|hit| hit["_id"] }).to_a + records.where(records.primary_key => grouped_hits.map { |hit| hit["_id"] }).to_a elsif records.respond_to?(:all) && records.all.respond_to?(:for_ids) # Mongoid 2 - records.all.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a + records.all.for_ids(grouped_hits.map { |hit| hit["_id"] }).to_a elsif records.respond_to?(:queryable) # Mongoid 3+ - records.queryable.for_ids(grouped_hits.map{|hit| hit["_id"] }).to_a + records.queryable.for_ids(grouped_hits.map { |hit| hit["_id"] }).to_a elsif records.respond_to?(:unscoped) && records.all.respond_to?(:preload) # Nobrainer - records.unscoped.where(:id.in => grouped_hits.map{|hit| hit["_id"] }).to_a + records.unscoped.where(:id.in => grouped_hits.map { |hit| hit["_id"] }).to_a else raise "Not sure how to load records" end diff --git a/lib/searchkick/tasks.rb b/lib/searchkick/tasks.rb index ffabbce..1c4d05a 100644 --- a/lib/searchkick/tasks.rb +++ b/lib/searchkick/tasks.rb @@ -3,13 +3,13 @@ require "rake" namespace :searchkick do desc "reindex model" - task :reindex => :environment do + task reindex: :environment do if ENV["CLASS"] klass = ENV["CLASS"].constantize rescue nil if klass klass.reindex else - abort "Could not find class: #{ENV["CLASS"]}" + abort "Could not find class: #{ENV['CLASS']}" end else abort "USAGE: rake searchkick:reindex CLASS=Product" @@ -20,7 +20,7 @@ namespace :searchkick do namespace :reindex do desc "reindex all models" - task :all => :environment do + task all: :environment do Rails.application.eager_load! Searchkick.models.each do |model| puts "Reindexing #{model.name}..." diff --git a/searchkick.gemspec b/searchkick.gemspec index d54cc6a..c08fd98 100644 --- a/searchkick.gemspec +++ b/searchkick.gemspec @@ -1,19 +1,19 @@ # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'searchkick/version' +require "searchkick/version" Gem::Specification.new do |spec| spec.name = "searchkick" spec.version = Searchkick::VERSION spec.authors = ["Andrew Kane"] spec.email = ["andrew@chartkick.com"] - spec.description = %q{Intelligent search made easy} - spec.summary = %q{Searchkick learns what your users are looking for. As more people search, it gets smarter and the results get better. It’s friendly for developers - and magical for your users.} + spec.description = "Intelligent search made easy" + spec.summary = "Searchkick learns what your users are looking for. As more people search, it gets smarter and the results get better. It’s friendly for developers - and magical for your users." spec.homepage = "https://github.com/ankane/searchkick" spec.license = "MIT" - spec.files = `git ls-files`.split($/) + spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] diff --git a/test/facets_test.rb b/test/facets_test.rb index 20cf18f..c888777 100644 --- a/test/facets_test.rb +++ b/test/facets_test.rb @@ -79,7 +79,7 @@ class TestFacets < Minitest::Test protected def store_facet(options) - Hash[ Product.search("Product", options).facets["store_id"]["terms"].map{|v| [v["term"], v["count"]] } ] + Hash[Product.search("Product", options).facets["store_id"]["terms"].map { |v| [v["term"], v["count"]] }] end end diff --git a/test/index_test.rb b/test/index_test.rb index f314589..61fe8d3 100644 --- a/test/index_test.rb +++ b/test/index_test.rb @@ -75,24 +75,24 @@ class TestIndex < Minitest::Test def test_bad_mapping Product.searchkick_index.delete store_names ["Product A"] - assert_raises(Searchkick::InvalidQueryError){ Product.search "test" } + assert_raises(Searchkick::InvalidQueryError) { Product.search "test" } ensure Product.reindex end def test_missing_index - assert_raises(Searchkick::MissingIndexError){ Product.search "test", index_name: "not_found" } + assert_raises(Searchkick::MissingIndexError) { Product.search "test", index_name: "not_found" } end def test_unsupported_version - raises_exception = lambda { |s| raise Elasticsearch::Transport::Transport::Error.new("[500] No query registered for [multi_match]") } + raises_exception = ->(s) { raise Elasticsearch::Transport::Transport::Error.new("[500] No query registered for [multi_match]") } Searchkick.client.stub :search, raises_exception do - assert_raises(Searchkick::UnsupportedVersionError){ Product.search("test") } + assert_raises(Searchkick::UnsupportedVersionError) { Product.search("test") } end end def test_invalid_query - assert_raises(Searchkick::InvalidQueryError){ Product.search(query: {}) } + assert_raises(Searchkick::InvalidQueryError) { Product.search(query: {}) } end if defined?(ActiveRecord) diff --git a/test/reindex_v2_job_test.rb b/test/reindex_v2_job_test.rb index b898a52..94c8bc4 100644 --- a/test/reindex_v2_job_test.rb +++ b/test/reindex_v2_job_test.rb @@ -3,7 +3,7 @@ require_relative "test_helper" class TestReindexV2Job < Minitest::Test def setup - skip if !defined?(ActiveJob) + skip unless defined?(ActiveJob) super Searchkick.disable_callbacks end diff --git a/test/sql_test.rb b/test/sql_test.rb index 97b5484..c98a22c 100644 --- a/test/sql_test.rb +++ b/test/sql_test.rb @@ -8,7 +8,7 @@ class TestSql < Minitest::Test end def test_no_limit - names = 20.times.map{|i| "Product #{i}" } + names = 20.times.map { |i| "Product #{i}" } store_names names assert_search "product", names end @@ -57,7 +57,7 @@ class TestSql < Minitest::Test {name: "Product A", store_id: 1, in_stock: true, backordered: true, created_at: now, orders_count: 4, user_ids: [1, 2, 3]}, {name: "Product B", store_id: 2, in_stock: true, backordered: false, created_at: now - 1, orders_count: 3, user_ids: [1]}, {name: "Product C", store_id: 3, in_stock: false, backordered: true, created_at: now - 2, orders_count: 2, user_ids: [1, 3]}, - {name: "Product D", store_id: 4, in_stock: false, backordered: false, created_at: now - 3, orders_count: 1}, + {name: "Product D", store_id: 4, in_stock: false, backordered: false, created_at: now - 3, orders_count: 1} ] assert_search "product", ["Product A", "Product B"], where: {in_stock: true} # date @@ -85,7 +85,7 @@ class TestSql < Minitest::Test assert_search "product", ["Product A", "Product C"], where: {user_ids: {all: [1, 3]}} assert_search "product", [], where: {user_ids: {all: [1, 2, 3, 4]}} # any / nested terms - assert_search "product", ["Product B", "Product C"], where: {user_ids: {not: [2], in: [1,3]}} + assert_search "product", ["Product B", "Product C"], where: {user_ids: {not: [2], in: [1, 3]}} # not / exists assert_search "product", ["Product D"], where: {user_ids: nil} assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {not: nil}} @@ -288,7 +288,7 @@ class TestSql < Minitest::Test def test_select store [{name: "Product A", store_id: 1}] result = Product.search("product", load: false, select: [:name, :store_id]).first - assert_equal %w[id name store_id], result.keys.reject{|k| k.start_with?("_") }.sort + assert_equal %w[id name store_id], result.keys.reject { |k| k.start_with?("_") }.sort assert_equal ["Product A"], result.name # this is not great end diff --git a/test/suggest_test.rb b/test/suggest_test.rb index 4750f6b..321114a 100644 --- a/test/suggest_test.rb +++ b/test/suggest_test.rb @@ -19,13 +19,13 @@ class TestSuggest < Minitest::Test def test_without_option store_names ["hi"] # needed to prevent ElasticsearchException - seed 668 - assert_raises(RuntimeError){ Product.search("hi").suggestions } + assert_raises(RuntimeError) { Product.search("hi").suggestions } end def test_multiple_fields store [ {name: "Shark", color: "Sharp"}, - {name: "Shark", color: "Sharp"}, + {name: "Shark", color: "Sharp"} ] assert_suggest_all "shar", ["shark", "sharp"] end diff --git a/test/test_helper.rb b/test/test_helper.rb index 289158f..3ce9941 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,7 +8,7 @@ ENV["RACK_ENV"] = "test" Minitest::Test = Minitest::Unit::TestCase unless defined?(Minitest::Test) -File.delete("elasticsearch.log") if File.exists?("elasticsearch.log") +File.delete("elasticsearch.log") if File.exist?("elasticsearch.log") Searchkick.client.transport.logger = Logger.new("elasticsearch.log") I18n.config.enforce_available_locales = true @@ -26,7 +26,7 @@ if defined?(Mongoid) module BSON class ObjectId def <=>(other) - self.data <=> other.data + data <=> other.data end end end @@ -223,7 +223,7 @@ class Animal searchkick \ autocomplete: [:name], suggest: [:name], - index_name: -> { "#{self.name.tableize}-#{Date.today.year}" } + index_name: -> { "#{name.tableize}-#{Date.today.year}" } # wordnet: true end @@ -252,7 +252,7 @@ class Minitest::Test end def store_names(names, klass = Product) - store names.map{|name| {name: name} }, klass + store names.map { |name| {name: name} }, klass end # no order -- libgit2 0.21.0