diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-11-07 13:52:08 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-11-07 13:52:08 +0000 |
commit | ad7d0cb2f4395d4abca83acd9b98b17fc73523c0 (patch) | |
tree | 06bc505c89da581d43b9a17d7e16f3dba4c64293 /spec/lib/gitlab | |
parent | e60e591fca3dd720c9a8b3e767d7b1b9f4560967 (diff) | |
parent | c239452b47f2819e3ed2fdaf4679737b3e1a456e (diff) | |
download | gitlab-ce-ad7d0cb2f4395d4abca83acd9b98b17fc73523c0.tar.gz |
Merge branch '43521-keep-personal-emails-private' into 'master'
Adds option to override commit email
Closes #43521
See merge request gitlab-org/gitlab-ce!22560
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/private_commit_email_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/lib/gitlab/private_commit_email_spec.rb b/spec/lib/gitlab/private_commit_email_spec.rb new file mode 100644 index 00000000000..bc86cd3842a --- /dev/null +++ b/spec/lib/gitlab/private_commit_email_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::PrivateCommitEmail do + let(:hostname) { Gitlab::CurrentSettings.current_application_settings.commit_email_hostname } + + context '.regex' do + subject { described_class.regex } + + it { is_expected.to match("1-foo@#{hostname}") } + it { is_expected.not_to match("1-foo@#{hostname}.foo") } + it { is_expected.not_to match('1-foo@users.noreply.gitlab.com') } + it { is_expected.not_to match('foo-1@users.noreply.gitlab.com') } + it { is_expected.not_to match('foobar@gitlab.com') } + 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) + end + + it 'returns nil on invalid commit email' do + email = "#{id}-foo@users.noreply.bar.com" + + expect(described_class.user_id_for_email(email)).to be_nil + end + end + + context '.for_user' do + it 'returns email in the format id-username@hostname' do + user = create(:user) + + expect(described_class.for_user(user)).to eq("#{user.id}-#{user.username}@#{hostname}") + end + end +end |