Ensure oath callbacks without a nickname work (google)

This commit is contained in:
Jan-Willem van der Meer 2014-09-01 14:26:10 +02:00
parent 5801d520a7
commit 262276c5f5
2 changed files with 13 additions and 0 deletions

View File

@ -86,6 +86,7 @@ module Gitlab
end
def username
return unless auth.info.respond_to?(:nickname)
auth.info.nickname.to_s.force_encoding("utf-8")
end

View File

@ -68,5 +68,17 @@ describe Gitlab::OAuth::User do
user = gl_auth.create(auth)
expect(user.email).to_not be_empty
end
it 'generates a username if non provided (google)' do
info = double(
uid: 'my-uid',
name: 'John',
email: 'john@example.com'
)
auth = double(info: info, provider: 'my-provider')
user = gl_auth.create(auth)
expect(user.username).to eql 'john'
end
end
end