attr_secure 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 823b15116fee5d14b97ae231f81b48e7cb1b304e
4
- data.tar.gz: 49b2aefa2a76a6eb4e6cd466320cba879ac88d20
3
+ metadata.gz: 8d5fbb2605957a88f3fd11dcbc0f735fc8b993ed
4
+ data.tar.gz: faf03ade79777a0e6b02d86698a463ca004f3d4c
5
5
  SHA512:
6
- metadata.gz: 19037e5da221dc532f23f733380f1bf0d10f18fb1b18d1877aa648d32b42262ae42622a9491173be0630979bec41d601a13e9861b778d38b933bcd69f3f7213c
7
- data.tar.gz: fd893bd6f3858c51e74c74057fbec4a88c99d588b849d1d42228a2996ad516669e29991f3ba6179bc7eef5cca3eb5800e1b3b083b80955552027444d7b32ab87
6
+ metadata.gz: 16569f6996244494a91e44b0d07f2032596c466aa53d4e69c1fd91e06bb68bd1fe668a67d3a252f4907eb1088b25a8d0ec867061fa5a2c0e172b9b3b968e0bd0
7
+ data.tar.gz: 55292057514a6f91c1dd9f03d128e51a48a3e155694f5632a3f2656999c2d044130d534b61b6b6b96aec12dbd00cb93868b159844861d52aaeebeefdf1f96a41
@@ -9,11 +9,15 @@ module AttrSecure
9
9
  attr_reader :secret
10
10
 
11
11
  def initialize(secret)
12
- @secret = secret.split(",")
12
+ self.secret = secret
13
13
  end
14
14
 
15
15
  def secret=(val)
16
- @secret = secret.split(",")
16
+ @secret = if val.is_a? Array
17
+ val
18
+ else
19
+ val.split(",")
20
+ end
17
21
  end
18
22
 
19
23
  def encrypt(value)
@@ -1,3 +1,3 @@
1
1
  module AttrSecure
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/spec/secure_spec.rb CHANGED
@@ -3,8 +3,17 @@ require 'spec_helper'
3
3
  describe AttrSecure::Secure do
4
4
  context "with a simple key" do
5
5
 
6
- subject { described_class.new(secret) }
7
- let(:secret) { 'fWSvpC6Eh1/FFE1TUgXpcEzMmmGc9IZSqoexzEslzKI=' }
6
+ subject { described_class.new(secret1) }
7
+ let(:secret1) { 'fWSvpC6Eh1/FFE1TUgXpcEzMmmGc9IZSqoexzEslzKI=' }
8
+ let(:secret2) { 'd9ssNmUYn7UpMoSc0eM2glVUG2DPYwXveLTDU7j8pBY=' }
9
+
10
+ describe '#secret=' do
11
+ it "should update the list of secrets" do
12
+ expect(subject.secret).to eq([secret1])
13
+ subject.secret = secret2
14
+ expect(subject.secret).to eq([secret2])
15
+ end
16
+ end
8
17
 
9
18
  describe '#encrypt' do
10
19
  it "should encrypt a string" do
@@ -23,24 +32,38 @@ describe AttrSecure::Secure do
23
32
  end
24
33
  end
25
34
 
26
- # context "with an array of keys" do
27
- # subject { described_class.new(secret) }
28
- # let(:secret) { 'fWSvpC6Eh1/FFE1TUgXpcEzMmmGc9IZSqoexzEslzKI=,d9ssNmUYn7UpMoSc0eM2glVUG2DPYwXveLTDU7j8pBY=' }
29
-
30
- # describe '#encrypt' do
31
- # it "should encrypt a string" do
32
- # expect(subject.encrypt('encrypted')).to be_a(String)
33
- # expect(subject.encrypt('encrypted')).to_not be_empty
34
- # expect(subject.encrypt('encrypted')).to_not eq(subject.encrypt('encrypted'))
35
- # end
36
- # end
37
-
38
- # describe '#decrypt' do
39
- # let(:encrypted_value) { subject.encrypt('decrypted') }
40
-
41
- # it "should decrypt a string" do
42
- # expect(subject.decrypt(encrypted_value)).to eq('decrypted')
43
- # end
44
- # end
45
- # end
35
+ [ ->(*secrets) { secrets.join(',') },
36
+ ->(*secrets) { secrets } ].each do |make_secret|
37
+ context "with an array of keys" do
38
+ subject { described_class.new(make_secret.call(secret1, secret2)) }
39
+ let(:secret1) { 'fWSvpC6Eh1/FFE1TUgXpcEzMmmGc9IZSqoexzEslzKI=' }
40
+ let(:secret2) { 'd9ssNmUYn7UpMoSc0eM2glVUG2DPYwXveLTDU7j8pBY=' }
41
+
42
+ describe '#secret=' do
43
+ it "should update the list of secrets" do
44
+ expect(subject.secret).to eq([secret1, secret2])
45
+ subject.secret = make_secret.call(secret2, secret1)
46
+ expect(subject.secret).to eq([secret2, secret1])
47
+ end
48
+ end
49
+
50
+ describe '#encrypt' do
51
+ it "should encrypt a string" do
52
+ expect(subject.encrypt('encrypted')).to be_a(String)
53
+ expect(subject.encrypt('encrypted')).to_not be_empty
54
+ expect(subject.encrypt('encrypted')).to_not eq(subject.encrypt('encrypted'))
55
+ end
56
+ end
57
+
58
+ describe '#decrypt' do
59
+ let(:encrypted_value) { subject.encrypt('decrypted') }
60
+
61
+ it "should decrypt a string" do
62
+ expect(subject.decrypt(encrypted_value)).to eq('decrypted')
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+
46
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_secure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Middleton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-18 00:00:00.000000000 Z
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec