gitlab-org--gitlab-foss/spec/lib/gitlab/git/user_spec.rb

62 lines
1.8 KiB
Ruby
Raw Normal View History

2017-08-23 11:23:28 -04:00
require 'spec_helper'
2017-09-13 12:16:56 -04:00
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' }
let(:user) do
described_class.new(username, name, email, gl_id)
end
2017-08-23 11:23:28 -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
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)
end
2017-10-03 12:53:11 -04:00
subject { described_class.from_gitaly(gitaly_user) }
it { expect(subject).to eq(user) }
2017-10-03 12:53:11 -04:00
end
describe '.from_gitlab' do
let(:user) { build(:user) }
subject { described_class.from_gitlab(user) }
it { expect(subject).to eq(described_class.new(user.username, user.name, user.email, 'user-')) }
end
2017-08-23 11:23:28 -04:00
describe '#==' do
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
it { expect(subject).to eq_other(username, name, email, gl_id) }
2017-08-23 11:23:28 -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
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
expect(subject.gl_id).to eq(gl_id)
end
end
2017-08-23 11:23:28 -04:00
end