Skip to content

Commit 2916ca0

Browse files
author
Aldo Ziflaj
committed
Test for aliased configs
1 parent 9447dd8 commit 2916ca0

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

spec/database_cleaner/active_record/base_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ module ActiveRecord
3838
expect(strategy.connection_hash).to eq({ 'database' => 'one' })
3939
end
4040

41+
context 'when the configs are aliased' do
42+
let(:other_db) { :other_db }
43+
let(:config_location) { 'spec/support/aliased-example.database.yml' }
44+
45+
it 'loads configs correctly' do
46+
strategy.db = my_db
47+
expected_hash = { 'database' => 'one',
48+
'encoding' => 'utf8',
49+
'reconnect' => true }
50+
expect(strategy.connection_hash).to eq(expected_hash)
51+
52+
strategy.db = other_db
53+
expected_hash.merge!('database' => 'two')
54+
expect(strategy.connection_hash).to eq(expected_hash)
55+
end
56+
end
57+
4158
context 'when ActiveRecord configuration contains a config for the given db' do
4259
if ::ActiveRecord.version >= Gem::Version.new('6.1')
4360
context 'ActiveRecord >= 6.1' do
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
default: &default
2+
encoding: utf8
3+
reconnect: true
4+
5+
my_db:
6+
<<: *default
7+
database: <%= "ONE".downcase %>
8+
9+
other_db:
10+
<<: *default
11+
database: <%= "TWO".downcase %>

0 commit comments

Comments
 (0)