Commit f0a4893c authored by Steve Abrams's avatar Steve Abrams

Merge branch 'compare-lowercase-values-in-user-search' into 'master'

Use lowercase values in user search ordering

See merge request gitlab-org/gitlab!81828
parents 208fb01e e59a0922
...@@ -668,9 +668,9 @@ class User < ApplicationRecord ...@@ -668,9 +668,9 @@ class User < ApplicationRecord
order = <<~SQL order = <<~SQL
CASE CASE
WHEN users.name = :query THEN 0 WHEN LOWER(users.name) = :query THEN 0
WHEN users.username = :query THEN 1 WHEN LOWER(users.username) = :query THEN 1
WHEN users.public_email = :query THEN 2 WHEN LOWER(users.public_email) = :query THEN 2
ELSE 3 ELSE 3
END END
SQL SQL
......
...@@ -2741,6 +2741,19 @@ RSpec.describe User do ...@@ -2741,6 +2741,19 @@ RSpec.describe User do
let_it_be(:user3) { create(:user, name: 'us', username: 'se', email: 'foo@example.com') } let_it_be(:user3) { create(:user, name: 'us', username: 'se', email: 'foo@example.com') }
let_it_be(:email) { create(:email, user: user, email: 'alias@example.com') } let_it_be(:email) { create(:email, user: user, email: 'alias@example.com') }
describe 'name user and email relative ordering' do
let_it_be(:named_alexander) { create(:user, name: 'Alexander Person', username: 'abcd', email: 'abcd@example.com') }
let_it_be(:username_alexand) { create(:user, name: 'Joao Alexander', username: 'Alexand', email: 'joao@example.com') }
it 'prioritizes exact matches' do
expect(described_class.search('Alexand')).to eq([username_alexand, named_alexander])
end
it 'falls back to ordering by name' do
expect(described_class.search('Alexander')).to eq([named_alexander, username_alexand])
end
end
describe 'name matching' do describe 'name matching' do
it 'returns users with a matching name with exact match first' do it 'returns users with a matching name with exact match first' do
expect(described_class.search(user.name)).to eq([user, user2]) expect(described_class.search(user.name)).to eq([user, user2])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment