Commit 7ca77ccbd760c010af67c526a465da7d939f1121

Authored by Nathan Smith
Committed by GitHub
1 parent d854c11c

Use `Searchkick::Results` as class for `model_name` when searching across multiple models (#1492)

Showing 2 changed files with 17 additions and 1 deletions   Show diff stats
lib/searchkick/results.rb
... ... @@ -71,7 +71,11 @@ module Searchkick
71 71 end
72 72  
73 73 def model_name
74   - klass.model_name
  74 + if klass.nil?
  75 + ActiveModel::Name.new(self.class, nil, 'Result')
  76 + else
  77 + klass.model_name
  78 + end
75 79 end
76 80  
77 81 def entry_name(options = {})
... ...
test/results_test.rb
... ... @@ -14,4 +14,16 @@ class ResultsTest < Minitest::Test
14 14 end
15 15 assert_equal 2, count
16 16 end
  17 +
  18 + def test_model_name_with_klass
  19 + store_names ["Product A", "Product B"]
  20 + results = Product.search("product")
  21 + assert_equal "Product", results.model_name.human
  22 + end
  23 +
  24 + def test_model_name_without_klass
  25 + store_names ["Product A", "Product B"]
  26 + results = Searchkick.search("product")
  27 + assert_equal "Result", results.model_name.human
  28 + end
17 29 end
... ...