From 277c0c08f33fc09addb5e23440cf633e697dfc49 Mon Sep 17 00:00:00 2001 From: Washington Botelho Date: Wed, 18 May 2022 10:11:38 -0300 Subject: [PATCH] up: avoids user and password for local tests The `require` now is local avoiding require unnecessary driver. --- spec/support/database.rb | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/spec/support/database.rb b/spec/support/database.rb index d58e10a..cd19fbe 100644 --- a/spec/support/database.rb +++ b/spec/support/database.rb @@ -1,30 +1,24 @@ # frozen_string_literal: true -require 'mysql2' -require 'pg' - ENV['DB'] ||= 'mysql' -conn_params = { - database: :rating_test, - host: '127.0.0.1', -} +conn_params = { database: :rating_test, host: '127.0.0.1' } case ENV.fetch('DB', nil) when 'mysql' - client = Mysql2::Client.new(host: '127.0.0.1', username: :root) + require 'mysql2' + + client = Mysql2::Client.new(host: conn_params[:host], username: :root) + conn_params[:adapter] = :mysql2 conn_params[:username] = :root when 'postgres' - ENV['POSTGRES_USER'] ||= 'rating_user' - client = PG::Connection.new(host: '127.0.0.1', user: ENV.fetch('POSTGRES_USER', nil), - password: ENV.fetch('POSTGRES_PASSWORD', nil) - ) - conn_params.merge!( - adapter: :postgresql, - username: ENV.fetch('POSTGRES_USER', nil), - password: ENV.fetch('POSTGRES_PASSWORD', nil) - ) + require 'pg' + + client = PG::Connection.new(host: conn_params[:host], user: :postgres) + + conn_params[:adapter] = :postgresql + conn_params[:username] = :postgres end client.query('DROP DATABASE IF EXISTS rating_test;')