-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
What Ruby, Rails and RSpec versions are you using?
Ruby version: 3.3.4
Rails version: 7.2.0
RSpec version: 3.13
- rspec-core 3.13.0
- rspec-expectations 3.13.1
- rspec-mocks 3.13.1
- rspec-rails 6.1.3
- rspec-support 3.13.1
Observed behaviour
Support for encrypted attributes in fixtures cannot be enabled when using Rails 7.2.0.
When the active_record_fixture_set
hook in the Active Record railtie runs, the value of ActiveRecord::Encryption.config.encrypt_fixtures
is false, and the module is not prepended.
This is because the active_record
hook has not yet run, and encryption has not been configured.
(Note, this is only an issue when eager_loading
is not enabled, as eager loading the application causes Active Record to be loaded before RSpec loads the Active Record Test Fixtures.)
Expected behaviour
Setting config.active_record.encryption.encrypt_fixtures = true
should allow fixtures to set encrypted attributes. Instead, a ActiveRecord::Encryption::Errors::Decryption
exception is raised whenever an encrypted attribute is attempted to be read.
Can you provide an example reproduction?
I've made a simple reproduction repo here: https://github.com/mbaird/fixture-encryption-bug
The main
branch includes the failing example, the output can be seen in the GitHub Action run.
The rails-7-1
branch switches to Rails 7.1, the tests pass on this branch.
I think these Rails issues may be related rails/rails#50606, rails/rails#48577.