Sha256: cbf37fe9ab5fe50249ca869b9673694d29388f42b06bf714eaf20b93c374801e

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require 'torque-postgresql'
require 'database_cleaner'
require 'factory_bot'
require 'dotenv'
require 'faker'
require 'rspec'
require 'byebug'

Dotenv.load

ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || {
  adapter: 'postgresql',
  username: 'travis',
  port: 5433,
})

cache = ActiveRecord::Base.connection.schema_cache
cleaner = ->() do
  cache.instance_variable_set(:@inheritance_loaded, false)
  cache.instance_variable_set(:@inheritance_dependencies, {})
  cache.instance_variable_set(:@inheritance_associations, {})
end

load File.join('schema.rb')
Dir.glob(File.join('spec', '{models,factories,mocks}', '*.rb')) do |file|
  require file[5..-4]
end

cleaner.call
I18n.load_path << Pathname.pwd.join('spec', 'en.yml')
RSpec.configure do |config|
  config.extend Mocks::CreateTable
  config.include Mocks::CacheQuery
  config.include FactoryBot::Syntax::Methods

  config.formatter = :documentation
  config.color     = true
  config.tty       = true

  # Handles acton before rspec initialize
  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.strategy = :transaction
  end

  config.before(:each, js: true) do
    DatabaseCleaner.strategy = :truncation
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.before(:each) do
    cleaner.call
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
torque-postgresql-2.2.3 spec/spec_helper.rb