diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index 6c0b2d4..977baf5 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -71,7 +71,11 @@ module Searchkick end def model_name - klass.model_name + if klass.nil? + ActiveModel::Name.new(self.class, nil, 'Result') + else + klass.model_name + end end def entry_name(options = {}) diff --git a/test/results_test.rb b/test/results_test.rb index d34eaea..c6f3881 100644 --- a/test/results_test.rb +++ b/test/results_test.rb @@ -14,4 +14,16 @@ class ResultsTest < Minitest::Test end assert_equal 2, count end + + def test_model_name_with_klass + store_names ["Product A", "Product B"] + results = Product.search("product") + assert_equal "Product", results.model_name.human + end + + def test_model_name_without_klass + store_names ["Product A", "Product B"] + results = Searchkick.search("product") + assert_equal "Result", results.model_name.human + end end -- libgit2 0.21.0