Skip to content

Commit

Permalink
Merge pull request #71 from FundingCircle/0.6-adds_encrypted_where_not
Browse files Browse the repository at this point in the history
Adds encrypted_where_not
  • Loading branch information
ahmetabdi authored Mar 15, 2019
2 parents 441642e + 7eabf97 commit b6c4a0d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Vault Rails Changelog

## v0.6.12 (March 14, 2019)

NEW FEATURES
- Added `encrypted_where_not` finds encrypted records not matching the specified conditions

## v0.6.11 (March 8, 2019)

NEW FEATURES
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ This method will look up seamlessly in the relevant column with encrypted data.
It is important to note that you can search only for attributes with **convergent** encryption.
Similar to `.where` the method `.encrypted_where` also returns an `ActiveRecord::Relation`

There is also `.encrypted_find_by` which works like `.find_by` finds the first encrypted record matching the specified conditions
Along with `.encrypted_where` we also have `.encrypted_where_not` which finds encrypted records not matching the specified conditions acts like `.where.not`

There is also `.encrypted_find_by` which works like `.find_by` finds the first encrypted record matching the specified conditions.

```ruby
Personal.encrypted_find_by(driving_licence_number: '12345678')
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_4.2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
fc-vault-rails (0.6.11)
fc-vault-rails (0.6.12)
activerecord (>= 4.2, < 5.0)
vault (~> 0.7)

Expand Down
4 changes: 4 additions & 0 deletions lib/vault/encrypted_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ def encrypted_where(attributes)
where(search_options(attributes))
end

def encrypted_where_not(attributes)
where.not(search_options(attributes))
end

private

def search_options(attributes)
Expand Down
2 changes: 1 addition & 1 deletion lib/vault/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Vault
module Rails
VERSION = "0.6.11"
VERSION = "0.6.12"
end
end
14 changes: 14 additions & 0 deletions spec/integration/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -731,4 +731,18 @@
end
end
end

describe '.encrypted_where_not' do
before do
allow(Vault::Rails).to receive(:convergent_encryption_context).and_return('a' * 16).at_least(:once)
end

it 'finds the expected records' do
first_person = LazyPerson.create!(passport_number: '12345678')
second_person = LazyPerson.create!(passport_number: '12345678')
third_person = LazyPerson.create!(passport_number: '87654321')

expect(LazyPerson.encrypted_where_not(passport_number: nil).pluck(:id)).to match_array([first_person, second_person, third_person].map(&:id))
end
end
end

0 comments on commit b6c4a0d

Please # to comment.