FEATURE: new API to search for a user by email

This commit is contained in:
Sam 2017-11-09 17:04:21 +11:00
parent 2d5bf0705a
commit 06365023c4
2 changed files with 18 additions and 0 deletions

View File

@ -114,6 +114,10 @@ class AdminUserIndexQuery
end
def filter_by_search
if params[:email].present?
return @query.where('user_emails.email = ?', params[:email].downcase)
end
filter = params[:filter]
if filter.present?
filter.strip!

View File

@ -188,6 +188,20 @@ describe AdminUserIndexQuery do
expect(query.to_sql.downcase).not_to include("ilike")
end
it "can correctly bypass expensive ilike query" do
user = Fabricate(:user, email: 'sam2@Sam.com')
query = AdminUserIndexQuery.new(email: 'Sam@sam.com').find_users_query
expect(query.count).to eq(0)
expect(query.to_sql.downcase).not_to include("ilike")
query = AdminUserIndexQuery.new(email: 'Sam2@sam.com').find_users_query
expect(query.first.id).to eq(user.id)
expect(query.count).to eq(1)
expect(query.to_sql.downcase).not_to include("ilike")
end
end
context "by email fragment" do