require 'spec_helper' require 'flydata-core/postgresql/config' module FlydataCore module Postgresql describe Config do let(:base_conf) do { 'host' => 'localhost', 'port' => 1234, 'username' => 'testuser', 'password' => 'password', 'database' => 'testdb', } end let(:conf) { base_conf } describe '.build_db_opts' do subject { described_class.build_db_opts(conf) } context 'with basic conf' do it { is_expected.to eq( host: 'localhost', port: 1234, username: 'testuser', password: 'password', database: 'testdb', user: 'testuser', dbname: 'testdb', ) } end context 'with conf having dbname' do let(:conf) { base_conf.merge('dbname' => 'testdb2') } it { is_expected.to eq( host: 'localhost', port: 1234, username: 'testuser', password: 'password', database: 'testdb', user: 'testuser', dbname: 'testdb2', ) } end end describe '.opts_for_pg' do subject { described_class.opts_for_pg(conf) } context 'with basic conf' do it { is_expected.to eq( host: 'localhost', port: 1234, password: 'password', user: 'testuser', dbname: 'testdb', ) } end context 'with conf having dbname' do let(:conf) { base_conf.merge('dbname' => 'testdb2') } it { is_expected.to eq( host: 'localhost', port: 1234, password: 'password', user: 'testuser', dbname: 'testdb2', ) } end context 'with conf having schema' do let(:conf) { base_conf.merge('schema' => 'dev_schema') } it { is_expected.to eq( host: 'localhost', port: 1234, password: 'password', user: 'testuser', dbname: 'testdb', ) } end end end end end