user_spec.rb 1.81 KB
Newer Older
Jacob Vosmaer's avatar
Jacob Vosmaer committed
1 2
require 'spec_helper'

3
describe Gitlab::Git::User do
4 5 6
  let(:username) { 'janedoe' }
  let(:name) { 'Jane Doé' }
  let(:email) { 'janedoé@example.com' }
Jacob Vosmaer's avatar
Jacob Vosmaer committed
7
  let(:gl_id) { 'user-123' }
8 9 10
  let(:user) do
    described_class.new(username, name, email, gl_id)
  end
Jacob Vosmaer's avatar
Jacob Vosmaer committed
11

12
  subject { described_class.new(username, name, email, gl_id) }
Jacob Vosmaer's avatar
Jacob Vosmaer committed
13

14
  describe '.from_gitaly' do
15
    let(:gitaly_user) do
16
      Gitaly::User.new(gl_username: username, name: name.b, email: email.b, gl_id: gl_id)
17 18
    end

19 20
    subject { described_class.from_gitaly(gitaly_user) }

21
    it { expect(subject).to eq(user) }
22 23 24 25 26 27 28 29 30
  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

Jacob Vosmaer's avatar
Jacob Vosmaer committed
31
  describe '#==' do
32 33
    def eq_other(username, name, email, gl_id)
      eq(described_class.new(username, name, email, gl_id))
Jacob Vosmaer's avatar
Jacob Vosmaer committed
34 35
    end

36
    it { expect(subject).to eq_other(username, name, email, gl_id) }
Jacob Vosmaer's avatar
Jacob Vosmaer committed
37

38 39 40 41 42
    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') }
Jacob Vosmaer's avatar
Jacob Vosmaer committed
43
  end
44 45 46 47 48 49 50

  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)
51 52 53 54 55 56 57

      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

58 59 60
      expect(subject.gl_id).to eq(gl_id)
    end
  end
Jacob Vosmaer's avatar
Jacob Vosmaer committed
61
end