Commit d9919421 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'allow-username-search-to-work-with-at-sign' into 'master'

Allow users to be found by @username

See merge request gitlab-org/gitlab!17742
parents 13ffe7dd 08e281a5
...@@ -444,6 +444,7 @@ class User < ApplicationRecord ...@@ -444,6 +444,7 @@ class User < ApplicationRecord
# #
# Returns an ActiveRecord::Relation. # Returns an ActiveRecord::Relation.
def search(query) def search(query)
query = query&.delete_prefix('@')
return none if query.blank? return none if query.blank?
query = query.downcase query = query.downcase
......
---
title: Allow users to be searched with a @ prefix
merge_request: 17742
author:
type: added
...@@ -1427,10 +1427,18 @@ describe User do ...@@ -1427,10 +1427,18 @@ describe User do
expect(described_class.search(user.username)).to eq([user, user2]) expect(described_class.search(user.username)).to eq([user, user2])
end end
it 'returns users with a matching username starting with a @' do
expect(described_class.search("@#{user.username}")).to eq([user, user2])
end
it 'returns users with a partially matching username' do it 'returns users with a partially matching username' do
expect(described_class.search(user.username[0..2])).to eq([user, user2]) expect(described_class.search(user.username[0..2])).to eq([user, user2])
end end
it 'returns users with a partially matching username starting with @' do
expect(described_class.search("@#{user.username[0..2]}")).to eq([user, user2])
end
it 'returns users with a matching username regardless of the casing' do it 'returns users with a matching username regardless of the casing' do
expect(described_class.search(user2.username.upcase)).to eq([user2]) expect(described_class.search(user2.username.upcase)).to eq([user2])
end end
......
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