Skip to content

Commit 6fa91dd

Browse files
committed
Fix KeyError when shared key has no adapter in database.yml
Follow-up #1605 (comment)
1 parent 7fc1595 commit 6fa91dd

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/rubocop/cop/mixin/database_type_resolvable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def database_yaml(environment = 'development')
5959
end
6060

6161
def database_adapter
62-
database_yaml['adapter'] || database_yaml('shared')&.fetch('adapter') || database_yaml.first.last['adapter']
62+
database_yaml['adapter'] || database_yaml('shared')&.dig('adapter') || database_yaml.first.last['adapter']
6363
end
6464
end
6565
end

spec/rubocop/cop/rails/bulk_change_table_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,19 @@ def change
708708
it_behaves_like 'no offense for postgresql'
709709
end
710710
end
711+
712+
context 'without adapter configuration' do
713+
let(:yaml) do
714+
{
715+
'shared' => {},
716+
'development' => {
717+
'foo' => 'bar'
718+
}
719+
}
720+
end
721+
722+
it_behaves_like 'no offense'
723+
end
711724
end
712725

713726
context 'invalid (e.g. ERB)' do

0 commit comments

Comments
 (0)