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

53 lines
1.5 KiB
Ruby
Raw Normal View History

2013-09-03 21:53:13 +00:00
require 'spec_helper'
describe Gitlab::OAuth::User do
2014-10-10 10:03:32 +00:00
let(:oauth_user) { Gitlab::OAuth::User.new(auth_hash) }
let(:gl_user) { oauth_user.gl_user }
let(:uid) { 'my-uid' }
let(:provider) { 'my-provider' }
let(:auth_hash) { double(uid: uid, provider: provider, info: double(info_hash)) }
let(:info_hash) do
{
nickname: 'john',
2013-09-03 21:53:13 +00:00
name: 'John',
email: 'john@mail.com'
2014-10-10 10:03:32 +00:00
}
2013-09-03 21:53:13 +00:00
end
2014-10-10 10:03:32 +00:00
describe :persisted? do
let!(:existing_user) { create(:user, extern_uid: 'my-uid', provider: 'my-provider') }
it "finds an existing user based on uid and provider (facebook)" do
auth = double(info: double(name: 'John'), uid: 'my-uid', provider: 'my-provider')
2014-10-10 10:03:32 +00:00
expect( oauth_user.persisted? ).to be_true
end
2014-10-10 10:03:32 +00:00
it "returns false if use is not found in database" do
auth_hash.stub(uid: 'non-existing')
expect( oauth_user.persisted? ).to be_false
end
end
2014-10-10 10:03:32 +00:00
describe :save do
let(:provider) { 'twitter' }
2013-09-03 21:53:13 +00:00
context "with allow_single_sign_on enabled" do
before { Gitlab.config.omniauth.stub allow_single_sign_on: true }
2014-10-10 10:03:32 +00:00
it "creates a user from Omniauth" do
oauth_user.save
2014-10-10 10:03:32 +00:00
expect(gl_user).to be_valid
expect(gl_user.extern_uid).to eql uid
expect(gl_user.provider).to eql 'twitter'
end
end
context "with allow_single_sign_on disabled (Default)" do
it "throws an error" do
expect{ oauth_user.save }.to raise_error StandardError
end
end
2013-09-03 21:53:13 +00:00
end
end