diff --git a/attr_encrypted.gemspec b/attr_encrypted.gemspec index 41f96ed9..5eb12e56 100644 --- a/attr_encrypted.gemspec +++ b/attr_encrypted.gemspec @@ -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') diff --git a/lib/attr_encrypted/adapters/active_record.rb b/lib/attr_encrypted/adapters/active_record.rb index fca9343e..59ce0f28 100644 --- a/lib/attr_encrypted/adapters/active_record.rb +++ b/lib/attr_encrypted/adapters/active_record.rb @@ -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 end end diff --git a/test/active_record_test.rb b/test/active_record_test.rb index 8ec31aea..7d0d53f4 100644 --- a/test/active_record_test.rb +++ b/test/active_record_test.rb @@ -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: 'test@example.com') + refute @person.attributes.keys.include? "email" + end end