Sha256: 7b5a904aba8f10c733247dfe3235c4bdedd3f241bf8c7652755877326dffc754

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'simplecov'
SimpleCov.start

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'rspec'
require 'active_record'
require 'schema_validations'
require 'schema_dev/rspec'

SchemaDev::Rspec.setup

RSpec.configure do |config|
  config.around(:each) do |example|
    remove_all_models

    ActiveRecord::Migration.suppress_messages do
      example.run
    ensure
      ActiveRecord::Base.connection.tables.each do |table|
        ActiveRecord::Migration.drop_table table, force: :cascade
      end
    end
  end
end

# avoid deprecation warnings
I18n.enforce_available_locales = true

Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }

def remove_all_models
  ActiveRecord::Base.descendants.each do |c|
    next if c == ActiveRecord::InternalMetadata
    next if c == ActiveRecord::SchemaMigration
    ActiveSupport::Dependencies.remove_constant c.name
  end
end

def define_schema(config={}, &block)
  ActiveRecord::Migration.suppress_messages do
    ActiveRecord::Schema.define do
      connection.tables.each do |table|
        drop_table table, force: :cascade
      end
      instance_eval &block
    end
  end
end

SimpleCov.command_name "[Ruby #{RUBY_VERSION} - ActiveRecord #{::ActiveRecord::VERSION::STRING}]"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
schema_validations-2.4.0 spec/spec_helper.rb