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

Allow filtering users by email #5643

Open
wants to merge 3 commits into
base: main
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 app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class User < ApplicationRecord

accepts_nested_attributes_for :identities, limit: 1

search_by :username, :first_name, :last_name
search_by :username, :first_name, :last_name, :email

scope :by_permission, ->(permission) { where(permission: permission) }
filterable_by :institution_id, model: Institution
Expand Down
10 changes: 10 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1150,4 +1150,14 @@ def setup

assert_not user.reload.open_questions?
end

test 'should be able to search by email' do
first = create :user, email: 'foo@bar.com'
second = create :user, email: 'foo@bax.com'

assert_equal first, User.by_filter('foo@bar.com').first
assert_equal second, User.by_filter('ax.com').first
assert_empty User.by_filter('baz')
assert_equal 2, User.by_filter('foo@ba').count
end
end