Skip to content

Add 5 missing Config DEFAULTS entries and fix autosetup initialization (#3395)#3539

Open
Rolling2405 wants to merge 4 commits intoDARIAEngineering:mainfrom
Rolling2405:feature/config-defaults
Open

Add 5 missing Config DEFAULTS entries and fix autosetup initialization (#3395)#3539
Rolling2405 wants to merge 4 commits intoDARIAEngineering:mainfrom
Rolling2405:feature/config-defaults

Conversation

@Rolling2405
Copy link
Copy Markdown
Contributor

@Rolling2405 Rolling2405 commented Apr 8, 2026

I rule and have completed some work on Case Manager that's ready for review!

This adds missing default configuration entries and fixes the auto-setup method so that new funds get all the expected Config records created automatically with sensible defaults.

This pull request makes the following changes:

  • Add Config.autosetup method that creates missing config entries from a defaults hash
  • Correctly handle boolean defaults (true"yes", false"no") to avoid Ruby's false.present? gotcha
  • Use config.update! (bang) for fail-fast error reporting
  • Prevent N+1 queries by preloading existing keys with pluck(:config_key).to_set
  • Method is idempotent and safe to run multiple times

It relates to the following issue #s:

For reviewer:

  • Adjust the title to explain what it does for the notification email to the listserv.
  • Tag this PR:
    • feature if it contains a feature, fix, or similar. This is anything that contains a user-facing fix in some way, such as frontend changes, alterations to backend behavior, or bug fixes.
    • dependencies if it contains library upgrades or similar. This is anything that upgrades any dependency, such as a Gemfile update or npm package upgrade.
  • If it contains neither, no need to tag this PR.

Rolling2405 and others added 4 commits April 7, 2026 18:33
Missing keys added to Config::DEFAULTS:
- procedure_type: nil (list field, same as other list fields)
- show_patient_identifier: false (toggle, off by default)
- display_practical_support_attachment_url: false (toggle, off by default)
- display_practical_support_waiver: false (toggle, off by default)
- display_consent_to_survey: false (toggle, off by default)

These 5 config_key enum entries (21-25) existed but had no DEFAULTS,
causing Config methods to potentially return unexpected values for
new fund setups.

Also improved autosetup to populate default values from DEFAULTS hash
when creating new config entries, so new funds start with correct
initial configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix false.present? bug: boolean false defaults were being skipped
  Changed to 'unless default_value.nil?' so false values are processed
- Translate boolean defaults: true -> 'Yes', false -> 'No' (DARIA convention)
- Fix silent update failures: config.update -> config.update!
- Fix N+1 queries: preload existing keys with pluck().to_set instead of
  running a COUNT query per config key
- Add comprehensive autosetup tests:
  - Boolean false defaults not skipped
  - Boolean true defaults translated to 'Yes'
  - Idempotency (running twice = no duplicates)
  - Existing values not overridden
  - String defaults set correctly

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The codebase consistently uses lowercase 'yes'/'no' for boolean config
values. Changed autosetup to use 'yes'/'no' instead of 'Yes'/'No'.
Also fixed test referencing non-existent 'shared_reset' config key.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add tests for:
- ALL 5 new defaults present in DEFAULTS hash (procedure_type, show_patient_identifier, etc.)
- Every config_key has a corresponding DEFAULTS entry
- Autosetup with nil default creates config without config_value
- procedure_type default is specifically nil (no preset options)
- Numeric defaults are stored as string representations
- Autosetup handles empty string edge cases correctly

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce default values for Configs

1 participant