Skip to content

Commit

Permalink
Try to set up data in advance, then populate and clean up indexes aro…
Browse files Browse the repository at this point in the history
…und the tests, then clean up data
jsgoldstein committed Sep 5, 2023
1 parent 72963a1 commit 9884835
Showing 2 changed files with 25 additions and 15 deletions.
10 changes: 8 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 17 additions & 13 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9884835

Please sign in to comment.