auth_hash_spec.rb 1.35 KB
Newer Older
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
require 'spec_helper'

describe Gitlab::OAuth::AuthHash do
  let(:auth_hash) do
    Gitlab::OAuth::AuthHash.new(double({
      provider: 'twitter',
      uid: uid,
      info: double(info_hash)
    }))
  end
  let(:uid) { 'my-uid' }
  let(:email) { 'my-email@example.com' }
  let(:nickname) { 'my-nickname' }
  let(:info_hash) {
    {
      email: email,
      nickname: nickname,
      name: 'John',
      first_name: "John",
      last_name: "Who"
    }
  }

  context "defaults" do
    it { expect(auth_hash.provider).to eql 'twitter' }
    it { expect(auth_hash.uid).to eql uid }
    it { expect(auth_hash.email).to eql email }
    it { expect(auth_hash.username).to eql nickname }
    it { expect(auth_hash.name).to eql "John" }
    it { expect(auth_hash.password).to_not be_empty }
  end

  context "email not provided" do
    before { info_hash.delete(:email) }
    it "generates a temp email" do
      expect( auth_hash.email).to start_with('temp-email-for-oauth')
    end
  end

  context "username not provided" do
    before { info_hash.delete(:nickname) }

    it "takes the first part of the email as username" do
      expect( auth_hash.username ).to eql "my-email"
    end
  end

  context "name not provided" do
    before { info_hash.delete(:name) }

    it "concats first and lastname as the name" do
      expect( auth_hash.name ).to eql "John Who"
    end
  end
end