Sha256: 234c13b255ef3df71543f77ab2df8ac1bae0dde3aadc8c2d731f889ab58be5ac

Contents?: true

Size: 912 Bytes

Versions: 1

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

module DatabaseMacros
  # Run migrations in the test database
  def run_migration(&block)
    migration_class = if ActiveRecord::Migration.respond_to?(:[])
                        ActiveRecord::Migration[4.2]
                      else
                        ActiveRecord::Migration
                      end

    # Create a new migration class
    klass = Class.new(migration_class)

    # Create a new `up` that executes the argument
    klass.send(:define_method, :up) { instance_exec(&block) }

    # Create a new instance of it and execute its `up` method
    klass.new.up
  end

  def setup_database(opts = {})
    adapter = "#{opts[:adapter].capitalize}Adapter".constantize.new(database: opts[:database])
    adapter.establish_connection!
    adapter.reset_database!

    # Silence everything
    ActiveRecord::Base.logger = ActiveRecord::Migration.verbose = nil
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord_json_validator-3.0.0 spec/support/macros/database_macros.rb