From 5994c85ea94fa5dfed355c61c13f39223e62c846 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 12 Jun 2017 17:48:32 +0900 Subject: [PATCH] FIX: Raise the right error when email params is missing. --- app/controllers/users_controller.rb | 5 +++-- spec/controllers/users_controller_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b066f1d6b9c..fb510fa4eb0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -292,6 +292,7 @@ class UsersController < ApplicationController end def create + params.require(:email) params.permit(:user_fields) unless SiteSetting.allow_new_registrations @@ -302,7 +303,7 @@ class UsersController < ApplicationController return fail_with("login.password_too_long") end - if params[:email] && params[:email].length > 254 + 1 + 253 + if params[:email].length > 254 + 1 + 253 return fail_with("login.email_too_long") end @@ -310,7 +311,7 @@ class UsersController < ApplicationController return fail_with("login.reserved_username") end - if user = User.where(staged: true).find_by(email: params[:email].strip.downcase) + if user = User.find_by(staged: true, email: params[:email].strip.downcase) user_params.each { |k, v| user.send("#{k}=", v) } user.staged = false else diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 8dcdec55b6a..44aac166d1c 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -472,6 +472,17 @@ describe UsersController do xhr :post, :create, post_user_params end + context 'when email params is missing' do + it 'should raise the right error' do + expect do + xhr :post, :create, + name: @user.name, + username: @user.username, + passsword: 'tesing12352343' + end.to raise_error(ActionController::ParameterMissing) + end + end + context 'when creating a user' do it 'sets the user locale to I18n.locale' do SiteSetting.default_locale = 'en'