summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-11-19 16:53:14 +0000
committerDouwe Maan <douwe@gitlab.com>2018-11-19 16:53:14 +0000
commitaf1ed0e2bbabb72aff521aa2d67a4325dd94f711 (patch)
tree143fac4538c3b20d5479c1f4096f52be26c870a8 /spec/lib
parentd5f08596305a7643d884e57ffc0375c6a5a7dbcb (diff)
parent59c4fb4ecb3aa81ea73a5fe75528ef969c28fa9d (diff)
downloadgitlab-ce-af1ed0e2bbabb72aff521aa2d67a4325dd94f711.tar.gz
Merge branch '54046-fix-by-any-email-for-private-commit-emails' into 'master'
Match users better by their private commit email Closes #54046 See merge request gitlab-org/gitlab-ce!23080
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/private_commit_email_spec.rb24
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