diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index a2cb50e..fc1d213 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -6,8 +6,8 @@ module Searchkick delegate :body, :params, to: :@query delegate_missing_to :private_execute - def initialize(klass, term = "*", **options) - @query = Query.new(klass, term, **options) + def initialize(model, term = "*", **options) + @query = Query.new(model, term, **options) end # same as Active Record diff --git a/test/query_test.rb b/test/query_test.rb index f1c2f0c..e0658d0 100644 --- a/test/query_test.rb +++ b/test/query_test.rb @@ -75,8 +75,8 @@ class QueryTest < Minitest::Test assert_equal 2, result.length - result.group_by(&:class).each_pair do |klass, records| - assert records.first.association(associations[klass].first).loaded? + result.group_by(&:class).each_pair do |model, records| + assert records.first.association(associations[model].first).loaded? end end diff --git a/test/results_test.rb b/test/results_test.rb index 6f90a31..358cb07 100644 --- a/test/results_test.rb +++ b/test/results_test.rb @@ -45,13 +45,13 @@ class ResultsTest < Minitest::Test assert_equal 2, count end - def test_model_name_with_klass + def test_model_name_with_model store_names ["Product A", "Product B"] results = Product.search("product") assert_equal "Product", results.model_name.human end - def test_model_name_without_klass + def test_model_name_without_model store_names ["Product A", "Product B"] results = Searchkick.search("product") assert_equal "Result", results.model_name.human diff --git a/test/support/helpers.rb b/test/support/helpers.rb index 99bd222..1aa3201 100644 --- a/test/support/helpers.rb +++ b/test/support/helpers.rb @@ -10,48 +10,48 @@ class Minitest::Test protected - def store(documents, klass = default_model, reindex: true) + def store(documents, model = default_model, reindex: true) if reindex documents.shuffle.each do |document| - klass.create!(document) + model.create!(document) end - klass.searchkick_index.refresh + model.searchkick_index.refresh else Searchkick.callbacks(false) do documents.shuffle.each do |document| - klass.create!(document) + model.create!(document) end end end end - def store_names(names, klass = default_model, reindex: true) - store names.map { |name| {name: name} }, klass, reindex: reindex + def store_names(names, model = default_model, reindex: true) + store names.map { |name| {name: name} }, model, reindex: reindex end # no order - def assert_search(term, expected, options = {}, klass = default_model) - assert_equal expected.sort, klass.search(term, **options).map(&:name).sort + def assert_search(term, expected, options = {}, model = default_model) + assert_equal expected.sort, model.search(term, **options).map(&:name).sort end - def assert_order(term, expected, options = {}, klass = default_model) - assert_equal expected, klass.search(term, **options).map(&:name) + def assert_order(term, expected, options = {}, model = default_model) + assert_equal expected, model.search(term, **options).map(&:name) end - def assert_equal_scores(term, options = {}, klass = default_model) - assert_equal 1, klass.search(term, **options).hits.map { |a| a["_score"] }.uniq.size + def assert_equal_scores(term, options = {}, model = default_model) + assert_equal 1, model.search(term, **options).hits.map { |a| a["_score"] }.uniq.size end - def assert_first(term, expected, options = {}, klass = default_model) - assert_equal expected, klass.search(term, **options).map(&:name).first + def assert_first(term, expected, options = {}, model = default_model) + assert_equal expected, model.search(term, **options).map(&:name).first end - def assert_misspellings(term, expected, misspellings = {}, klass = default_model) + def assert_misspellings(term, expected, misspellings = {}, model = default_model) options = { fields: [:name, :color], misspellings: misspellings } - assert_search(term, expected, options, klass) + assert_search(term, expected, options, model) end def assert_warns(message) @@ -61,15 +61,15 @@ class Minitest::Test assert_match "[searchkick] WARNING: #{message}", stderr end - def with_options(options, klass = default_model) - previous_options = klass.searchkick_options.dup + def with_options(options, model = default_model) + previous_options = model.searchkick_options.dup begin - klass.searchkick_options.merge!(options) - klass.reindex + model.searchkick_options.merge!(options) + model.reindex yield ensure - klass.searchkick_options.clear - klass.searchkick_options.merge!(previous_options) + model.searchkick_options.clear + model.searchkick_options.merge!(previous_options) end end -- libgit2 0.21.0