shuber-attr_encrypted 1.0.7 → 1.0.8
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.
- data/CHANGELOG +3 -0
- data/lib/attr_encrypted.rb +4 -4
- data/test/attr_encrypted_test.rb +8 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
data/lib/attr_encrypted.rb
CHANGED
@@ -152,8 +152,8 @@ module Huberry
|
|
152
152
|
|
153
153
|
define_class_method "encrypt_#{attribute}" do |value|
|
154
154
|
if options[:if] && !options[:unless]
|
155
|
-
if value.nil?
|
156
|
-
encrypted_value =
|
155
|
+
if value.nil? || (value.is_a?(String) && value.empty?)
|
156
|
+
encrypted_value = value
|
157
157
|
else
|
158
158
|
value = Marshal.dump(value) if options[:marshal]
|
159
159
|
encrypted_value = options[:encryptor].send options[:encrypt_method], options.merge(:value => value)
|
@@ -167,8 +167,8 @@ module Huberry
|
|
167
167
|
|
168
168
|
define_class_method "decrypt_#{attribute}" do |encrypted_value|
|
169
169
|
if options[:if] && !options[:unless]
|
170
|
-
if encrypted_value.nil?
|
171
|
-
decrypted_value =
|
170
|
+
if encrypted_value.nil? || (encrypted_value.is_a?(String) && encrypted_value.empty?)
|
171
|
+
decrypted_value = encrypted_value
|
172
172
|
else
|
173
173
|
encrypted_value = encrypted_value.unpack(options[:encode]).to_s if options[:encode]
|
174
174
|
decrypted_value = options[:encryptor].send(options[:decrypt_method], options.merge(:value => encrypted_value))
|
data/test/attr_encrypted_test.rb
CHANGED
@@ -75,6 +75,10 @@ class AttrEncryptedTest < Test::Unit::TestCase
|
|
75
75
|
assert_nil User.encrypt_email(nil)
|
76
76
|
end
|
77
77
|
|
78
|
+
def test_should_not_encrypt_empty_string
|
79
|
+
assert_equal '', User.encrypt_email('')
|
80
|
+
end
|
81
|
+
|
78
82
|
def test_should_encrypt_email
|
79
83
|
assert_not_nil User.encrypt_email('test@example.com')
|
80
84
|
assert_not_equal 'test@example.com', User.encrypt_email('test@example.com')
|
@@ -92,6 +96,10 @@ class AttrEncryptedTest < Test::Unit::TestCase
|
|
92
96
|
assert_nil User.decrypt_email(nil)
|
93
97
|
end
|
94
98
|
|
99
|
+
def test_should_not_decrypt_empty_string
|
100
|
+
assert_equal '', User.decrypt_email('')
|
101
|
+
end
|
102
|
+
|
95
103
|
def test_should_decrypt_email
|
96
104
|
encrypted_email = User.encrypt_email('test@example.com')
|
97
105
|
assert_not_equal 'test@test.com', encrypted_email
|