From f60da50cdc4d98185fd2d76ee153afab982f766c Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Tue, 25 Jun 2024 15:47:09 +0200 Subject: [PATCH] Allow filtering users by email --- app/models/user.rb | 2 +- test/models/user_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 75b4b0ff7b..9150946039 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/test/models/user_test.rb b/test/models/user_test.rb index b940f77a77..b50601400b 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -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