Commit 5569ac606b62ef2158f41f8d9f1c4dbfb272a7e5

Authored by Andrew Kane
1 parent 460f3891

Fixed index name for inherited models - fixes #1548

  1 +## 5.0.2 (unreleased)
  2 +
  3 +- Fixed index name for inherited models
  4 +
1 ## 5.0.1 (2022-02-27) 5 ## 5.0.1 (2022-02-27)
2 6
3 - Prefer `mode: :async` over `async: true` for full reindex 7 - Prefer `mode: :async` over `async: true` for full reindex
lib/searchkick/model.rb
@@ -88,9 +88,9 @@ module Searchkick @@ -88,9 +88,9 @@ module Searchkick
88 if options[:index_name] 88 if options[:index_name]
89 options[:index_name] 89 options[:index_name]
90 elsif options[:index_prefix].respond_to?(:call) 90 elsif options[:index_prefix].respond_to?(:call)
91 - -> { [options[:index_prefix].call, model_name.plural, Searchkick.env, Searchkick.index_suffix].compact.join("_") } 91 + -> { [options[:index_prefix].call, searchkick_klass.model_name.plural, Searchkick.env, Searchkick.index_suffix].compact.join("_") }
92 else 92 else
93 - [options.key?(:index_prefix) ? options[:index_prefix] : Searchkick.index_prefix, model_name.plural, Searchkick.env, Searchkick.index_suffix].compact.join("_") 93 + [options.key?(:index_prefix) ? options[:index_prefix] : Searchkick.index_prefix, searchkick_klass.model_name.plural, Searchkick.env, Searchkick.index_suffix].compact.join("_")
94 end 94 end
95 end 95 end
96 end 96 end
test/inheritance_test.rb
@@ -13,7 +13,7 @@ class InheritanceTest < Minitest::Test @@ -13,7 +13,7 @@ class InheritanceTest < Minitest::Test
13 end 13 end
14 14
15 def test_child_index_name 15 def test_child_index_name
16 - assert_equal "animals-#{Date.today.year}#{ENV["TEST_ENV_NUMBER"]}", Dog.searchkick_index.name 16 + assert_equal "animals_test#{ENV["TEST_ENV_NUMBER"]}", Dog.searchkick_index.name
17 end 17 end
18 18
19 def test_child_search 19 def test_child_search
test/models/animal.rb
@@ -2,6 +2,5 @@ class Animal @@ -2,6 +2,5 @@ class Animal
2 searchkick \ 2 searchkick \
3 inheritance: true, 3 inheritance: true,
4 text_start: [:name], 4 text_start: [:name],
5 - suggest: [:name],  
6 - index_name: -> { "#{name.tableize}-#{Date.today.year}#{Searchkick.index_suffix}" } 5 + suggest: [:name]
7 end 6 end