2019-11-21 04:06:16 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-23 11:23:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Git::User do
|
2017-11-23 05:48:57 -05:00
|
|
|
let(:username) { 'janedoe' }
|
|
|
|
let(:name) { 'Jane Doé' }
|
|
|
|
let(:email) { 'janedoé@example.com' }
|
2017-08-23 11:23:28 -04:00
|
|
|
let(:gl_id) { 'user-123' }
|
2017-10-23 16:31:05 -04:00
|
|
|
let(:user) do
|
|
|
|
described_class.new(username, name, email, gl_id)
|
|
|
|
end
|
2017-08-23 11:23:28 -04:00
|
|
|
|
2017-08-02 14:14:50 -04:00
|
|
|
subject { described_class.new(username, name, email, gl_id) }
|
2017-08-23 11:23:28 -04:00
|
|
|
|
2017-10-03 12:53:11 -04:00
|
|
|
describe '.from_gitaly' do
|
2017-10-23 16:31:05 -04:00
|
|
|
let(:gitaly_user) do
|
2017-11-23 05:48:57 -05:00
|
|
|
Gitaly::User.new(gl_username: username, name: name.b, email: email.b, gl_id: gl_id)
|
2017-10-23 16:31:05 -04:00
|
|
|
end
|
|
|
|
|
2017-10-03 12:53:11 -04:00
|
|
|
subject { described_class.from_gitaly(gitaly_user) }
|
|
|
|
|
2017-10-23 16:31:05 -04:00
|
|
|
it { expect(subject).to eq(user) }
|
2017-10-03 12:53:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.from_gitlab' do
|
2018-09-14 05:52:09 -04:00
|
|
|
context 'when no commit_email has been set' do
|
|
|
|
let(:user) { build(:user, email: 'alice@example.com', commit_email: nil) }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2018-09-14 05:52:09 -04:00
|
|
|
subject { described_class.from_gitlab(user) }
|
2017-10-03 12:53:11 -04:00
|
|
|
|
2018-09-14 05:52:09 -04:00
|
|
|
it { expect(subject).to eq(described_class.new(user.username, user.name, user.email, 'user-')) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when commit_email has been set' do
|
|
|
|
let(:user) { build(:user, email: 'alice@example.com', commit_email: 'bob@example.com') }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2018-09-14 05:52:09 -04:00
|
|
|
subject { described_class.from_gitlab(user) }
|
|
|
|
|
|
|
|
it { expect(subject).to eq(described_class.new(user.username, user.name, user.commit_email, 'user-')) }
|
|
|
|
end
|
2017-10-03 12:53:11 -04:00
|
|
|
end
|
|
|
|
|
2017-08-23 11:23:28 -04:00
|
|
|
describe '#==' do
|
2017-08-02 14:14:50 -04:00
|
|
|
def eq_other(username, name, email, gl_id)
|
|
|
|
eq(described_class.new(username, name, email, gl_id))
|
2017-08-23 11:23:28 -04:00
|
|
|
end
|
|
|
|
|
2017-08-02 14:14:50 -04:00
|
|
|
it { expect(subject).to eq_other(username, name, email, gl_id) }
|
2017-08-23 11:23:28 -04:00
|
|
|
|
2017-08-02 14:14:50 -04:00
|
|
|
it { expect(subject).not_to eq_other(nil, nil, nil, nil) }
|
|
|
|
it { expect(subject).not_to eq_other(username + 'x', name, email, gl_id) }
|
|
|
|
it { expect(subject).not_to eq_other(username, name + 'x', email, gl_id) }
|
|
|
|
it { expect(subject).not_to eq_other(username, name, email + 'x', gl_id) }
|
|
|
|
it { expect(subject).not_to eq_other(username, name, email, gl_id + 'x') }
|
2017-08-23 11:23:28 -04:00
|
|
|
end
|
2017-10-23 16:31:05 -04:00
|
|
|
|
|
|
|
describe '#to_gitaly' do
|
|
|
|
subject { user.to_gitaly }
|
|
|
|
|
|
|
|
it 'creates a Gitaly::User with the correct data' do
|
|
|
|
expect(subject).to be_a(Gitaly::User)
|
|
|
|
expect(subject.gl_username).to eq(username)
|
2017-11-23 05:48:57 -05:00
|
|
|
|
|
|
|
expect(subject.name).to eq(name.b)
|
|
|
|
expect(subject.name).to be_a_binary_string
|
|
|
|
|
|
|
|
expect(subject.email).to eq(email.b)
|
|
|
|
expect(subject.email).to be_a_binary_string
|
|
|
|
|
2017-10-23 16:31:05 -04:00
|
|
|
expect(subject.gl_id).to eq(gl_id)
|
|
|
|
end
|
|
|
|
end
|
2017-08-23 11:23:28 -04:00
|
|
|
end
|