FIX: Raise the right error when email params is missing.

This commit is contained in:
Guo Xiang Tan 2017-06-12 17:48:32 +09:00
parent 23420c0817
commit 5994c85ea9
2 changed files with 14 additions and 2 deletions

View File

@ -292,6 +292,7 @@ class UsersController < ApplicationController
end end
def create def create
params.require(:email)
params.permit(:user_fields) params.permit(:user_fields)
unless SiteSetting.allow_new_registrations unless SiteSetting.allow_new_registrations
@ -302,7 +303,7 @@ class UsersController < ApplicationController
return fail_with("login.password_too_long") return fail_with("login.password_too_long")
end end
if params[:email] && params[:email].length > 254 + 1 + 253 if params[:email].length > 254 + 1 + 253
return fail_with("login.email_too_long") return fail_with("login.email_too_long")
end end
@ -310,7 +311,7 @@ class UsersController < ApplicationController
return fail_with("login.reserved_username") return fail_with("login.reserved_username")
end 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_params.each { |k, v| user.send("#{k}=", v) }
user.staged = false user.staged = false
else else

View File

@ -472,6 +472,17 @@ describe UsersController do
xhr :post, :create, post_user_params xhr :post, :create, post_user_params
end 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 context 'when creating a user' do
it 'sets the user locale to I18n.locale' do it 'sets the user locale to I18n.locale' do
SiteSetting.default_locale = 'en' SiteSetting.default_locale = 'en'