test/callbacks_test.rb in searchkick-2.0.3 vs test/callbacks_test.rb in searchkick-2.0.4
- old
+ new
@@ -22,6 +22,38 @@
store_names ["Product A", "Product B"]
end
Product.searchkick_index.refresh
assert_search "product", ["Product A", "Product B"]
end
+
+ def test_queue
+ skip unless defined?(ActiveJob) && defined?(Redis)
+
+ reindex_queue = Product.searchkick_index.reindex_queue
+ reindex_queue.clear
+
+ Searchkick.callbacks(:queue) do
+ store_names ["Product A", "Product B"]
+ end
+ Product.searchkick_index.refresh
+ assert_search "product", [], load: false
+ assert_equal 2, reindex_queue.length
+
+ Searchkick::ProcessQueueJob.perform_later(class_name: "Product")
+ Product.searchkick_index.refresh
+ assert_search "product", ["Product A", "Product B"], load: false
+ assert_equal 0, reindex_queue.length
+
+ Searchkick.callbacks(:queue) do
+ Product.where(name: "Product B").destroy_all
+ Product.create!(name: "Product C")
+ end
+ Product.searchkick_index.refresh
+ assert_search "product", ["Product A", "Product B"], load: false
+ assert_equal 2, reindex_queue.length
+
+ Searchkick::ProcessQueueJob.perform_later(class_name: "Product")
+ Product.searchkick_index.refresh
+ assert_search "product", ["Product A", "Product C"], load: false
+ assert_equal 0, reindex_queue.length
+ end
end