From 81fb775ef8a541aa8aa45a868aba0c4236a99b42 Mon Sep 17 00:00:00 2001 From: Eugene Gavrilov Date: Thu, 16 May 2019 00:15:57 +0500 Subject: [PATCH] clear pull request --- gemfiles/.bundle/config | 2 -- lib/vault/encrypted_model.rb | 14 +++++++++----- spec/dummy/app/models/person.rb | 7 ++++--- spec/spec_helper.rb | 8 ++++---- 4 files changed, 17 insertions(+), 14 deletions(-) delete mode 100644 gemfiles/.bundle/config diff --git a/gemfiles/.bundle/config b/gemfiles/.bundle/config deleted file mode 100644 index c127f802..00000000 --- a/gemfiles/.bundle/config +++ /dev/null @@ -1,2 +0,0 @@ ---- -BUNDLE_RETRY: "1" diff --git a/lib/vault/encrypted_model.rb b/lib/vault/encrypted_model.rb index 984113a5..706ecedd 100644 --- a/lib/vault/encrypted_model.rb +++ b/lib/vault/encrypted_model.rb @@ -73,13 +73,13 @@ def vault_attribute(vault_attr, options = {}) # Getter define_method(vault_attr.to_s) do - __vault_load_attributes! unless @__vault_loaded + self.__vault_load_attributes! unless @__vault_loaded instance_variable_get("@#{vault_attr}") end # Setter define_method("#{vault_attr}=") do |value| - __vault_load_attributes! unless @__vault_loaded + self.__vault_load_attributes! unless @__vault_loaded # We always set it as changed without comparing with the current value # because we allow our held values to be mutated, so we need to assume @@ -266,9 +266,11 @@ def __vault_persist_attributes! # If there are any changes to the model, update them all at once, # skipping any callbacks and validation. This is okay, because we are # already in a transaction due to the callback. - self.update_columns(changes) unless changes.empty? + if !changes.empty? + self.update_columns(changes) + end - true + return true end # Encrypt a single attribute using Vault and persist back onto the @@ -284,7 +286,9 @@ def __vault_persist_attribute!(attribute, options) plaintext = instance_variable_get("@#{attribute}") # Apply the serialize to the plaintext value, if one exists - plaintext = serializer.encode(plaintext) if serializer + if serializer + plaintext = serializer.encode(plaintext) + end # Generate context if needed generated_context = __vault_generate_context(context) diff --git a/spec/dummy/app/models/person.rb b/spec/dummy/app/models/person.rb index 53377e9e..460f22a3 100644 --- a/spec/dummy/app/models/person.rb +++ b/spec/dummy/app/models/person.rb @@ -1,4 +1,4 @@ -require 'binary_serializer' +require "binary_serializer" class Person < ActiveRecord::Base include Vault::EncryptedModel @@ -7,8 +7,8 @@ class Person < ActiveRecord::Base vault_attribute :credit_card, encrypted_column: :cc_encrypted, - path: 'credit-secrets', - key: 'people_credit_cards' + path: "credit-secrets", + key: "people_credit_cards" vault_attribute :details, serialize: :json @@ -35,3 +35,4 @@ def encryption_context "user_#{id}" end end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3f356c79..4dcf41fc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) -require 'vault/rails' +$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) +require "vault/rails" -require 'rspec' +require "rspec" RSpec.configure do |config| # Prohibit using the should syntax @@ -21,4 +21,4 @@ config.order = 'random' end -require File.expand_path('../dummy/config/environment.rb', __FILE__) +require File.expand_path("../dummy/config/environment.rb", __FILE__)