Commit 006857c4faa8a5418b21a4128b4b8c2ca12540bf

Authored by Andrew Kane
1 parent ac5c952d

Improved tests start time

test/boost_test.rb
... ... @@ -171,6 +171,7 @@ class BoostTest < Minitest::Test
171 171 end
172 172  
173 173 def test_boost_by_indices
  174 + setup_animal
174 175 store_names ["Rex"], Animal
175 176 store_names ["Rexx"], Product
176 177  
... ...
test/inheritance_test.rb
1 1 require_relative "test_helper"
2 2  
3 3 class InheritanceTest < Minitest::Test
  4 + def setup
  5 + super
  6 + setup_animal
  7 + end
  8 +
4 9 def test_child_reindex
5 10 store_names ["Max"], Cat
6 11 assert Dog.reindex
... ...
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 &lt; 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 &lt; 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 &lt; 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
... ... @@ -7,7 +7,7 @@ class ShouldIndexTest &lt; Minitest::Test
7 7 end
8 8  
9 9 def test_default_true
10   - assert Animal.new.should_index?
  10 + assert Store.new.should_index?
11 11 end
12 12  
13 13 def test_change_to_true
... ...
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)
... ...