Problem this feature will solve
The encrypt matcher today exposes deterministic, downcase, and ignore_case, but ActiveRecord::Encryption accepts several more options that are part of the declared contract of an encrypted attribute:
previous: — key rotation entries.
key: and key_provider: — per-attribute key/provider overrides.
compressor: (Rails 7.1+) and compress: false.
support_unencrypted_data: true — was global only, became per-attribute in Rails 8.1.
context_properties: — encryption-context overrides.
None of these can be expressed in a matcher today, so changes to them are not caught by specs.
Desired solution
New qualifiers mirroring the option names:
it do
should encrypt(:ssn).
deterministic(true).
with_key_provider(MyKeyProvider).
with_compressor(MyCompressor).
supporting_unencrypted_data
end
Naming is open. Following the matcher's existing with_X / without_X convention: with_previous(...), with_key(...), with_key_provider(...), with_compressor(...), without_compression, supporting_unencrypted_data, with_context_properties(...).
Alternatives considered
- Inspecting the scheme directly via
Model.encrypted_attributes[:attr] in a spec.
Additional context
References:
Problem this feature will solve
The
encryptmatcher today exposesdeterministic,downcase, andignore_case, butActiveRecord::Encryptionaccepts several more options that are part of the declared contract of an encrypted attribute:previous:— key rotation entries.key:andkey_provider:— per-attribute key/provider overrides.compressor:(Rails 7.1+) andcompress: false.support_unencrypted_data: true— was global only, became per-attribute in Rails 8.1.context_properties:— encryption-context overrides.None of these can be expressed in a matcher today, so changes to them are not caught by specs.
Desired solution
New qualifiers mirroring the option names:
Naming is open. Following the matcher's existing
with_X/without_Xconvention:with_previous(...),with_key(...),with_key_provider(...),with_compressor(...),without_compression,supporting_unencrypted_data,with_context_properties(...).Alternatives considered
Model.encrypted_attributes[:attr]in a spec.Additional context
References:
support_unencrypted_data.