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
@@ -171,6 +171,7 @@ class BoostTest < Minitest::Test | @@ -171,6 +171,7 @@ class BoostTest < Minitest::Test | ||
171 | end | 171 | end |
172 | 172 | ||
173 | def test_boost_by_indices | 173 | def test_boost_by_indices |
174 | + setup_animal | ||
174 | store_names ["Rex"], Animal | 175 | store_names ["Rex"], Animal |
175 | store_names ["Rexx"], Product | 176 | store_names ["Rexx"], Product |
176 | 177 |
test/inheritance_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | class InheritanceTest < Minitest::Test | 3 | class InheritanceTest < Minitest::Test |
4 | + def setup | ||
5 | + super | ||
6 | + setup_animal | ||
7 | + end | ||
8 | + | ||
4 | def test_child_reindex | 9 | def test_child_reindex |
5 | store_names ["Max"], Cat | 10 | store_names ["Max"], Cat |
6 | assert Dog.reindex | 11 | assert Dog.reindex |
test/match_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | class MatchTest < Minitest::Test | 3 | class MatchTest < Minitest::Test |
4 | - def setup | ||
5 | - super | ||
6 | - setup_speaker | ||
7 | - end | ||
8 | - | ||
9 | # exact | 4 | # exact |
10 | 5 | ||
11 | def test_match | 6 | def test_match |
@@ -230,6 +225,7 @@ class MatchTest < Minitest::Test | @@ -230,6 +225,7 @@ class MatchTest < Minitest::Test | ||
230 | end | 225 | end |
231 | 226 | ||
232 | def test_dynamic_fields | 227 | def test_dynamic_fields |
228 | + setup_speaker | ||
233 | store_names ["Red Bull"], Speaker | 229 | store_names ["Red Bull"], Speaker |
234 | assert_search "redbull", ["Red Bull"], {fields: [:name]}, Speaker | 230 | assert_search "redbull", ["Red Bull"], {fields: [:name]}, Speaker |
235 | end | 231 | end |
test/query_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | class QueryTest < Minitest::Test | 3 | class QueryTest < Minitest::Test |
4 | - def setup | ||
5 | - super | ||
6 | - setup_speaker | ||
7 | - end | ||
8 | - | ||
9 | def test_basic | 4 | def test_basic |
10 | store_names ["Milk", "Apple"] | 5 | store_names ["Milk", "Apple"] |
11 | query = Product.search("milk", body: {query: {match_all: {}}}) | 6 | query = Product.search("milk", body: {query: {match_all: {}}}) |
@@ -54,6 +49,7 @@ class QueryTest < Minitest::Test | @@ -54,6 +49,7 @@ class QueryTest < Minitest::Test | ||
54 | # nested | 49 | # nested |
55 | 50 | ||
56 | def test_nested_search | 51 | def test_nested_search |
52 | + setup_speaker | ||
57 | store [{name: "Product A", aisle: {"id" => 1, "name" => "Frozen"}}], Speaker | 53 | store [{name: "Product A", aisle: {"id" => 1, "name" => "Frozen"}}], Speaker |
58 | assert_search "frozen", ["Product A"], {fields: ["aisle.name"]}, Speaker | 54 | assert_search "frozen", ["Product A"], {fields: ["aisle.name"]}, Speaker |
59 | end | 55 | end |
test/reindex_test.rb
@@ -321,4 +321,10 @@ class ReindexTest < Minitest::Test | @@ -321,4 +321,10 @@ class ReindexTest < Minitest::Test | ||
321 | end | 321 | end |
322 | assert_search "*", [] | 322 | assert_search "*", [] |
323 | end | 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 | end | 330 | end |
test/should_index_test.rb
@@ -7,7 +7,7 @@ class ShouldIndexTest < Minitest::Test | @@ -7,7 +7,7 @@ class ShouldIndexTest < Minitest::Test | ||
7 | end | 7 | end |
8 | 8 | ||
9 | def test_default_true | 9 | def test_default_true |
10 | - assert Animal.new.should_index? | 10 | + assert Store.new.should_index? |
11 | end | 11 | end |
12 | 12 | ||
13 | def test_change_to_true | 13 | def test_change_to_true |
test/support/helpers.rb
@@ -2,32 +2,31 @@ class Minitest::Test | @@ -2,32 +2,31 @@ class Minitest::Test | ||
2 | include ActiveJob::TestHelper | 2 | include ActiveJob::TestHelper |
3 | 3 | ||
4 | def setup | 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 | end | 7 | end |
15 | - | ||
16 | - Product.destroy_all | ||
17 | - Store.destroy_all | ||
18 | - Animal.destroy_all | ||
19 | end | 8 | end |
20 | 9 | ||
21 | protected | 10 | protected |
22 | 11 | ||
12 | + def setup_animal | ||
13 | + setup_model(Animal) | ||
14 | + end | ||
15 | + | ||
23 | def setup_region | 16 | def setup_region |
24 | - $setup_region ||= (Region.reindex || true) | ||
25 | - Region.destroy_all | 17 | + setup_model(Region) |
26 | end | 18 | end |
27 | 19 | ||
28 | def setup_speaker | 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 | end | 30 | end |
32 | 31 | ||
33 | def store(documents, model = default_model, reindex: true) | 32 | def store(documents, model = default_model, reindex: true) |