rating/spec/support/database.rb

28 lines
665 B
Ruby
Raw Permalink Normal View History

2022-04-21 23:44:05 +00:00
# frozen_string_literal: true
ENV['DB'] ||= 'postgres'
2022-04-21 23:44:05 +00:00
conn_params = { database: :rating_test, host: '127.0.0.1' }
2022-04-21 23:44:05 +00:00
case ENV.fetch('DB')
2022-04-21 23:44:05 +00:00
when 'mysql'
require 'mysql2'
client = Mysql2::Client.new(host: conn_params[:host], username: :root)
2022-04-21 23:44:05 +00:00
conn_params[:adapter] = :mysql2
conn_params[:username] = :root
when 'postgres'
require 'pg'
client = PG::Connection.new(host: conn_params[:host], password: '', user: :postgres)
conn_params[:adapter] = :postgresql
conn_params[:username] = :postgres
2022-04-21 23:44:05 +00:00
end
client.query('DROP DATABASE IF EXISTS rating_test;')
client.query('CREATE DATABASE rating_test;')
ActiveRecord::Base.establish_connection(conn_params)