# frozen_string_literal: true

# rubocop:disable
# Include this file in your test by copying the following line to your test:
#   require File.expand_path(File.dirname(__FILE__) + "/test_helper")

require 'pathname'
lib = Pathname.new(
  File.expand_path('../../lib', File.dirname(__FILE__))
)
support = Pathname.new(
  File.expand_path('../spec/support', File.dirname(__FILE__))
)
$LOAD_PATH.unshift lib
$LOAD_PATH.unshift support
RAILS_ROOT = File.dirname(__FILE__)

require 'active_record'
require 'active_support'
require 'permanent_records'

module Rails
  def self.env
    'test'
  end
end

I18n.config.enforce_available_locales = true if I18n.config.respond_to?(:enforce_available_locales)

require 'logger'
ActiveRecord::Base.logger = Logger.new support.join('debug.log')
ActiveRecord::Base.configurations = YAML.load_file support.join('database.yml')
ActiveRecord::Base.establish_connection

load 'schema.rb' if File.exist?(support.join('schema.rb'))

Dir.glob(support.join('*.rb')).sort.each do |file|
  autoload File.basename(file).chomp('.rb').camelcase.intern, file
  require file
end

require 'database_cleaner'

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

  config.before do
    DatabaseCleaner.start
  end

  config.after do
    DatabaseCleaner.clean
  end
end
