Commit ff3dededf9ae97a1e7affdc8d30323728aef82ab
1 parent
69d49a3e
Exists in
master
Moved callbacks tests [skip ci]
Showing
2 changed files
with
49 additions
and
62 deletions
Show diff stats
test/callbacks_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | class CallbacksTest < Minitest::Test | 3 | class CallbacksTest < Minitest::Test |
4 | - def test_disable_callbacks_model | ||
5 | - store_names ["product a"] | ||
6 | - | 4 | + def test_false |
7 | Searchkick.callbacks(false) do | 5 | Searchkick.callbacks(false) do |
8 | - store_names ["product b"] | 6 | + store_names ["Product A", "Product B"] |
9 | end | 7 | end |
10 | - assert_search "product", ["product a"] | 8 | + assert_search "product", [] |
9 | + end | ||
11 | 10 | ||
11 | + def test_bulk | ||
12 | + Searchkick.callbacks(:bulk) do | ||
13 | + store_names ["Product A", "Product B"] | ||
14 | + end | ||
15 | + Product.search_index.refresh | ||
16 | + assert_search "product", ["Product A", "Product B"] | ||
17 | + end | ||
18 | + | ||
19 | + def test_queue | ||
20 | + # TODO figure out which earlier test leaves records in index | ||
12 | Product.reindex | 21 | Product.reindex |
13 | 22 | ||
14 | - assert_search "product", ["product a", "product b"] | 23 | + reindex_queue = Product.search_index.reindex_queue |
24 | + reindex_queue.clear | ||
25 | + | ||
26 | + Searchkick.callbacks(:queue) do | ||
27 | + store_names ["Product A", "Product B"] | ||
28 | + end | ||
29 | + Product.search_index.refresh | ||
30 | + assert_search "product", [], load: false, conversions: false | ||
31 | + assert_equal 2, reindex_queue.length | ||
32 | + | ||
33 | + perform_enqueued_jobs do | ||
34 | + Searchkick::ProcessQueueJob.perform_now(class_name: "Product") | ||
35 | + end | ||
36 | + Product.search_index.refresh | ||
37 | + assert_search "product", ["Product A", "Product B"], load: false | ||
38 | + assert_equal 0, reindex_queue.length | ||
39 | + | ||
40 | + Searchkick.callbacks(:queue) do | ||
41 | + Product.where(name: "Product B").destroy_all | ||
42 | + Product.create!(name: "Product C") | ||
43 | + end | ||
44 | + Product.search_index.refresh | ||
45 | + assert_search "product", ["Product A", "Product B"], load: false | ||
46 | + assert_equal 2, reindex_queue.length | ||
47 | + | ||
48 | + perform_enqueued_jobs do | ||
49 | + Searchkick::ProcessQueueJob.perform_now(class_name: "Product") | ||
50 | + end | ||
51 | + Product.search_index.refresh | ||
52 | + assert_search "product", ["Product A", "Product C"], load: false | ||
53 | + assert_equal 0, reindex_queue.length | ||
54 | + | ||
55 | + # ensure no error with empty queue | ||
56 | + Searchkick::ProcessQueueJob.perform_now(class_name: "Product") | ||
15 | end | 57 | end |
16 | 58 | ||
17 | - def test_disable_callbacks_global | 59 | + def test_disable_callbacks |
18 | # make sure callbacks default to on | 60 | # make sure callbacks default to on |
19 | assert Searchkick.callbacks? | 61 | assert Searchkick.callbacks? |
20 | 62 |
test/reindex_test.rb
@@ -255,61 +255,6 @@ class ReindexTest < Minitest::Test | @@ -255,61 +255,6 @@ class ReindexTest < Minitest::Test | ||
255 | assert_equal "wait only available in :async mode", error.message | 255 | assert_equal "wait only available in :async mode", error.message |
256 | end | 256 | end |
257 | 257 | ||
258 | - def test_callbacks_false | ||
259 | - Searchkick.callbacks(false) do | ||
260 | - store_names ["Product A", "Product B"] | ||
261 | - end | ||
262 | - assert_search "product", [] | ||
263 | - end | ||
264 | - | ||
265 | - def test_callbacks_bulk | ||
266 | - Searchkick.callbacks(:bulk) do | ||
267 | - store_names ["Product A", "Product B"] | ||
268 | - end | ||
269 | - Product.search_index.refresh | ||
270 | - assert_search "product", ["Product A", "Product B"] | ||
271 | - end | ||
272 | - | ||
273 | - def test_callbacks_queue | ||
274 | - # TODO figure out which earlier test leaves records in index | ||
275 | - Product.reindex | ||
276 | - | ||
277 | - reindex_queue = Product.search_index.reindex_queue | ||
278 | - reindex_queue.clear | ||
279 | - | ||
280 | - Searchkick.callbacks(:queue) do | ||
281 | - store_names ["Product A", "Product B"] | ||
282 | - end | ||
283 | - Product.search_index.refresh | ||
284 | - assert_search "product", [], load: false, conversions: false | ||
285 | - assert_equal 2, reindex_queue.length | ||
286 | - | ||
287 | - perform_enqueued_jobs do | ||
288 | - Searchkick::ProcessQueueJob.perform_now(class_name: "Product") | ||
289 | - end | ||
290 | - Product.search_index.refresh | ||
291 | - assert_search "product", ["Product A", "Product B"], load: false | ||
292 | - assert_equal 0, reindex_queue.length | ||
293 | - | ||
294 | - Searchkick.callbacks(:queue) do | ||
295 | - Product.where(name: "Product B").destroy_all | ||
296 | - Product.create!(name: "Product C") | ||
297 | - end | ||
298 | - Product.search_index.refresh | ||
299 | - assert_search "product", ["Product A", "Product B"], load: false | ||
300 | - assert_equal 2, reindex_queue.length | ||
301 | - | ||
302 | - perform_enqueued_jobs do | ||
303 | - Searchkick::ProcessQueueJob.perform_now(class_name: "Product") | ||
304 | - end | ||
305 | - Product.search_index.refresh | ||
306 | - assert_search "product", ["Product A", "Product C"], load: false | ||
307 | - assert_equal 0, reindex_queue.length | ||
308 | - | ||
309 | - # ensure no error with empty queue | ||
310 | - Searchkick::ProcessQueueJob.perform_now(class_name: "Product") | ||
311 | - end | ||
312 | - | ||
313 | def test_object_index | 258 | def test_object_index |
314 | error = assert_raises(Searchkick::Error) do | 259 | error = assert_raises(Searchkick::Error) do |
315 | Product.search_index.reindex(Object.new) | 260 | Product.search_index.reindex(Object.new) |