diff options
author | Nick Thomas <nick@gitlab.com> | 2018-11-14 18:42:36 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-11-19 12:45:07 +0000 |
commit | 59c4fb4ecb3aa81ea73a5fe75528ef969c28fa9d (patch) | |
tree | c4fb7f51773be8c797b05809081ba50d61e3a338 /spec/lib/gitlab/private_commit_email_spec.rb | |
parent | 3eb366722e32d878d56ed09a5fa596b777fccef5 (diff) | |
download | gitlab-ce-59c4fb4ecb3aa81ea73a5fe75528ef969c28fa9d.tar.gz |
Match users better by their private commit email
Private commit emails were introduced in !22560, but some parts of
GitLab were not updated to take account of them. This commit adds
support in places that were missed.
Diffstat (limited to 'spec/lib/gitlab/private_commit_email_spec.rb')
-rw-r--r-- | spec/lib/gitlab/private_commit_email_spec.rb | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/spec/lib/gitlab/private_commit_email_spec.rb b/spec/lib/gitlab/private_commit_email_spec.rb index bc86cd3842a..10bf624bbdd 100644 --- a/spec/lib/gitlab/private_commit_email_spec.rb +++ b/spec/lib/gitlab/private_commit_email_spec.rb @@ -4,6 +4,9 @@ require 'spec_helper' describe Gitlab::PrivateCommitEmail do let(:hostname) { Gitlab::CurrentSettings.current_application_settings.commit_email_hostname } + let(:id) { 1 } + let(:valid_email) { "#{id}-foo@#{hostname}" } + let(:invalid_email) { "#{id}-foo@users.noreply.bar.com" } context '.regex' do subject { described_class.regex } @@ -16,18 +19,25 @@ describe Gitlab::PrivateCommitEmail do end context '.user_id_for_email' do - let(:id) { 1 } - it 'parses user id from email' do - email = "#{id}-foo@#{hostname}" - - expect(described_class.user_id_for_email(email)).to eq(id) + expect(described_class.user_id_for_email(valid_email)).to eq(id) end it 'returns nil on invalid commit email' do - email = "#{id}-foo@users.noreply.bar.com" + expect(described_class.user_id_for_email(invalid_email)).to be_nil + end + end + + context '.user_ids_for_email' do + it 'returns deduplicated user IDs for each valid email' do + result = described_class.user_ids_for_emails([valid_email, valid_email, invalid_email]) + + expect(result).to eq([id]) + end - expect(described_class.user_id_for_email(email)).to be_nil + it 'returns an empty array with no valid emails' do + result = described_class.user_ids_for_emails([invalid_email]) + expect(result).to eq([]) end end |