diff --git a/test/support/helpers.rb b/test/support/helpers.rb index 6ce9f0e..11fa61e 100644 --- a/test/support/helpers.rb +++ b/test/support/helpers.rb @@ -26,19 +26,23 @@ class Minitest::Test ($setup_model ||= {})[model] ||= (model.reindex || true) # clear every time - model.destroy_all + Searchkick.callbacks(:bulk) do + model.destroy_all + end end def store(documents, model = default_model, reindex: true) if reindex - documents.shuffle.each do |document| - model.create!(document) + Searchkick.callbacks(:bulk) do + with_transaction(model) do + model.create!(documents.shuffle) + end end model.searchkick_index.refresh else Searchkick.callbacks(false) do - documents.shuffle.each do |document| - model.create!(document) + with_transaction(model) do + model.create!(documents.shuffle) end end end @@ -102,6 +106,14 @@ class Minitest::Test end end + def with_transaction(model, &block) + if model.respond_to?(:transaction) + model.transaction(&block) + else + yield + end + end + def activerecord? defined?(ActiveRecord) end -- libgit2 0.21.0