diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-09-06 11:23:22 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-09-06 11:23:22 +0000 |
commit | 98ae35a8b08c86f7a380aecfb967f092cc1e0ef0 (patch) | |
tree | 251cf64c3094839ae002b721098a89846aeeba64 /spec/lib/gitlab/user_extractor_spec.rb | |
parent | 4ad792dede4d9a68df6b4797a72c46f65bdcaccd (diff) | |
parent | c826ecc3e76917d7b77701551e25425da9274b2e (diff) | |
download | gitlab-ce-98ae35a8b08c86f7a380aecfb967f092cc1e0ef0.tar.gz |
Merge branch 'bvl-codeowners-file-ce' into 'master'
Port changes for CODEOWNERS to CE
See merge request gitlab-org/gitlab-ce!21309
Diffstat (limited to 'spec/lib/gitlab/user_extractor_spec.rb')
-rw-r--r-- | spec/lib/gitlab/user_extractor_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/lib/gitlab/user_extractor_spec.rb b/spec/lib/gitlab/user_extractor_spec.rb new file mode 100644 index 00000000000..fcc05ab3a0c --- /dev/null +++ b/spec/lib/gitlab/user_extractor_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::UserExtractor do + let(:text) do + <<~TXT + This is a long texth that mentions some users. + @user-1, @user-2 and user@gitlab.org take a walk in the park. + There they meet @user-4 that was out with other-user@gitlab.org. + @user-1 thought it was late, so went home straight away + TXT + end + subject(:extractor) { described_class.new(text) } + + describe '#users' do + it 'returns an empty relation when nil was passed' do + extractor = described_class.new(nil) + + expect(extractor.users).to be_empty + expect(extractor.users).to be_a(ActiveRecord::Relation) + end + + it 'returns the user case insensitive for usernames' do + user = create(:user, username: "USER-4") + + expect(extractor.users).to include(user) + end + + it 'returns users by primary email' do + user = create(:user, email: 'user@gitlab.org') + + expect(extractor.users).to include(user) + end + + it 'returns users by secondary email' do + user = create(:email, email: 'other-user@gitlab.org').user + + expect(extractor.users).to include(user) + end + end + + describe '#matches' do + it 'includes all mentioned email adresses' do + expect(extractor.matches[:emails]).to contain_exactly('user@gitlab.org', 'other-user@gitlab.org') + end + + it 'includes all mentioned usernames' do + expect(extractor.matches[:usernames]).to contain_exactly('user-1', 'user-2', 'user-4') + end + end + + describe '#references' do + it 'includes all user-references once' do + expect(extractor.references).to contain_exactly('user-1', 'user-2', 'user@gitlab.org', 'user-4', 'other-user@gitlab.org') + end + end +end |