debian-mirror-gitlab/spec/lib/gitlab/private_commit_email_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.6 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::PrivateCommitEmail do
2018-12-13 13:39:08 +05:30
let(:hostname) { Gitlab::CurrentSettings.current_application_settings.commit_email_hostname }
2019-02-15 15:39:39 +05:30
let(:id) { 1 }
let(:valid_email) { "#{id}-foo@#{hostname}" }
let(:invalid_email) { "#{id}-foo@users.noreply.bar.com" }
2018-12-13 13:39:08 +05:30
2020-03-13 15:44:24 +05:30
describe '.regex' do
2018-12-13 13:39:08 +05:30
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
2020-03-13 15:44:24 +05:30
describe '.user_id_for_email' do
2018-12-13 13:39:08 +05:30
it 'parses user id from email' do
2019-02-15 15:39:39 +05:30
expect(described_class.user_id_for_email(valid_email)).to eq(id)
2018-12-23 12:14:25 +05:30
end
2019-01-03 12:48:30 +05:30
it 'returns nil on invalid commit email' do
2019-02-15 15:39:39 +05:30
expect(described_class.user_id_for_email(invalid_email)).to be_nil
end
end
2020-03-13 15:44:24 +05:30
describe '.user_ids_for_email' do
2019-02-15 15:39:39 +05:30
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
2018-12-13 13:39:08 +05:30
2019-02-15 15:39:39 +05:30
it 'returns an empty array with no valid emails' do
result = described_class.user_ids_for_emails([invalid_email])
expect(result).to eq([])
2018-12-13 13:39:08 +05:30
end
end
2020-03-13 15:44:24 +05:30
describe '.for_user' do
2018-12-13 13:39:08 +05:30
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