[Tests] Clear elasticsearch before tests run

Previously they were only created if they didn't exist.
Data from previous test runs was still present.
This commit is contained in:
Earlopain 2023-09-08 19:17:47 +02:00
parent 499d447352
commit de4068ade8
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
3 changed files with 7 additions and 6 deletions

View File

@ -18,6 +18,9 @@ FileUtils.chdir APP_ROOT do
FileUtils.cp 'docker/danbooru_local_config.rb', 'config/danbooru_local_config.rb'
end
puts "== Creating elasticsearch indices ==\n"
system! "RAILS_ENV=development bin/rails runner '[Post, PostVersion].each { |model| model.__elasticsearch__.create_index! }'"
puts "\n== Preparing database =="
# Create the test database, since only development exists at this point
system! 'RAILS_ENV=test bin/rails db:create'

View File

@ -4,12 +4,6 @@ require "digest/md5"
require "net/http"
require "tempfile"
puts "== Creating elasticsearch indices ==\n"
Post.__elasticsearch__.create_index!
PostVersion.__elasticsearch__.create_index!
puts "== Seeding database with sample content ==\n"
# Uncomment to see detailed logs
# ActiveRecord::Base.logger = ActiveSupport::Logger.new($stdout)

View File

@ -37,6 +37,10 @@ end
BCrypt::Engine.send(:remove_const, :DEFAULT_COST)
BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
# Clear the elastic indicies completly
Post.__elasticsearch__.create_index!(force: true)
PostVersion.__elasticsearch__.create_index!(force: true)
class ActiveSupport::TestCase
include ActionDispatch::TestProcess::FixtureFile
include FactoryBot::Syntax::Methods