Skip to content

Commit

Permalink
Update spec to run with multiple attr_encrypted versions
Browse files Browse the repository at this point in the history
Runs spec assertions conditionally based on which version of
attr_encrypted is loaded.
  • Loading branch information
mjankowski committed Apr 21, 2023
1 parent f2671a4 commit b4f0d29
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions spec/devise/models/two_factor_authenticatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,31 @@ def save(validate)

describe 'otp_secret options' do
it 'should be of the key' do
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:key]).to eq('test-key'*8)
if attr_encrypted_is_rails_seven_compatible?
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:key]).to eq('test-key'*8)
else
expect(subject.encrypted_attributes[:otp_secret][:key]).to eq('test-key'*8)
end
end

it 'should be of the mode' do
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:mode]).to eq(:per_attribute_iv_and_salt)
if attr_encrypted_is_rails_seven_compatible?
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:mode]).to eq(:per_attribute_iv_and_salt)
else
expect(subject.encrypted_attributes[:otp_secret][:mode]).to eq(:per_attribute_iv_and_salt)
end
end

it 'should be of the mode' do
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:algorithm]).to eq('aes-256-cbc')
if attr_encrypted_is_rails_seven_compatible?
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:algorithm]).to eq('aes-256-cbc')
else
expect(subject.encrypted_attributes[:otp_secret][:algorithm]).to eq('aes-256-cbc')
end
end

def attr_encrypted_is_rails_seven_compatible?
Gem::Version.new(AttrEncrypted::Version.string) >= Gem::Version.new('4.0.0')
end
end
end
Expand Down

0 comments on commit b4f0d29

Please sign in to comment.