2020-01-29 10:08:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe AttrEncrypted do
|
2020-01-29 10:08:59 -05:00
|
|
|
describe '#encrypted_attributes' do
|
|
|
|
subject do
|
|
|
|
Class.new(ActiveRecord::Base) do
|
|
|
|
self.table_name = 'projects'
|
|
|
|
|
|
|
|
attr_accessor :encrypted_foo
|
|
|
|
attr_accessor :encrypted_foo_iv
|
|
|
|
|
|
|
|
attr_encrypted :foo, key: 'This is a key that is 256 bits!!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not share state with other instances' do
|
|
|
|
instance = subject.new
|
|
|
|
instance.foo = 'bar'
|
|
|
|
|
|
|
|
another_instance = subject.new
|
|
|
|
|
|
|
|
expect(instance.encrypted_attributes[:foo][:operation]).to eq(:encrypting)
|
|
|
|
expect(another_instance.encrypted_attributes[:foo][:operation]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|