Skip to content

Commit

Permalink
Merge pull request #5643 from dodona-edu/feat/filter-users-by-email
Browse files Browse the repository at this point in the history
Allow filtering users by email
  • Loading branch information
jorg-vr authored Nov 19, 2024
2 parents 2cf5203 + 1b4d0d1 commit 429e80e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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 @@ -1223,4 +1223,14 @@ def setup

assert_not user.reload.open_questions?
end

test 'should be able to search by email' do
first = create :user, email: '[email protected]'
second = create :user, email: '[email protected]'

assert_equal first, User.by_filter('[email protected]').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

0 comments on commit 429e80e

Please sign in to comment.