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 7628010e..3aa2498f 100644 --- a/lib/vault/encrypted_model.rb +++ b/lib/vault/encrypted_model.rb @@ -69,13 +69,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 @@ -247,9 +247,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 @@ -264,7 +266,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 the ciphertext and store it back as an attribute ciphertext = Vault::Rails.encrypt(path, key, plaintext) diff --git a/spec/dummy/app/models/person.rb b/spec/dummy/app/models/person.rb index d477f71d..c52ccae2 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 @@ -22,3 +22,4 @@ class Person < ActiveRecord::Base vault_attribute :non_ascii 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__)