Commit 4746a50b7e3f8f561b5d8d6a9dab37cbbde73dd9
1 parent
5f9515a4
Exists in
master
and in
9 other branches
Improved tests
Showing
2 changed files
with
23 additions
and
30 deletions
Show diff stats
test/reindex_test.rb
... | ... | @@ -2,23 +2,17 @@ require_relative "test_helper" |
2 | 2 | |
3 | 3 | class ReindexTest < Minitest::Test |
4 | 4 | def test_record_inline |
5 | - Searchkick.callbacks(false) do | |
6 | - store_names ["Product A", "Product B"] | |
7 | - end | |
8 | - assert_search "product", [] | |
5 | + store_names ["Product A", "Product B"], reindex: false | |
9 | 6 | |
10 | - product = Product.find_by(name: "Product A") | |
7 | + product = Product.find_by!(name: "Product A") | |
11 | 8 | product.reindex(refresh: true) |
12 | 9 | assert_search "product", ["Product A"] |
13 | 10 | end |
14 | 11 | |
15 | 12 | def test_record_async |
16 | - Searchkick.callbacks(false) do | |
17 | - store_names ["Product A", "Product B"] | |
18 | - end | |
19 | - assert_search "product", [] | |
13 | + store_names ["Product A", "Product B"], reindex: false | |
20 | 14 | |
21 | - product = Product.find_by(name: "Product A") | |
15 | + product = Product.find_by!(name: "Product A") | |
22 | 16 | product.reindex(mode: :async) |
23 | 17 | Product.search_index.refresh |
24 | 18 | assert_search "product", ["Product A"] |
... | ... | @@ -30,12 +24,9 @@ class ReindexTest < Minitest::Test |
30 | 24 | reindex_queue = Product.searchkick_index.reindex_queue |
31 | 25 | reindex_queue.clear |
32 | 26 | |
33 | - Searchkick.callbacks(false) do | |
34 | - store_names ["Product A", "Product B"] | |
35 | - end | |
36 | - assert_search "product", [] | |
27 | + store_names ["Product A", "Product B"], reindex: false | |
37 | 28 | |
38 | - product = Product.find_by(name: "Product A") | |
29 | + product = Product.find_by!(name: "Product A") | |
39 | 30 | product.reindex(mode: :queue) |
40 | 31 | Product.search_index.refresh |
41 | 32 | assert_search "product", [] |
... | ... | @@ -49,9 +40,7 @@ class ReindexTest < Minitest::Test |
49 | 40 | skip if nobrainer? || cequel? |
50 | 41 | |
51 | 42 | store_names ["Product A"] |
52 | - Searchkick.callbacks(false) do | |
53 | - store_names ["Product B", "Product C"] | |
54 | - end | |
43 | + store_names ["Product B", "Product C"], reindex: false | |
55 | 44 | Product.where(name: "Product B").reindex(refresh: true) |
56 | 45 | assert_search "product", ["Product A", "Product B"] |
57 | 46 | end |
... | ... | @@ -77,9 +66,7 @@ class ReindexTest < Minitest::Test |
77 | 66 | def test_full_async |
78 | 67 | skip unless defined?(ActiveJob) |
79 | 68 | |
80 | - Searchkick.callbacks(false) do | |
81 | - store_names ["Product A"] | |
82 | - end | |
69 | + store_names ["Product A"], reindex: false | |
83 | 70 | reindex = Product.reindex(async: true) |
84 | 71 | assert_search "product", [], conversions: false |
85 | 72 | |
... | ... | @@ -98,9 +85,7 @@ class ReindexTest < Minitest::Test |
98 | 85 | def test_full_async_wait |
99 | 86 | skip unless defined?(ActiveJob) && defined?(Redis) |
100 | 87 | |
101 | - Searchkick.callbacks(false) do | |
102 | - store_names ["Product A"] | |
103 | - end | |
88 | + store_names ["Product A"], reindex: false | |
104 | 89 | |
105 | 90 | capture_io do |
106 | 91 | Product.reindex(async: {wait: true}) | ... | ... |
test/test_helper.rb
... | ... | @@ -71,15 +71,23 @@ class Minitest::Test |
71 | 71 | |
72 | 72 | protected |
73 | 73 | |
74 | - def store(documents, klass = Product) | |
75 | - documents.shuffle.each do |document| | |
76 | - klass.create!(document) | |
74 | + def store(documents, klass = Product, reindex: true) | |
75 | + if reindex | |
76 | + documents.shuffle.each do |document| | |
77 | + klass.create!(document) | |
78 | + end | |
79 | + klass.searchkick_index.refresh | |
80 | + else | |
81 | + Searchkick.callbacks(false) do | |
82 | + documents.shuffle.each do |document| | |
83 | + klass.create!(document) | |
84 | + end | |
85 | + end | |
77 | 86 | end |
78 | - klass.searchkick_index.refresh | |
79 | 87 | end |
80 | 88 | |
81 | - def store_names(names, klass = Product) | |
82 | - store names.map { |name| {name: name} }, klass | |
89 | + def store_names(names, klass = Product, reindex: true) | |
90 | + store names.map { |name| {name: name} }, klass, reindex: reindex | |
83 | 91 | end |
84 | 92 | |
85 | 93 | # no order | ... | ... |