diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c24e0c0ed9bbac..7b8dccb6a0b34c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -130,14 +130,14 @@ def get(path, headers: nil, sign_with: nil, **args) if RUN_SEARCH_SPECS Chewy.strategy(:urgent) - search_data_manager.populate + search_data_manager.prepare_test_data end end config.after :suite do streaming_server_manager.stop - search_data_manager.destroy if RUN_SEARCH_SPECS + search_data_manager.cleanup_test_data if RUN_SEARCH_SPECS end config.around :each, type: :system do |example| @@ -158,6 +158,12 @@ def get(path, headers: nil, sign_with: nil, **args) self.use_transactional_tests = true end + config.around :each, type: :search do |example| + search_data_manager.populate_indexes + example.run + search_data_manager.remove_indexes + end + config.before(:each) do |example| unless example.metadata[:paperclip_processing] allow_any_instance_of(Paperclip::Attachment).to receive(:post_process).and_return(true) # rubocop:disable RSpec/AnyInstance diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e1a31e8af5c549..a6c6fc7bdd9420 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -131,16 +131,7 @@ def stop end class SearchDataManager - def indexes - [ - AccountsIndex, - PublicStatusesIndex, - StatusesIndex, - TagsIndex, - ] - end - - def populate + def prepare_test_data 4.times do |i| username = "search_test_account_#{i + 1}" account = Fabricate.create(:account, username: username, indexable: i.even?) @@ -152,18 +143,31 @@ def populate 3.times do |i| Fabricate.create(:tag, name: "search_test_tag_#{i}") end + end + + def indexes + [ + AccountsIndex, + PublicStatusesIndex, + StatusesIndex, + TagsIndex, + ] + end + def populate_indexes indexes.each do |index_class| index_class.purge! index_class.import! end end - def destroy + def remove_indexes + indexes.each(&:delete!) + end + + def cleanup_test_data Status.destroy_all Account.destroy_all Tag.destroy_all - - indexes.each(&:delete!) end end