Maintenance: Error message about existing user with same email address is not expressive.

This commit is contained in:
Thorsten Eckel 2020-01-10 11:43:36 +01:00
parent 87be5318c3
commit 1772e9f1e4
3 changed files with 6 additions and 6 deletions

View file

@ -141,8 +141,8 @@ class UsersController < ApplicationController
end end
# check if user already exists # check if user already exists
exists = User.find_by(email: clean_params[:email].downcase.strip) exists = User.exists?(email: clean_params[:email].downcase.strip)
raise Exceptions::UnprocessableEntity, 'Email address is already used for other user.' if exists raise Exceptions::UnprocessableEntity, "Email address '#{clean_params[:email].downcase.strip}' is already used for other user." if exists
user = User.new(clean_params) user = User.new(clean_params)
user.associations_from_param(params) user.associations_from_param(params)

View file

@ -1026,9 +1026,9 @@ try to find correct name
return true if email.blank? return true if email.blank?
return true if !changes return true if !changes
return true if !changes['email'] 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 end
def validate_roles(role) def validate_roles(role)

View file

@ -115,7 +115,7 @@ RSpec.describe 'User', type: :request, searchindex: true do
post '/api/v1/users', params: params, headers: headers, as: :json post '/api/v1/users', params: params, headers: headers, as: :json
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['error']).to be_truthy 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 # email missing with enabled feature
params = { firstname: 'some firstname', signup: true } 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 post '/api/v1/users', params: params, as: :json
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
expect(json_response).to be_truthy 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 # missing required attributes
params = { note: 'some note' } params = { note: 'some note' }