test/mongoid_test.rb in symmetric-encryption-3.8.3 vs test/mongoid_test.rb in symmetric-encryption-3.9.0
- old
+ new
@@ -2,31 +2,21 @@
require 'mongoid'
require_relative 'test_helper'
require_relative '../lib/symmetric_encryption/extensions/mongoid/encrypted'
ENV['RACK_ENV'] = 'test'
- Mongoid.logger = SemanticLogger[Mongoid]
- filename =
- case Mongoid::VERSION.to_i
- when 3, 4
- 'test/config/mongoid_v3.yml'
- when 1, 2
- 'test/config/mongoid_v2.yml'
- else
- 'test/config/mongoid_v5.yml'
- end
- Mongoid.load!(filename)
+ Mongoid.load!('test/config/mongoid.yml')
#@formatter:off
class MongoidUser
include Mongoid::Document
field :name, type: String
- field :encrypted_bank_account_number, type: String, encrypted: true
- field :encrypted_social_security_number, type: String, encrypted: true
- field :encrypted_string, type: String, encrypted: {random_iv: true}
- field :encrypted_long_string, type: String, encrypted: {random_iv: true, compress: true}
+ field :encrypted_bank_account_number, type: String, encrypted: true
+ field :encrypted_social_security_number, type: String, encrypted: true
+ field :encrypted_string, type: String, encrypted: {random_iv: true}
+ field :encrypted_long_string, type: String, encrypted: {random_iv: true, compress: true}
field :encrypted_integer_value, type: String, encrypted: {type: :integer}
field :aiv, type: String, encrypted: {type: :integer, decrypt_as: :aliased_integer_value}
field :encrypted_float_value, type: String, encrypted: {type: :float}
field :encrypted_decimal_value, type: String, encrypted: {type: :decimal}
@@ -192,18 +182,18 @@
assert_equal @bank_account_number_encrypted, @user.encrypted_social_security_number
end
it "all paths it lead to the same result, check uninitialized" do
user = MongoidUser.new
- assert_equal nil, user.social_security_number
+ assert_nil user.social_security_number
assert_equal @bank_account_number, (user.social_security_number = @bank_account_number)
assert_equal @bank_account_number, user.social_security_number
assert_equal @bank_account_number_encrypted, user.encrypted_social_security_number
- assert_equal nil, (user.social_security_number = nil)
- assert_equal nil, user.social_security_number
- assert_equal nil, user.encrypted_social_security_number
+ assert_nil (user.social_security_number = nil)
+ assert_nil user.social_security_number
+ assert_nil user.encrypted_social_security_number
end
it 'allow unencrypted values to be passed to the constructor' do
user = MongoidUser.new(bank_account_number: @bank_account_number, social_security_number: @social_security_number)
assert_equal @bank_account_number, user.bank_account_number
@@ -383,18 +373,18 @@
end
end
describe 'time values' do
it 'return correct data type' do
- assert_equal @time_value, @user_clone.time_value
+ assert_equal @time_value, @user_clone.time_value.dup
assert @user.clone.time_value.kind_of?(Time)
end
it 'coerce data type before save' do
now = Time.now
u = MongoidUser.new(time_value: now)
- assert_equal now, u.time_value
+ assert_equal now, u.time_value.dup
assert u.time_value.kind_of?(Time)
end
it 'permit replacing value with nil' do
@user_clone.time_value = nil
@@ -409,10 +399,10 @@
new_time_value = Time.new(1998, 10, 21, 8, 33, 28, '+04:00')
@user_clone.time_value = new_time_value
@user_clone.save!
@user.reload
- assert_equal new_time_value, @user.time_value
+ assert_equal new_time_value, @user.time_value.dup
end
end
describe 'date values' do
it 'return correct data type' do