diff --git a/test/boost_test.rb b/test/boost_test.rb index 79d9083..1689e67 100644 --- a/test/boost_test.rb +++ b/test/boost_test.rb @@ -171,6 +171,7 @@ class BoostTest < Minitest::Test end def test_boost_by_indices + setup_animal store_names ["Rex"], Animal store_names ["Rexx"], Product diff --git a/test/inheritance_test.rb b/test/inheritance_test.rb index 630e85d..b0b34f3 100644 --- a/test/inheritance_test.rb +++ b/test/inheritance_test.rb @@ -1,6 +1,11 @@ require_relative "test_helper" class InheritanceTest < Minitest::Test + def setup + super + setup_animal + end + def test_child_reindex store_names ["Max"], Cat assert Dog.reindex diff --git a/test/match_test.rb b/test/match_test.rb index 439ef6f..dff1cae 100644 --- a/test/match_test.rb +++ b/test/match_test.rb @@ -1,11 +1,6 @@ require_relative "test_helper" class MatchTest < Minitest::Test - def setup - super - setup_speaker - end - # exact def test_match @@ -230,6 +225,7 @@ class MatchTest < Minitest::Test end def test_dynamic_fields + setup_speaker store_names ["Red Bull"], Speaker assert_search "redbull", ["Red Bull"], {fields: [:name]}, Speaker end diff --git a/test/query_test.rb b/test/query_test.rb index ef21c22..649479a 100644 --- a/test/query_test.rb +++ b/test/query_test.rb @@ -1,11 +1,6 @@ require_relative "test_helper" class QueryTest < Minitest::Test - def setup - super - setup_speaker - end - def test_basic store_names ["Milk", "Apple"] query = Product.search("milk", body: {query: {match_all: {}}}) @@ -54,6 +49,7 @@ class QueryTest < Minitest::Test # nested def test_nested_search + setup_speaker store [{name: "Product A", aisle: {"id" => 1, "name" => "Frozen"}}], Speaker assert_search "frozen", ["Product A"], {fields: ["aisle.name"]}, Speaker end diff --git a/test/reindex_test.rb b/test/reindex_test.rb index 28cb160..3816a4e 100644 --- a/test/reindex_test.rb +++ b/test/reindex_test.rb @@ -321,4 +321,10 @@ class ReindexTest < Minitest::Test end assert_search "*", [] end + + def test_both_paths + Product.searchkick_index.delete if Product.searchkick_index.exists? + Product.reindex + Product.reindex # run twice for both index paths + end end diff --git a/test/should_index_test.rb b/test/should_index_test.rb index 9d5083d..c3531c2 100644 --- a/test/should_index_test.rb +++ b/test/should_index_test.rb @@ -7,7 +7,7 @@ class ShouldIndexTest < Minitest::Test end def test_default_true - assert Animal.new.should_index? + assert Store.new.should_index? end def test_change_to_true diff --git a/test/support/helpers.rb b/test/support/helpers.rb index 0315e00..133503e 100644 --- a/test/support/helpers.rb +++ b/test/support/helpers.rb @@ -2,32 +2,31 @@ class Minitest::Test include ActiveJob::TestHelper def setup - $setup_once ||= begin - # TODO improve - Product.searchkick_index.delete if Product.searchkick_index.exists? - Product.reindex - Product.reindex # run twice for both index paths - Product.create!(name: "Set mapping") - - Store.reindex - Animal.reindex + [Product, Store].each do |model| + setup_model(model) end - - Product.destroy_all - Store.destroy_all - Animal.destroy_all end protected + def setup_animal + setup_model(Animal) + end + def setup_region - $setup_region ||= (Region.reindex || true) - Region.destroy_all + setup_model(Region) end def setup_speaker - $setup_speaker ||= (Speaker.reindex || true) - Speaker.destroy_all + setup_model(Speaker) + end + + def setup_model(model) + # reindex once + ($setup_model ||= {})[model] ||= (model.reindex || true) + + # clear every time + model.destroy_all end def store(documents, model = default_model, reindex: true) -- libgit2 0.21.0