symmetric-encryption 3.2 → 3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +67 -11
- data/lib/symmetric_encryption.rb +7 -9
- data/lib/symmetric_encryption/extensions/active_record/base.rb +29 -11
- data/lib/symmetric_encryption/mongoid.rb +29 -7
- data/lib/symmetric_encryption/railties/symmetric_encryption.rake +5 -1
- data/lib/symmetric_encryption/symmetric_encryption.rb +94 -7
- data/lib/symmetric_encryption/version.rb +1 -1
- data/test/attr_encrypted_test.rb +315 -17
- data/test/cipher_test.rb +1 -10
- data/test/field_encrypted_test.rb +306 -19
- data/test/reader_test.rb +1 -10
- data/test/symmetric_encryption_test.rb +113 -10
- data/test/test_db.sqlite3 +0 -0
- data/test/test_helper.rb +19 -0
- data/test/writer_test.rb +1 -10
- metadata +28 -12
data/test/attr_encrypted_test.rb
CHANGED
@@ -1,18 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'logger'
|
6
|
-
require 'erb'
|
7
|
-
require 'test/unit'
|
8
|
-
# Since we want both the AR and Mongoid extensions loaded we need to require them first
|
9
|
-
require 'active_record'
|
10
|
-
require 'mongoid'
|
11
|
-
require 'symmetric-encryption'
|
12
|
-
# Should redefines Proc#bind so must include after Rails
|
13
|
-
require 'shoulda'
|
14
|
-
|
15
|
-
ActiveRecord::Base.logger = Logger.new($stderr)
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
ActiveRecord::Base.logger = SemanticLogger[ActiveRecord]
|
16
4
|
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read('test/config/database.yml')).result)
|
17
5
|
ActiveRecord::Base.establish_connection('test')
|
18
6
|
|
@@ -22,7 +10,18 @@ ActiveRecord::Schema.define :version => 0 do
|
|
22
10
|
t.string :encrypted_social_security_number
|
23
11
|
t.string :encrypted_string
|
24
12
|
t.text :encrypted_long_string
|
13
|
+
t.text :encrypted_data_yaml
|
14
|
+
t.text :encrypted_data_json
|
25
15
|
t.string :name
|
16
|
+
|
17
|
+
t.string :encrypted_integer_value
|
18
|
+
t.string :encrypted_float_value
|
19
|
+
t.string :encrypted_decimal_value
|
20
|
+
t.string :encrypted_datetime_value
|
21
|
+
t.string :encrypted_time_value
|
22
|
+
t.string :encrypted_date_value
|
23
|
+
t.string :encrypted_true_value
|
24
|
+
t.string :encrypted_false_value
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
@@ -31,6 +30,17 @@ class User < ActiveRecord::Base
|
|
31
30
|
attr_encrypted :social_security_number
|
32
31
|
attr_encrypted :string, :random_iv => true
|
33
32
|
attr_encrypted :long_string, :random_iv => true, :compress => true
|
33
|
+
attr_encrypted :data_yaml, :random_iv => true, :compress => true, :type => :yaml
|
34
|
+
attr_encrypted :data_json, :random_iv => true, :compress => true, :type => :json
|
35
|
+
|
36
|
+
attr_encrypted :integer_value, :type => :integer
|
37
|
+
attr_encrypted :float_value, :type => :float
|
38
|
+
attr_encrypted :decimal_value, :type => :decimal
|
39
|
+
attr_encrypted :datetime_value, :type => :datetime
|
40
|
+
attr_encrypted :time_value, :type => :time
|
41
|
+
attr_encrypted :date_value, :type => :date
|
42
|
+
attr_encrypted :true_value, :type => :boolean
|
43
|
+
attr_encrypted :false_value, :type => :boolean
|
34
44
|
|
35
45
|
validates :encrypted_bank_account_number, :symmetric_encryption => true
|
36
46
|
validates :encrypted_social_security_number, :symmetric_encryption => true
|
@@ -66,12 +76,31 @@ class AttrEncryptedTest < Test::Unit::TestCase
|
|
66
76
|
|
67
77
|
@name = 'Joe Bloggs'
|
68
78
|
|
79
|
+
@integer_value = 12
|
80
|
+
@float_value = 88.12345
|
81
|
+
@decimal_value = BigDecimal.new("22.51")
|
82
|
+
@datetime_value = DateTime.new(2001, 11, 26, 20, 55, 54, "-5")
|
83
|
+
@time_value = Time.new(2013, 01, 01, 22, 30, 00, "-04:00")
|
84
|
+
@date_value = Date.new(1927, 04, 02)
|
85
|
+
@h = { :a => 'A', :b => 'B' }
|
86
|
+
|
69
87
|
@user = User.new(
|
70
88
|
# Encrypted Attribute
|
71
89
|
:bank_account_number => @bank_account_number,
|
72
90
|
# Encrypted Attribute
|
73
91
|
:social_security_number => @social_security_number,
|
74
|
-
:name => @name
|
92
|
+
:name => @name,
|
93
|
+
# data type specific fields
|
94
|
+
:integer_value => @integer_value,
|
95
|
+
:float_value => @float_value,
|
96
|
+
:decimal_value => @decimal_value,
|
97
|
+
:datetime_value => @datetime_value,
|
98
|
+
:time_value => @time_value,
|
99
|
+
:date_value => @date_value,
|
100
|
+
:true_value => true,
|
101
|
+
:false_value => false,
|
102
|
+
:data_yaml => @h.dup,
|
103
|
+
:data_json => @h.dup
|
75
104
|
)
|
76
105
|
end
|
77
106
|
|
@@ -80,6 +109,8 @@ class AttrEncryptedTest < Test::Unit::TestCase
|
|
80
109
|
assert_equal true, @user.respond_to?(:bank_account_number)
|
81
110
|
assert_equal true, @user.respond_to?(:encrypted_social_security_number)
|
82
111
|
assert_equal true, @user.respond_to?(:social_security_number)
|
112
|
+
assert_equal true, @user.respond_to?(:data_yaml)
|
113
|
+
assert_equal true, @user.respond_to?(:data_json)
|
83
114
|
assert_equal false, @user.respond_to?(:encrypted_name)
|
84
115
|
end
|
85
116
|
|
@@ -247,7 +278,274 @@ class AttrEncryptedTest < Test::Unit::TestCase
|
|
247
278
|
assert_equal @bank_account_number_encrypted, @user.encrypted_bank_account_number
|
248
279
|
assert_equal @bank_account_number, @user.bank_account_number
|
249
280
|
end
|
250
|
-
end
|
251
281
|
|
282
|
+
context "data types" do
|
283
|
+
setup do
|
284
|
+
@user_clone = User.find(@user.id)
|
285
|
+
end
|
286
|
+
|
287
|
+
context "integer values" do
|
288
|
+
should "return correct data type" do
|
289
|
+
assert_equal @integer_value, @user_clone.integer_value
|
290
|
+
assert @user.clone.integer_value.kind_of?(Integer)
|
291
|
+
end
|
292
|
+
|
293
|
+
should "permit replacing value with nil" do
|
294
|
+
@user_clone.integer_value = nil
|
295
|
+
@user_clone.save!
|
296
|
+
|
297
|
+
@user.reload
|
298
|
+
assert_nil @user.integer_value
|
299
|
+
assert_nil @user.encrypted_integer_value
|
300
|
+
end
|
301
|
+
|
302
|
+
should "permit replacing value" do
|
303
|
+
new_integer_value = 98
|
304
|
+
@user_clone.integer_value = new_integer_value
|
305
|
+
@user_clone.save!
|
306
|
+
|
307
|
+
@user.reload
|
308
|
+
assert_equal new_integer_value, @user.integer_value
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context "float values" do
|
313
|
+
should "return correct data type" do
|
314
|
+
assert_equal @float_value, @user_clone.float_value
|
315
|
+
assert @user.clone.float_value.kind_of?(Float)
|
316
|
+
end
|
317
|
+
|
318
|
+
should "permit replacing value with nil" do
|
319
|
+
@user_clone.float_value = nil
|
320
|
+
@user_clone.save!
|
321
|
+
|
322
|
+
@user.reload
|
323
|
+
assert_nil @user.float_value
|
324
|
+
assert_nil @user.encrypted_float_value
|
325
|
+
end
|
326
|
+
|
327
|
+
should "permit replacing value" do
|
328
|
+
new_float_value = 45.4321
|
329
|
+
@user_clone.float_value = new_float_value
|
330
|
+
@user_clone.save!
|
331
|
+
|
332
|
+
@user.reload
|
333
|
+
assert_equal new_float_value, @user.float_value
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
context "decimal values" do
|
338
|
+
should "return correct data type" do
|
339
|
+
assert_equal @decimal_value, @user_clone.decimal_value
|
340
|
+
assert @user.clone.decimal_value.kind_of?(BigDecimal)
|
341
|
+
end
|
342
|
+
|
343
|
+
should "permit replacing value with nil" do
|
344
|
+
@user_clone.decimal_value = nil
|
345
|
+
@user_clone.save!
|
346
|
+
|
347
|
+
@user.reload
|
348
|
+
assert_nil @user.decimal_value
|
349
|
+
assert_nil @user.encrypted_decimal_value
|
350
|
+
end
|
351
|
+
|
352
|
+
should "permit replacing value" do
|
353
|
+
new_decimal_value = BigDecimal.new("99.95")
|
354
|
+
@user_clone.decimal_value = new_decimal_value
|
355
|
+
@user_clone.save!
|
356
|
+
|
357
|
+
@user.reload
|
358
|
+
assert_equal new_decimal_value, @user.decimal_value
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context "datetime values" do
|
363
|
+
should "return correct data type" do
|
364
|
+
assert_equal @datetime_value, @user_clone.datetime_value
|
365
|
+
assert @user.clone.datetime_value.kind_of?(DateTime)
|
366
|
+
end
|
367
|
+
|
368
|
+
should "permit replacing value with nil" do
|
369
|
+
@user_clone.datetime_value = nil
|
370
|
+
@user_clone.save!
|
371
|
+
|
372
|
+
@user.reload
|
373
|
+
assert_nil @user.datetime_value
|
374
|
+
assert_nil @user.encrypted_datetime_value
|
375
|
+
end
|
376
|
+
|
377
|
+
should "permit replacing value" do
|
378
|
+
new_datetime_value = DateTime.new(1998, 10, 21, 8, 33, 28, "+5")
|
379
|
+
@user_clone.datetime_value = new_datetime_value
|
380
|
+
@user_clone.save!
|
381
|
+
|
382
|
+
@user.reload
|
383
|
+
assert_equal new_datetime_value, @user.datetime_value
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
context "time values" do
|
388
|
+
should "return correct data type" do
|
389
|
+
assert_equal @time_value, @user_clone.time_value
|
390
|
+
assert @user.clone.time_value.kind_of?(Time)
|
391
|
+
end
|
392
|
+
|
393
|
+
should "permit replacing value with nil" do
|
394
|
+
@user_clone.time_value = nil
|
395
|
+
@user_clone.save!
|
396
|
+
|
397
|
+
@user.reload
|
398
|
+
assert_nil @user.time_value
|
399
|
+
assert_nil @user.encrypted_time_value
|
400
|
+
end
|
401
|
+
|
402
|
+
should "permit replacing value" do
|
403
|
+
new_time_value = Time.new(1998, 10, 21, 8, 33, 28, "+04:00")
|
404
|
+
@user_clone.time_value = new_time_value
|
405
|
+
@user_clone.save!
|
406
|
+
|
407
|
+
@user.reload
|
408
|
+
assert_equal new_time_value, @user.time_value
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
context "date values" do
|
413
|
+
should "return correct data type" do
|
414
|
+
assert_equal @date_value, @user_clone.date_value
|
415
|
+
assert @user.clone.date_value.kind_of?(Date)
|
416
|
+
end
|
417
|
+
|
418
|
+
should "permit replacing value with nil" do
|
419
|
+
@user_clone.date_value = nil
|
420
|
+
@user_clone.save!
|
421
|
+
|
422
|
+
@user.reload
|
423
|
+
assert_nil @user.date_value
|
424
|
+
assert_nil @user.encrypted_date_value
|
425
|
+
end
|
426
|
+
|
427
|
+
should "permit replacing value" do
|
428
|
+
new_date_value = Date.new(1998, 10, 21)
|
429
|
+
@user_clone.date_value = new_date_value
|
430
|
+
@user_clone.save!
|
431
|
+
|
432
|
+
@user.reload
|
433
|
+
assert_equal new_date_value, @user.date_value
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
context "true values" do
|
438
|
+
should "return correct data type" do
|
439
|
+
assert_equal true, @user_clone.true_value
|
440
|
+
assert @user.clone.true_value.kind_of?(TrueClass)
|
441
|
+
end
|
442
|
+
|
443
|
+
should "permit replacing value with nil" do
|
444
|
+
@user_clone.true_value = nil
|
445
|
+
@user_clone.save!
|
446
|
+
|
447
|
+
@user.reload
|
448
|
+
assert_nil @user.true_value
|
449
|
+
assert_nil @user.encrypted_true_value
|
450
|
+
end
|
451
|
+
|
452
|
+
should "permit replacing value" do
|
453
|
+
new_value = false
|
454
|
+
@user_clone.true_value = new_value
|
455
|
+
@user_clone.save!
|
456
|
+
|
457
|
+
@user.reload
|
458
|
+
assert_equal new_value, @user.true_value
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
context "false values" do
|
463
|
+
should "return correct data type" do
|
464
|
+
assert_equal false, @user_clone.false_value
|
465
|
+
assert @user.clone.false_value.kind_of?(FalseClass)
|
466
|
+
end
|
467
|
+
|
468
|
+
should "permit replacing value with nil" do
|
469
|
+
@user_clone.false_value = nil
|
470
|
+
@user_clone.save!
|
471
|
+
|
472
|
+
@user.reload
|
473
|
+
assert_nil @user.false_value
|
474
|
+
assert_nil @user.encrypted_false_value
|
475
|
+
end
|
476
|
+
|
477
|
+
should "permit replacing value" do
|
478
|
+
new_value = true
|
479
|
+
@user_clone.false_value = new_value
|
480
|
+
@user_clone.save!
|
481
|
+
|
482
|
+
@user.reload
|
483
|
+
assert_equal new_value, @user.false_value
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context "JSON Serialization" do
|
488
|
+
setup do
|
489
|
+
# JSON Does not support symbols, so they will come back as strings
|
490
|
+
# Convert symbols to string in the test
|
491
|
+
@h.keys.each do |k|
|
492
|
+
@h[k.to_s] = @h[k]
|
493
|
+
@h.delete(k)
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
should "return correct data type" do
|
498
|
+
assert_equal @h, @user_clone.data_json
|
499
|
+
assert @user.clone.data_json.kind_of?(Hash)
|
500
|
+
end
|
501
|
+
|
502
|
+
should "permit replacing value with nil" do
|
503
|
+
@user_clone.data_json = nil
|
504
|
+
@user_clone.save!
|
505
|
+
|
506
|
+
@user.reload
|
507
|
+
assert_nil @user.data_json
|
508
|
+
assert_nil @user.encrypted_data_json
|
509
|
+
end
|
510
|
+
|
511
|
+
should "permit replacing value" do
|
512
|
+
new_value = @h.clone
|
513
|
+
new_value['c'] = 'C'
|
514
|
+
@user_clone.data_json = new_value
|
515
|
+
@user_clone.save!
|
516
|
+
|
517
|
+
@user.reload
|
518
|
+
assert_equal new_value, @user.data_json
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
context "YAML Serialization" do
|
523
|
+
should "return correct data type" do
|
524
|
+
assert_equal @h, @user_clone.data_yaml
|
525
|
+
assert @user.clone.data_yaml.kind_of?(Hash)
|
526
|
+
end
|
527
|
+
|
528
|
+
should "permit replacing value with nil" do
|
529
|
+
@user_clone.data_yaml = nil
|
530
|
+
@user_clone.save!
|
531
|
+
|
532
|
+
@user.reload
|
533
|
+
assert_nil @user.data_yaml
|
534
|
+
assert_nil @user.encrypted_data_yaml
|
535
|
+
end
|
536
|
+
|
537
|
+
should "permit replacing value" do
|
538
|
+
new_value = @h.clone
|
539
|
+
new_value[:c] = 'C'
|
540
|
+
@user_clone.data_yaml = new_value
|
541
|
+
@user_clone.save!
|
542
|
+
|
543
|
+
@user.reload
|
544
|
+
assert_equal new_value, @user.data_yaml
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
end
|
549
|
+
end
|
252
550
|
end
|
253
551
|
end
|
data/test/cipher_test.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'test/unit'
|
6
|
-
require 'shoulda'
|
7
|
-
require 'symmetric_encryption'
|
8
|
-
|
9
|
-
# Load Symmetric Encryption keys
|
10
|
-
SymmetricEncryption.load!(File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml'), 'test')
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
11
2
|
|
12
3
|
# Unit Test for SymmetricEncryption::Cipher
|
13
4
|
#
|
@@ -1,17 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'logger'
|
6
|
-
require 'erb'
|
7
|
-
require 'test/unit'
|
8
|
-
require 'shoulda'
|
9
|
-
# Since we want both the Mongoid extensions loaded we need to require it first
|
10
|
-
require 'active_record'
|
11
|
-
require 'mongoid'
|
12
|
-
require 'symmetric-encryption'
|
13
|
-
|
14
|
-
Mongoid.logger = Logger.new($stdout)
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
Mongoid.logger = SemanticLogger[Mongoid]
|
15
4
|
filename = defined?(Mongoid::VERSION) ? "test/config/mongoid_v3.yml" : "test/config/mongoid_v2.yml"
|
16
5
|
Mongoid.load!(filename)
|
17
6
|
|
@@ -24,8 +13,20 @@ class MongoidUser
|
|
24
13
|
field :encrypted_string, :type => String, :encrypted => {:random_iv => true}
|
25
14
|
field :encrypted_long_string, :type => String, :encrypted => {:random_iv => true, :compress => true}
|
26
15
|
|
27
|
-
|
28
|
-
|
16
|
+
field :encrypted_integer_value, :type => String, :encrypted => {:type => :integer}
|
17
|
+
field :encrypted_float_value, :type => String, :encrypted => {:type => :float}
|
18
|
+
field :encrypted_decimal_value, :type => String, :encrypted => {:type => :decimal}
|
19
|
+
field :encrypted_datetime_value, :type => String, :encrypted => {:type => :datetime}
|
20
|
+
field :encrypted_time_value, :type => String, :encrypted => {:type => :time}
|
21
|
+
field :encrypted_date_value, :type => String, :encrypted => {:type => :date}
|
22
|
+
field :encrypted_true_value, :type => String, :encrypted => {:type => :boolean}
|
23
|
+
field :encrypted_false_value, :type => String, :encrypted => {:type => :boolean}
|
24
|
+
field :encrypted_data_yaml, :type => String, :encrypted => {:random_iv => true, :compress => true, :type => :yaml}
|
25
|
+
field :encrypted_data_json, :type => String, :encrypted => {:random_iv => true, :compress => true, :type => :json}
|
26
|
+
|
27
|
+
# TODO Validates should work
|
28
|
+
#validates :encrypted_bank_account_number, :symmetric_encrypted => true
|
29
|
+
#validates :encrypted_social_security_number, :symmetric_encrypted => true
|
29
30
|
end
|
30
31
|
|
31
32
|
# Load Symmetric Encryption keys
|
@@ -55,11 +56,29 @@ class FieldEncryptedTest < Test::Unit::TestCase
|
|
55
56
|
@string = "A string containing some data to be encrypted with a random initialization vector"
|
56
57
|
@long_string = "A string containing some data to be encrypted with a random initialization vector and compressed since it takes up so much space in plain text form"
|
57
58
|
|
58
|
-
|
59
|
+
@integer_value = 12
|
60
|
+
@float_value = 88.12345
|
61
|
+
@decimal_value = BigDecimal.new("22.51")
|
62
|
+
@datetime_value = DateTime.new(2001, 11, 26, 20, 55, 54, "-5")
|
63
|
+
@time_value = Time.new(2013, 01, 01, 22, 30, 00, "-04:00")
|
64
|
+
@date_value = Date.new(1927, 04, 02)
|
65
|
+
@h = { :a => 'A', :b => 'B' }
|
66
|
+
|
59
67
|
@user = MongoidUser.new(
|
60
68
|
:encrypted_bank_account_number => @bank_account_number_encrypted,
|
61
69
|
:encrypted_social_security_number => @social_security_number_encrypted,
|
62
|
-
:name => "Joe Bloggs"
|
70
|
+
:name => "Joe Bloggs",
|
71
|
+
# data type specific fields
|
72
|
+
:integer_value => @integer_value,
|
73
|
+
:float_value => @float_value,
|
74
|
+
:decimal_value => @decimal_value,
|
75
|
+
:datetime_value => @datetime_value,
|
76
|
+
:time_value => @time_value,
|
77
|
+
:date_value => @date_value,
|
78
|
+
:true_value => true,
|
79
|
+
:false_value => false,
|
80
|
+
:data_yaml => @h.dup,
|
81
|
+
:data_json => @h.dup
|
63
82
|
)
|
64
83
|
end
|
65
84
|
|
@@ -168,6 +187,274 @@ class FieldEncryptedTest < Test::Unit::TestCase
|
|
168
187
|
assert_equal @bank_account_number_encrypted, user.encrypted_bank_account_number
|
169
188
|
assert_equal @social_security_number_encrypted, user.encrypted_social_security_number
|
170
189
|
end
|
171
|
-
end
|
172
190
|
|
191
|
+
context "data types" do
|
192
|
+
setup do
|
193
|
+
@user.save!
|
194
|
+
@user_clone = MongoidUser.find(@user.id)
|
195
|
+
end
|
196
|
+
|
197
|
+
context "integer values" do
|
198
|
+
should "return correct data type" do
|
199
|
+
assert_equal @integer_value, @user_clone.integer_value
|
200
|
+
assert @user.clone.integer_value.kind_of?(Integer)
|
201
|
+
end
|
202
|
+
|
203
|
+
should "permit replacing value with nil" do
|
204
|
+
@user_clone.integer_value = nil
|
205
|
+
@user_clone.save!
|
206
|
+
|
207
|
+
@user.reload
|
208
|
+
assert_nil @user.integer_value
|
209
|
+
assert_nil @user.encrypted_integer_value
|
210
|
+
end
|
211
|
+
|
212
|
+
should "permit replacing value" do
|
213
|
+
new_integer_value = 98
|
214
|
+
@user_clone.integer_value = new_integer_value
|
215
|
+
@user_clone.save!
|
216
|
+
|
217
|
+
@user.reload
|
218
|
+
assert_equal new_integer_value, @user.integer_value
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "float values" do
|
223
|
+
should "return correct data type" do
|
224
|
+
assert_equal @float_value, @user_clone.float_value
|
225
|
+
assert @user.clone.float_value.kind_of?(Float)
|
226
|
+
end
|
227
|
+
|
228
|
+
should "permit replacing value with nil" do
|
229
|
+
@user_clone.float_value = nil
|
230
|
+
@user_clone.save!
|
231
|
+
|
232
|
+
@user.reload
|
233
|
+
assert_nil @user.float_value
|
234
|
+
assert_nil @user.encrypted_float_value
|
235
|
+
end
|
236
|
+
|
237
|
+
should "permit replacing value" do
|
238
|
+
new_float_value = 45.4321
|
239
|
+
@user_clone.float_value = new_float_value
|
240
|
+
@user_clone.save!
|
241
|
+
|
242
|
+
@user.reload
|
243
|
+
assert_equal new_float_value, @user.float_value
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context "decimal values" do
|
248
|
+
should "return correct data type" do
|
249
|
+
assert_equal @decimal_value, @user_clone.decimal_value
|
250
|
+
assert @user.clone.decimal_value.kind_of?(BigDecimal)
|
251
|
+
end
|
252
|
+
|
253
|
+
should "permit replacing value with nil" do
|
254
|
+
@user_clone.decimal_value = nil
|
255
|
+
@user_clone.save!
|
256
|
+
|
257
|
+
@user.reload
|
258
|
+
assert_nil @user.decimal_value
|
259
|
+
assert_nil @user.encrypted_decimal_value
|
260
|
+
end
|
261
|
+
|
262
|
+
should "permit replacing value" do
|
263
|
+
new_decimal_value = BigDecimal.new("99.95")
|
264
|
+
@user_clone.decimal_value = new_decimal_value
|
265
|
+
@user_clone.save!
|
266
|
+
|
267
|
+
@user.reload
|
268
|
+
assert_equal new_decimal_value, @user.decimal_value
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context "datetime values" do
|
273
|
+
should "return correct data type" do
|
274
|
+
assert_equal @datetime_value, @user_clone.datetime_value
|
275
|
+
assert @user.clone.datetime_value.kind_of?(DateTime)
|
276
|
+
end
|
277
|
+
|
278
|
+
should "permit replacing value with nil" do
|
279
|
+
@user_clone.datetime_value = nil
|
280
|
+
@user_clone.save!
|
281
|
+
|
282
|
+
@user.reload
|
283
|
+
assert_nil @user.datetime_value
|
284
|
+
assert_nil @user.encrypted_datetime_value
|
285
|
+
end
|
286
|
+
|
287
|
+
should "permit replacing value" do
|
288
|
+
new_datetime_value = DateTime.new(1998, 10, 21, 8, 33, 28, "+5")
|
289
|
+
@user_clone.datetime_value = new_datetime_value
|
290
|
+
@user_clone.save!
|
291
|
+
|
292
|
+
@user.reload
|
293
|
+
assert_equal new_datetime_value, @user.datetime_value
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "time values" do
|
298
|
+
should "return correct data type" do
|
299
|
+
assert_equal @time_value, @user_clone.time_value
|
300
|
+
assert @user.clone.time_value.kind_of?(Time)
|
301
|
+
end
|
302
|
+
|
303
|
+
should "permit replacing value with nil" do
|
304
|
+
@user_clone.time_value = nil
|
305
|
+
@user_clone.save!
|
306
|
+
|
307
|
+
@user.reload
|
308
|
+
assert_nil @user.time_value
|
309
|
+
assert_nil @user.encrypted_time_value
|
310
|
+
end
|
311
|
+
|
312
|
+
should "permit replacing value" do
|
313
|
+
new_time_value = Time.new(1998, 10, 21, 8, 33, 28, "+04:00")
|
314
|
+
@user_clone.time_value = new_time_value
|
315
|
+
@user_clone.save!
|
316
|
+
|
317
|
+
@user.reload
|
318
|
+
assert_equal new_time_value, @user.time_value
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
context "date values" do
|
323
|
+
should "return correct data type" do
|
324
|
+
assert_equal @date_value, @user_clone.date_value
|
325
|
+
assert @user.clone.date_value.kind_of?(Date)
|
326
|
+
end
|
327
|
+
|
328
|
+
should "permit replacing value with nil" do
|
329
|
+
@user_clone.date_value = nil
|
330
|
+
@user_clone.save!
|
331
|
+
|
332
|
+
@user.reload
|
333
|
+
assert_nil @user.date_value
|
334
|
+
assert_nil @user.encrypted_date_value
|
335
|
+
end
|
336
|
+
|
337
|
+
should "permit replacing value" do
|
338
|
+
new_date_value = Date.new(1998, 10, 21)
|
339
|
+
@user_clone.date_value = new_date_value
|
340
|
+
@user_clone.save!
|
341
|
+
|
342
|
+
@user.reload
|
343
|
+
assert_equal new_date_value, @user.date_value
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
context "true values" do
|
348
|
+
should "return correct data type" do
|
349
|
+
assert_equal true, @user_clone.true_value
|
350
|
+
assert @user.clone.true_value.kind_of?(TrueClass)
|
351
|
+
end
|
352
|
+
|
353
|
+
should "permit replacing value with nil" do
|
354
|
+
@user_clone.true_value = nil
|
355
|
+
@user_clone.save!
|
356
|
+
|
357
|
+
@user.reload
|
358
|
+
assert_nil @user.true_value
|
359
|
+
assert_nil @user.encrypted_true_value
|
360
|
+
end
|
361
|
+
|
362
|
+
should "permit replacing value" do
|
363
|
+
new_value = false
|
364
|
+
@user_clone.true_value = new_value
|
365
|
+
@user_clone.save!
|
366
|
+
|
367
|
+
@user.reload
|
368
|
+
assert_equal new_value, @user.true_value
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
context "false values" do
|
373
|
+
should "return correct data type" do
|
374
|
+
assert_equal false, @user_clone.false_value
|
375
|
+
assert @user.clone.false_value.kind_of?(FalseClass)
|
376
|
+
end
|
377
|
+
|
378
|
+
should "permit replacing value with nil" do
|
379
|
+
@user_clone.false_value = nil
|
380
|
+
@user_clone.save!
|
381
|
+
|
382
|
+
@user.reload
|
383
|
+
assert_nil @user.false_value
|
384
|
+
assert_nil @user.encrypted_false_value
|
385
|
+
end
|
386
|
+
|
387
|
+
should "permit replacing value" do
|
388
|
+
new_value = true
|
389
|
+
@user_clone.false_value = new_value
|
390
|
+
@user_clone.save!
|
391
|
+
|
392
|
+
@user.reload
|
393
|
+
assert_equal new_value, @user.false_value
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context "JSON Serialization" do
|
398
|
+
setup do
|
399
|
+
# JSON Does not support symbols, so they will come back as strings
|
400
|
+
# Convert symbols to string in the test
|
401
|
+
@h.keys.each do |k|
|
402
|
+
@h[k.to_s] = @h[k]
|
403
|
+
@h.delete(k)
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
should "return correct data type" do
|
408
|
+
assert_equal @h, @user_clone.data_json
|
409
|
+
assert @user.clone.data_json.kind_of?(Hash)
|
410
|
+
end
|
411
|
+
|
412
|
+
should "permit replacing value with nil" do
|
413
|
+
@user_clone.data_json = nil
|
414
|
+
@user_clone.save!
|
415
|
+
|
416
|
+
@user.reload
|
417
|
+
assert_nil @user.data_json
|
418
|
+
assert_nil @user.encrypted_data_json
|
419
|
+
end
|
420
|
+
|
421
|
+
should "permit replacing value" do
|
422
|
+
new_value = @h.clone
|
423
|
+
new_value['c'] = 'C'
|
424
|
+
@user_clone.data_json = new_value
|
425
|
+
@user_clone.save!
|
426
|
+
|
427
|
+
@user.reload
|
428
|
+
assert_equal new_value, @user.data_json
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
context "YAML Serialization" do
|
433
|
+
should "return correct data type" do
|
434
|
+
assert_equal @h, @user_clone.data_yaml
|
435
|
+
assert @user.clone.data_yaml.kind_of?(Hash)
|
436
|
+
end
|
437
|
+
|
438
|
+
should "permit replacing value with nil" do
|
439
|
+
@user_clone.data_yaml = nil
|
440
|
+
@user_clone.save!
|
441
|
+
|
442
|
+
@user.reload
|
443
|
+
assert_nil @user.data_yaml
|
444
|
+
assert_nil @user.encrypted_data_yaml
|
445
|
+
end
|
446
|
+
|
447
|
+
should "permit replacing value" do
|
448
|
+
new_value = @h.clone
|
449
|
+
new_value[:c] = 'C'
|
450
|
+
@user_clone.data_yaml = new_value
|
451
|
+
@user_clone.save!
|
452
|
+
|
453
|
+
@user.reload
|
454
|
+
assert_equal new_value, @user.data_yaml
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
end
|
173
460
|
end
|