From 262276c5f55802541f4df19a44488b4f5239054c Mon Sep 17 00:00:00 2001 From: Jan-Willem van der Meer Date: Mon, 1 Sep 2014 14:26:10 +0200 Subject: [PATCH] Ensure oath callbacks without a nickname work (google) --- lib/gitlab/oauth/user.rb | 1 + spec/lib/gitlab/oauth/user_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/gitlab/oauth/user.rb b/lib/gitlab/oauth/user.rb index 5efd5799f9f..1b04dffc3a8 100644 --- a/lib/gitlab/oauth/user.rb +++ b/lib/gitlab/oauth/user.rb @@ -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 diff --git a/spec/lib/gitlab/oauth/user_spec.rb b/spec/lib/gitlab/oauth/user_spec.rb index d6ac0c0896b..7dcc849454b 100644 --- a/spec/lib/gitlab/oauth/user_spec.rb +++ b/spec/lib/gitlab/oauth/user_spec.rb @@ -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