Skip to content

Commit

Permalink
Fix "async" config setup
Browse files Browse the repository at this point in the history
DfE::Analytics initialisation code was ignoring the
"config.async = false" option when provided, and setting it to
"config.async = true" anyways.

This was caused by the conditional assignment operator "||=".

"foo ||= true" does set 'foo' as 'true' if it was either 'nil' or
'false'.
  • Loading branch information
scruti committed Dec 4, 2024
1 parent 0f5cb40 commit c84b132
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dfe/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def self.configure
config.bigquery_timeout ||= 120
config.environment ||= ENV.fetch('RAILS_ENV', 'development')
config.log_only ||= false
config.async ||= true
config.queue ||= :default
config.user_identifier ||= proc { |user| user&.id }
config.entity_table_checks_enabled ||= false
Expand All @@ -84,6 +83,7 @@ def self.configure
config.azure_federated_auth ||= false
config.excluded_paths ||= []
config.excluded_models_proc ||= proc { |_model| false }
config.async = true if config.async.nil?

return unless config.azure_federated_auth

Expand Down
22 changes: 22 additions & 0 deletions spec/dfe/analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@
end
end

describe '.async?' do
context 'when the async config has been set to true' do
before do
described_class.configure { |config| config.async = true }
end

it 'returns true' do
expect(described_class.async?).to be true
end
end

context 'when the async config has been set to false' do
before do
described_class.configure { |config| config.async = false }
end

it 'returns false' do
expect(described_class.async?).to be false
end
end
end

describe '.extract_model_attributes' do
with_model :Candidate do
table do |t|
Expand Down

0 comments on commit c84b132

Please sign in to comment.