Maintenance: Error message about existing user with same email address is not expressive.
This commit is contained in:
parent
87be5318c3
commit
1772e9f1e4
3 changed files with 6 additions and 6 deletions
|
@ -141,8 +141,8 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
# check if user already exists
|
||||
exists = User.find_by(email: clean_params[:email].downcase.strip)
|
||||
raise Exceptions::UnprocessableEntity, 'Email address is already used for other user.' if exists
|
||||
exists = User.exists?(email: clean_params[:email].downcase.strip)
|
||||
raise Exceptions::UnprocessableEntity, "Email address '#{clean_params[:email].downcase.strip}' is already used for other user." if exists
|
||||
|
||||
user = User.new(clean_params)
|
||||
user.associations_from_param(params)
|
||||
|
|
|
@ -1026,9 +1026,9 @@ try to find correct name
|
|||
return true if email.blank?
|
||||
return true if !changes
|
||||
return true if !changes['email']
|
||||
return true if !User.find_by(email: email.downcase.strip)
|
||||
return true if !User.exists?(email: email.downcase.strip)
|
||||
|
||||
raise Exceptions::UnprocessableEntity, 'Email address is already used for other user.'
|
||||
raise Exceptions::UnprocessableEntity, "Email address '#{email.downcase.strip}' is already used for other user."
|
||||
end
|
||||
|
||||
def validate_roles(role)
|
||||
|
|
|
@ -115,7 +115,7 @@ RSpec.describe 'User', type: :request, searchindex: true do
|
|||
post '/api/v1/users', params: params, headers: headers, as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json_response['error']).to be_truthy
|
||||
expect(json_response['error']).to eq('Email address is already used for other user.')
|
||||
expect(json_response['error']).to eq("Email address 'rest-customer1@example.com' is already used for other user.")
|
||||
|
||||
# email missing with enabled feature
|
||||
params = { firstname: 'some firstname', signup: true }
|
||||
|
@ -295,7 +295,7 @@ RSpec.describe 'User', type: :request, searchindex: true do
|
|||
post '/api/v1/users', params: params, as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json_response).to be_truthy
|
||||
expect(json_response['error']).to eq('Email address is already used for other user.')
|
||||
expect(json_response['error']).to eq("Email address 'new_agent_by_admin2@example.com' is already used for other user.")
|
||||
|
||||
# missing required attributes
|
||||
params = { note: 'some note' }
|
||||
|
|
Loading…
Reference in a new issue