summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ldap/user_spec.rb
blob: 726c9764e3d23ebf0faea6217fac03866e570531 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'spec_helper'

describe Gitlab::LDAP::User do
  let(:gl_user) { Gitlab::LDAP::User.new(auth_hash) }
  let(:info) do
    {
      name: 'John',
      email: 'john@example.com',
      nickname: 'john'
    }
  end
  let(:auth_hash) do
    double(uid: 'my-uid', provider: 'ldapmain', info: double(info))
  end

  describe :find_or_create do
    it "finds the user if already existing" do
      existing_user = create(:user, extern_uid: 'my-uid', provider: 'ldapmain')

      expect{ gl_user.save }.to_not change{ User.count }
    end

    it "connects to existing non-ldap user if the email matches" do
      existing_user = create(:user, email: 'john@example.com')
      expect{ gl_user.save }.to_not change{ User.count }

      existing_user.reload
      expect(existing_user.extern_uid).to eql 'my-uid'
      expect(existing_user.provider).to eql 'ldapmain'
    end

    it "creates a new user if not found" do
      expect{ gl_user.save }.to change{ User.count }.by(1)
    end
  end
end