Skip to content

Commit

Permalink
Quietly fail init if no database is present
Browse files Browse the repository at this point in the history
Failing loudly under these circs context isn't helpful because it
doesn't reflect a problem with the analytics setup; apps in CI often run
the asset precompilation step without a database present.
  • Loading branch information
duncanjbrown committed Sep 23, 2022
1 parent a64cf26 commit 678a644
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/dfe/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def self.initialize!
model.include(DfE::Analytics::Entities)
end
end
rescue ActiveRecord::ConnectionNotEstablished
Rails.logger.info('No database connection; DfE Analytics not initialized')
end

def self.enabled?
Expand Down
10 changes: 10 additions & 0 deletions spec/dfe/analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
table
end

context 'when no database connection is available' do
before do
allow(DfE::Analytics::Fields).to receive(:check!).and_raise(ActiveRecord::ConnectionNotEstablished)
end

it 'recovers and logs' do
expect { DfE::Analytics.initialize! }.not_to raise_error
end
end

context 'when the field lists are valid' do
before do
allow(DfE::Analytics).to receive(:allowlist).and_return(
Expand Down

0 comments on commit 678a644

Please sign in to comment.