I have a model, which is using attr_encrypted
gem to encrypt the password.
class Credential < ApplicationRecord
validates :user_name, presence: true
enum credential_type: { windows: 1, linux: 2 }
attr_encrypted :user_pass, key: :encryption_key
def encryption_key
# Some complex logic
end
end
I am learning to write test cases and my factory for the above looks like this:
FactoryBot.define do
factory :credential do
user_name { "rmishra" }
user_pass { "secret" }
credential_type { "linux" }
encryption_key { "abcdefghijklmnopqrstuvw123456789" }
end
end
My spec file looks like:
RSpec.describe Credential, type: :model do
let(:credential) { create(:credential) }
...
end
How do I stub encryption_key
method in factory definition, which is getting used at the time of create
?