Commit 3eee0426 authored by Yorick Peterse's avatar Yorick Peterse

Backport EE changes to UserExtractor to CE

This backports the changes EE made to Gitlab::UserExtractor, removing
the need for an EE specific module.
parent 96eefa7f
...@@ -11,11 +11,14 @@ module Gitlab ...@@ -11,11 +11,14 @@ module Gitlab
USERNAME_REGEXP = User.reference_pattern USERNAME_REGEXP = User.reference_pattern
def initialize(text) def initialize(text)
@text = text # EE passes an Array to `text` in a few places, so we want to support both
# here.
@text = Array(text).join(' ')
end end
def users def users
return User.none unless @text.present? return User.none unless @text.present?
return User.none if references.empty?
@users ||= User.from_union(union_relations) @users ||= User.from_union(union_relations)
end end
......
...@@ -38,6 +38,18 @@ describe Gitlab::UserExtractor do ...@@ -38,6 +38,18 @@ describe Gitlab::UserExtractor do
expect(extractor.users).to include(user) expect(extractor.users).to include(user)
end end
context 'input as array of strings' do
it 'is treated as one string' do
extractor = described_class.new(text.lines)
user_1 = create(:user, username: "USER-1")
user_4 = create(:user, username: "USER-4")
user_email = create(:user, email: 'user@gitlab.org')
expect(extractor.users).to contain_exactly(user_1, user_4, user_email)
end
end
end end
describe '#matches' do describe '#matches' do
...@@ -48,6 +60,14 @@ describe Gitlab::UserExtractor do ...@@ -48,6 +60,14 @@ describe Gitlab::UserExtractor do
it 'includes all mentioned usernames' do it 'includes all mentioned usernames' do
expect(extractor.matches[:usernames]).to contain_exactly('user-1', 'user-2', 'user-4') expect(extractor.matches[:usernames]).to contain_exactly('user-1', 'user-2', 'user-4')
end end
context 'input has no matching e-mail or usernames' do
it 'returns an empty list of users' do
extractor = described_class.new('My test')
expect(extractor.users).to be_empty
end
end
end end
describe '#references' do describe '#references' do
......
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