Skip to content

Add test coverage for CombinedConfiguration option defaults, keys, and reload - #58378

Open
hammadxcm wants to merge 1 commit into
rails:mainfrom
hammadxcm:test-combined-configuration-coverage
Open

hammadxcm wants to merge 1 commit into
rails:mainfrom
hammadxcm:test-combined-configuration-coverage

Conversation

@hammadxcm

Copy link
Copy Markdown
Contributor

Summary

ActiveSupport::CombinedConfiguration composes the configuration backends and applies its own fallback when none of them holds a key, but that fallback had no tests.

All three backends cover option's default: keyword:

  • env_configuration_test.rb — static default, callable default, false/nil from the block, present key not triggering the default
  • dot_env_configuration_test.rb — same set
  • encrypted_configuration_test.rb — same set

combined_configuration_test.rb had none of them. It also never called #keys directly (only indirectly through the #inspect assertion), and never called #reload.

What this adds

Six tests, named to match the existing backend tests:

  • option with a missing key returns nil
  • option with a missing key returns a static default:
  • option with a missing key calls a callable default:
  • option with a present key returns the value without invoking the default: block
  • keys returns symbolized, de-duplicated keys drawn from every backend, not just the first
  • reload picks up a value added at runtime

No behavior changes — lib/ is untouched, so no CHANGELOG entry.

Verification

23 runs, 42 assertions, 0 failures, 0 errors, 0 skips

I checked the tests actually fail when the behavior regresses, by temporarily mutating combined_configuration.rb:

Mutation Result
option ignores default: 2 failures
keys returns only the first backend's keys 1 failure
reload becomes a no-op 1 error

rubocop is clean.

…and reload

`EnvConfiguration`, `DotEnvConfiguration`, and `EncryptedConfiguration` all
have tests for `option`'s `default:` keyword, but `CombinedConfiguration` --
which composes them and applies its own default when no backend holds the
key -- had none. `#keys` was only exercised indirectly through `#inspect`,
and `#reload` was not covered at all.

Add tests for the missing-key, static default, callable default, and
present-key-does-not-trigger-default cases, plus direct coverage of `#keys`
and `#reload`.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant