Skip to content

Commit

Permalink
Fix missing Dirty methods not being generated
Browse files Browse the repository at this point in the history
  • Loading branch information
finalwharf committed Oct 26, 2018
1 parent 78acc92 commit b065151
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
24 changes: 24 additions & 0 deletions lib/vault/active_record/associations/join_dependency/join_part.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'active_record'
# Force ther original JoinPart to load
require 'active_record/associations/join_dependency/join_part'

module ActiveRecord
module Associations
class JoinDependency
class JoinPart
# Prevent virtual attributes from being included in JOIN sql queries.
# This will work with both ActiveRecord 4 an 5 because in the original
# implementation this methos is delegated to the base class - the model.
def column_names
column_names = base_klass.column_names

if base_klass.methods.include? :persistable_attribute_names
column_names = column_names & base_klass.persistable_attribute_names
end

column_names
end
end
end
end
end
7 changes: 0 additions & 7 deletions lib/vault/encrypted_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@ def __vault_load_attributes!
end
end

# In ActiveRecord 4.2, virtual attributes are not excluded from joins aliases
if respond_to?(:persistable_attribute_names)
def self.column_names
super & persistable_attribute_names
end
end

# Decrypt and load a single attribute from Vault.
def __vault_load_attribute!(attribute, options)
# If the user provided a value for the attribute, do not try to load it from Vault
Expand Down
1 change: 1 addition & 0 deletions lib/vault/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_relative 'rails/serializers/integer_serializer'
require_relative 'rails/serializers/float_serializer'
require_relative 'rails/version'
require_relative 'active_record/associations/join_dependency/join_part'

module Vault
module Rails
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class Person < ActiveRecord::Base

has_many :problems

before_validation :format_ssn, if: -> { ssn_changed? }

def format_ssn; end

vault_attribute :county_plaintext, encrypted_column: :county_encrypted
vault_attribute_proxy :county, :county_plaintext

Expand Down

0 comments on commit b065151

Please sign in to comment.