From 0d22a77c63b6fe2569ab94a9dc205aeef67364f1 Mon Sep 17 00:00:00 2001 From: Einar Jonsson Date: Sun, 25 Aug 2013 20:18:07 +0000 Subject: [PATCH] Added test case for nickname registration failure * Also made a minor readability change by moving the auth.present? check * from UsersController#create into #create_third_party_auth_records * which is the method that relies on the check. --- app/controllers/users_controller.rb | 4 +++- spec/controllers/users_controller_spec.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d58892815fc..b965fdaf433 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -167,7 +167,7 @@ class UsersController < ApplicationController if user.save activator = UserActivator.new(user, session, cookies) message = activator.activation_message - create_third_party_auth_records(user, auth) if auth.present? + create_third_party_auth_records(user, auth) # Clear authentication session. session[:authentication] = nil @@ -408,6 +408,8 @@ class UsersController < ApplicationController end def create_third_party_auth_records(user, auth) + return unless auth.present? + if twitter_auth?(auth) TwitterUserInfo.create( user_id: user.id, diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 96308a06853..b7aa04086ac 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -490,6 +490,21 @@ describe UsersController do include_examples 'failed signup' end + context 'when nickname is unavailable in DiscourseHub' do + before do + SiteSetting.stubs(:call_discourse_hub?).returns(true) + DiscourseHub.stubs(:register_nickname).raises(DiscourseHub::NicknameUnavailable) + end + let(:create_params) {{ + name: @user.name, + username: @user.username, + password: 'strongpassword', + email: @user.email + }} + + include_examples 'failed signup' + end + context 'when an Exception is raised' do [ ActiveRecord::StatementInvalid,