# spec/spec_helper.rb

load 'application.rb'

require 'rspec'
require 'factory_bot'
require 'database_cleaner'

ActiveRecord::Base.logger = Logger.new(File.open('db/test_database.log', 'a'))
ActiveRecord::Base.establish_connection(YAML.safe_load(File.open('db/database.yml'))['test'])
ActiveRecord::Migrator.migrate('db/migrate')

FactoryBot.definition_file_paths = [File.expand_path('../factories', __FILE__)]
FactoryBot.find_definitions

RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.around(:each) do |example|
    DatabaseCleaner.cleaning do
      example.run
    end
  end

  config.include FactoryBot::Syntax::Methods

  config.order = 'random'
end
