Sha256: 7c00bcab7ea664b87072bc33d51d4d97167a2edb34362391a8a84c5a2c8489fa

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

if ENV['TRAVIS']
  require 'simplecov'
  require 'coveralls'

  SimpleCov.formatter = Coveralls::SimpleCov::Formatter

  SimpleCov.start do
    add_filter "spec/"
  end
end

require "active_record"
require "arel-mysql-index-hint"
require "models"

$__arel_mysql_index_hint_sql_log__ = []

TEST_MYSQL_HOST = '127.0.0.1'
TEST_MYSQL_PORT = 3306
TEST_MYSQL_USER = 'root'
TEST_MYSQL_PASS = 'password'
MYSQL_CLI = "MYSQL_PWD=#{TEST_MYSQL_PASS} mysql -h #{TEST_MYSQL_HOST} -P #{TEST_MYSQL_PORT} -u #{TEST_MYSQL_USER}"

ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload|
  sql = payload[:sql]
  $__arel_mysql_index_hint_sql_log__ << sql.gsub(/\s+/, " ") if sql
end

RSpec.configure do |config|
  config.before(:all) do
    init_database

    ActiveRecord::Base.establish_connection(
      adapter: 'mysql2',
      database: 'arel_mysql_index_hint_test',
      host: TEST_MYSQL_HOST,
      port: TEST_MYSQL_PORT,
      username: TEST_MYSQL_USER,
      password: TEST_MYSQL_PASS,
    )
  end

  config.before(:each) do
    $__arel_mysql_index_hint_sql_log__.clear
  end
end

def init_database
  sql_file = File.expand_path('../init.sql', __FILE__)
  system("#{MYSQL_CLI} < #{sql_file}")
end

def sql_log
  $__arel_mysql_index_hint_sql_log__.dup
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arel-mysql-index-hint-0.2.1 spec/spec_helper.rb