diff --git a/lib/auth/github_authenticator.rb b/lib/auth/github_authenticator.rb index fa274b4e935..2d3f705cf30 100644 --- a/lib/auth/github_authenticator.rb +++ b/lib/auth/github_authenticator.rb @@ -41,7 +41,7 @@ class Auth::GithubAuthenticator < Auth::Authenticator # If there's existing user info with the given GitHub ID, that's all we # need to know. user = user_info.user - result.email = data[:email], + result.email = data[:email] result.email_valid = data[:email].present? else # Potentially use *any* of the emails from GitHub to find a match or diff --git a/spec/components/auth/github_authenticator_spec.rb b/spec/components/auth/github_authenticator_spec.rb index 50c5cdf0f2d..011c440971b 100644 --- a/spec/components/auth/github_authenticator_spec.rb +++ b/spec/components/auth/github_authenticator_spec.rb @@ -24,9 +24,8 @@ describe Auth::GithubAuthenticator do let(:user) { Fabricate(:user) } context 'after_authenticate' do - - it 'can authenticate and create a user record for already existing users' do - hash = { + let(:data) do + { extra: { all_emails: [{ email: user.email, @@ -41,14 +40,22 @@ describe Auth::GithubAuthenticator do }, uid: "100" } + end - result = authenticator.after_authenticate(hash) + it 'can authenticate and create a user record for already existing users' do + result = authenticator.after_authenticate(data) expect(result.user.id).to eq(user.id) expect(result.username).to eq(user.username) expect(result.name).to eq(user.name) expect(result.email).to eq(user.email) expect(result.email_valid).to eq(true) + + # Authenticates again when user has Github user info + result = authenticator.after_authenticate(data) + + expect(result.email).to eq(user.email) + expect(result.email_valid).to eq(true) end it 'should use primary email for new user creation over other available emails' do