Commit 006857c4faa8a5418b21a4128b4b8c2ca12540bf
1 parent
ac5c952d
Exists in
master
and in
2 other branches
Improved tests start time
Showing
7 changed files
with
31 additions
and
28 deletions
Show diff stats
test/boost_test.rb
test/inheritance_test.rb
test/match_test.rb
1 | 1 | require_relative "test_helper" |
2 | 2 | |
3 | 3 | class MatchTest < Minitest::Test |
4 | - def setup | |
5 | - super | |
6 | - setup_speaker | |
7 | - end | |
8 | - | |
9 | 4 | # exact |
10 | 5 | |
11 | 6 | def test_match |
... | ... | @@ -230,6 +225,7 @@ class MatchTest < Minitest::Test |
230 | 225 | end |
231 | 226 | |
232 | 227 | def test_dynamic_fields |
228 | + setup_speaker | |
233 | 229 | store_names ["Red Bull"], Speaker |
234 | 230 | assert_search "redbull", ["Red Bull"], {fields: [:name]}, Speaker |
235 | 231 | end | ... | ... |
test/query_test.rb
1 | 1 | require_relative "test_helper" |
2 | 2 | |
3 | 3 | class QueryTest < Minitest::Test |
4 | - def setup | |
5 | - super | |
6 | - setup_speaker | |
7 | - end | |
8 | - | |
9 | 4 | def test_basic |
10 | 5 | store_names ["Milk", "Apple"] |
11 | 6 | query = Product.search("milk", body: {query: {match_all: {}}}) |
... | ... | @@ -54,6 +49,7 @@ class QueryTest < Minitest::Test |
54 | 49 | # nested |
55 | 50 | |
56 | 51 | def test_nested_search |
52 | + setup_speaker | |
57 | 53 | store [{name: "Product A", aisle: {"id" => 1, "name" => "Frozen"}}], Speaker |
58 | 54 | assert_search "frozen", ["Product A"], {fields: ["aisle.name"]}, Speaker |
59 | 55 | end | ... | ... |
test/reindex_test.rb
... | ... | @@ -321,4 +321,10 @@ class ReindexTest < Minitest::Test |
321 | 321 | end |
322 | 322 | assert_search "*", [] |
323 | 323 | end |
324 | + | |
325 | + def test_both_paths | |
326 | + Product.searchkick_index.delete if Product.searchkick_index.exists? | |
327 | + Product.reindex | |
328 | + Product.reindex # run twice for both index paths | |
329 | + end | |
324 | 330 | end | ... | ... |
test/should_index_test.rb
test/support/helpers.rb
... | ... | @@ -2,32 +2,31 @@ class Minitest::Test |
2 | 2 | include ActiveJob::TestHelper |
3 | 3 | |
4 | 4 | def setup |
5 | - $setup_once ||= begin | |
6 | - # TODO improve | |
7 | - Product.searchkick_index.delete if Product.searchkick_index.exists? | |
8 | - Product.reindex | |
9 | - Product.reindex # run twice for both index paths | |
10 | - Product.create!(name: "Set mapping") | |
11 | - | |
12 | - Store.reindex | |
13 | - Animal.reindex | |
5 | + [Product, Store].each do |model| | |
6 | + setup_model(model) | |
14 | 7 | end |
15 | - | |
16 | - Product.destroy_all | |
17 | - Store.destroy_all | |
18 | - Animal.destroy_all | |
19 | 8 | end |
20 | 9 | |
21 | 10 | protected |
22 | 11 | |
12 | + def setup_animal | |
13 | + setup_model(Animal) | |
14 | + end | |
15 | + | |
23 | 16 | def setup_region |
24 | - $setup_region ||= (Region.reindex || true) | |
25 | - Region.destroy_all | |
17 | + setup_model(Region) | |
26 | 18 | end |
27 | 19 | |
28 | 20 | def setup_speaker |
29 | - $setup_speaker ||= (Speaker.reindex || true) | |
30 | - Speaker.destroy_all | |
21 | + setup_model(Speaker) | |
22 | + end | |
23 | + | |
24 | + def setup_model(model) | |
25 | + # reindex once | |
26 | + ($setup_model ||= {})[model] ||= (model.reindex || true) | |
27 | + | |
28 | + # clear every time | |
29 | + model.destroy_all | |
31 | 30 | end |
32 | 31 | |
33 | 32 | def store(documents, model = default_model, reindex: true) | ... | ... |