diff --git a/lib/searchkick.rb b/lib/searchkick.rb index 5e042c2..3479234 100644 --- a/lib/searchkick.rb +++ b/lib/searchkick.rb @@ -131,8 +131,9 @@ module Searchkick previous_value = callbacks_value begin self.callbacks_value = value - yield + result = yield indexer.perform if callbacks_value == :bulk + result ensure self.callbacks_value = previous_value end diff --git a/lib/searchkick/model.rb b/lib/searchkick/model.rb index 2fd6bfc..8091c82 100644 --- a/lib/searchkick/model.rb +++ b/lib/searchkick/model.rb @@ -37,7 +37,7 @@ module Searchkick alias_method :search_index, :searchkick_index unless method_defined?(:search_index) def searchkick_reindex(method_name = nil, full: false, **options) - # return unless Searchkick.callbacks? + return unless Searchkick.callbacks? scoped = (respond_to?(:current_scope) && respond_to?(:default_scoped) && current_scope && current_scope.to_sql != default_scoped.to_sql) || (respond_to?(:queryable) && queryable != unscoped.with_default_scope) diff --git a/test/reindex_v2_job_test.rb b/test/reindex_v2_job_test.rb index 0bf88b0..c497103 100644 --- a/test/reindex_v2_job_test.rb +++ b/test/reindex_v2_job_test.rb @@ -4,29 +4,24 @@ class ReindexV2JobTest < Minitest::Test def setup skip unless defined?(ActiveJob) super - Searchkick.disable_callbacks - end - - def teardown - Searchkick.enable_callbacks end def test_create - product = Product.create!(name: "Boom") - Product.searchkick_index.refresh + product = Searchkick.callbacks(false) { Product.create!(name: "Boom") } + Product.search_index.refresh assert_search "*", [] Searchkick::ReindexV2Job.perform_later("Product", product.id.to_s) - Product.searchkick_index.refresh + Product.search_index.refresh assert_search "*", ["Boom"] end def test_destroy - product = Product.create!(name: "Boom") + product = Searchkick.callbacks(false) { Product.create!(name: "Boom") } Product.reindex assert_search "*", ["Boom"] - product.destroy + Searchkick.callbacks(false) { product.destroy } Searchkick::ReindexV2Job.perform_later("Product", product.id.to_s) - Product.searchkick_index.refresh + Product.search_index.refresh assert_search "*", [] end end -- libgit2 0.21.0