ankane / lockbox

Modern encryption for Ruby and Rails
MIT License
1.44k stars 68 forks source link

Rails 7: generate_x_ciphertext method does not exists in fixtures #145

Closed renchap closed 2 years ago

renchap commented 2 years ago

I am trying to update my app to Rails 7 RC1, and I am facing an issue with the fixtures.

I am generating fixture data by calling the generate_field_ciphertext as indicated in the README:

password_ciphertext: <%= MyModule::Password.generate_password_ciphertext(::Digest::MD5.hexdigest("mymd5pass")).inspect %>

But I am getting this error when running tests:

NoMethodError: undefined method `generate_password_ciphertext' for MyModule::Password:Class
Did you mean?  generate_relation_method
    test/fixtures/my_module/password.yml:3:in `get_binding'

My model is very simple:

class MyModule::Password < ApplicationRecord
  encrypts :password, key: ENV["LOCKBOX_KEY"]
end

It worked fine with the current stable Rails, I am not sure what is happening here.

ankane commented 2 years ago

Hey @renchap, encrypts uses Active Record encryption in Rails 7. You'll need to use lockbox_encrypts for now. See #107 for more info.

renchap commented 2 years ago

Thanks, I missed that AR now implements encrypts and it needed to be renamed 👍