attr_vault 0.0.6 → 0.0.7

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: 51257ff03a337f75042850857d0f468a7b55b6c7
4
- data.tar.gz: d57fad1f79b934d11ff0e087e80b0e6acc04ea27
3
+ metadata.gz: 0aa597401fd64a09739ef2bae49e733dfc685ef0
4
+ data.tar.gz: d142b54cfb76ca707a3f9870e8e6e371b3dd4cd0
5
5
  SHA512:
6
- metadata.gz: d5e950284be5139fc7596f8eb6ace59132eaa2046245079fa5d421a0f41ae668a984dd546f4ced3004a28142af4fb93cb9596b7a02c6d57d4cbd1a7d72e1e722
7
- data.tar.gz: 49c6168c1f49ce9ec1a78f596db759beb8b65aeb967a6853154e6c1fd65684972767da413b1bb0dc12d176e013506c887cc6eaef52a218d09cebcee404defff1
6
+ metadata.gz: b3b314083ed69c69238ed2ec49d153bdc4a308198d4678125b761961d248862a6f5a9e28bd62b999d84d63454fd816f2bc8f2ec939181b99093114580960630c
7
+ data.tar.gz: dd9845748629a782392981a759d4d2ac209dad8ee481f439284e61c92aec8ff0696c17521ad1cf066c194cd6b5cc70039ac8c270af0adaa7902be63c4f74ab26
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attr_vault (0.0.6)
4
+ attr_vault (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module AttrVault
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/attr_vault.rb CHANGED
@@ -28,16 +28,16 @@ module AttrVault
28
28
  # they're set explicitly in a new record, in which case they
29
29
  # will be in the dirty attrs already and are handled below.
30
30
  self.class.vault_attrs.each do |attr|
31
- next if @vault_dirty_attrs.has_key? attr.name
32
- @vault_dirty_attrs[attr.name] = self.send(attr.name)
31
+ @vault_dirty_attrs[attr.name] ||= self.send(attr.name)
33
32
  end
34
33
  end
35
34
  # If any attr has plaintext_source_field and the plaintext field
36
35
  # has a value set, flag the attr as dirty using the plaintext
37
- # source value, then nil out the plaintext field.
36
+ # source value, then nil out the plaintext field. Skip any
37
+ # attributes that are already dirty.
38
38
  self.class.vault_attrs.reject { |attr| attr.plaintext_source_field.nil? }.each do |attr|
39
39
  unless self[attr.plaintext_source_field].nil?
40
- @vault_dirty_attrs[attr.name] = self[attr.plaintext_source_field]
40
+ @vault_dirty_attrs[attr.name] ||= self[attr.plaintext_source_field]
41
41
  self[attr.plaintext_source_field] = nil
42
42
  end
43
43
  end
@@ -287,6 +287,19 @@ describe AttrVault do
287
287
  expect(reloaded.other_not_secret).to be_nil
288
288
  expect(reloaded.other).to eq becomes_secret2
289
289
  end
290
+
291
+ it "nils out the plaintext field and persists the encrypted field on save" do
292
+ becomes_secret = 'the location of all those socks that disappear from the dryer'
293
+ new_secret = 'the location of pliny the younger drafts'
294
+ s = item1.create(not_secret: becomes_secret)
295
+ reloaded = item2[s.id]
296
+ expect(reloaded.secret).to eq(becomes_secret)
297
+ reloaded.secret = new_secret
298
+ expect(reloaded.secret).to eq(new_secret)
299
+ reloaded.save
300
+ expect(reloaded.secret).to eq(new_secret)
301
+ expect(reloaded.not_secret).to be_nil
302
+ end
290
303
  end
291
304
 
292
305
  context "with renamed database fields" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_vault
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciek Sakrejda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec