Skip to content
Permalink
Browse files

Maintenance: Error message about existing user with same email addres…

…s is not expressive.
  • Loading branch information
thorsteneckel committed Jan 10, 2020
1 parent 87be531 commit 1772e9f1e45f4babf88be39284f08ba8bf98cfb3
Showing with 6 additions and 6 deletions.
  1. +2 −2 app/controllers/users_controller.rb
  2. +2 −2 app/models/user.rb
  3. +2 −2 spec/requests/user_spec.rb
@@ -141,8 +141,8 @@ def create
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 @@ def ensure_uniq_email
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 @@
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 @@
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' }

0 comments on commit 1772e9f

Please sign in to comment.
You can’t perform that action at this time.