Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out decrypted attributes in ActiveRecord #354

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion attr_encrypted.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('activerecord-jdbcsqlite3-adapter')
s.add_development_dependency('jdbc-sqlite3', '< 3.8.7') # 3.8.7 is nice and broke
else
s.add_development_dependency('sqlite3')
s.add_development_dependency('sqlite3', '~> 1.3.0', '>= 1.3.6')
end
s.add_development_dependency('dm-sqlite-adapter')
s.add_development_dependency('simplecov')
Expand Down
6 changes: 6 additions & 0 deletions lib/attr_encrypted/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def assign_attributes(*args)
def attributes=(*args)
perform_attribute_assignment :attributes_without_attr_encrypted=, *args
end

alias_method :attributes_without_attr_encrypted, :attributes
def attributes
encrypted_keys = self.class.encrypted_attributes.keys
attributes_without_attr_encrypted.reject { |k, _| encrypted_keys.include?(k.to_sym) }
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is an inconsistency. #has_attribute? will return true for encrypted attributes as it relies on @attributes.

end
end

Expand Down
5 changes: 5 additions & 0 deletions test/active_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,9 @@ def test_should_evaluate_proc_based_mode
refute_equal address.encrypted_zipcode, zipcode
assert_equal address.zipcode, zipcode
end

def test_should_filter_decrypted_attributes
@person = Person.new(email: '[email protected]')
refute @person.attributes.keys.include? "email"
end
end