From 5801d520a75ce03339944d67cfde6cc3c1b05cfc Mon Sep 17 00:00:00 2001
From: Jan-Willem van der Meer <mail@jewilmeer.nl>
Date: Mon, 1 Sep 2014 13:48:17 +0200
Subject: [PATCH] Handle user creation if email is not provided

This fixes #1541
---
 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 8c426d810c2..5efd5799f9f 100644
--- a/lib/gitlab/oauth/user.rb
+++ b/lib/gitlab/oauth/user.rb
@@ -73,6 +73,7 @@ module Gitlab
         end
 
         def email
+          return unless auth.info.respond_to?(:email)
           auth.info.email.downcase unless auth.info.email.nil?
         end
 
diff --git a/spec/lib/gitlab/oauth/user_spec.rb b/spec/lib/gitlab/oauth/user_spec.rb
index 347723f6943..d6ac0c0896b 100644
--- a/spec/lib/gitlab/oauth/user_spec.rb
+++ b/spec/lib/gitlab/oauth/user_spec.rb
@@ -56,5 +56,17 @@ describe Gitlab::OAuth::User do
       user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit
       user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group
     end
+
+    it "Set a temp email address if not provided (like twitter does)" do
+      info = double(
+        uid: 'my-uid',
+        nickname: 'john',
+        name: 'John'
+      )
+      auth = double(info: info, provider: 'my-provider')
+
+      user = gl_auth.create(auth)
+      expect(user.email).to_not be_empty
+    end
   end
 end
-- 
2.30.9