From fbbc50f24a9fcbebfafcfd65fcc0fdf55d67de79 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 31 Jan 2020 22:40:55 +0100 Subject: [PATCH] Maintenance: Invalid email error message is not expressive. --- app/controllers/tickets_controller.rb | 2 +- app/models/email_address.rb | 2 +- app/models/user.rb | 2 +- lib/email_helper/probe.rb | 2 +- spec/requests/user_spec.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index daa361264..65f04f0b9 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -100,7 +100,7 @@ class TicketsController < ApplicationController email_address = $1 email_address_validation = EmailAddressValidation.new(email_address) if !email_address_validation.valid_format? - render json: { error: 'Invalid email of customer' }, status: :unprocessable_entity + render json: { error: "Invalid email '#{email_address}' of customer" }, status: :unprocessable_entity return end local_customer = User.find_by(email: email_address.downcase) diff --git a/app/models/email_address.rb b/app/models/email_address.rb index 28bd94ea4..e0e611e83 100644 --- a/app/models/email_address.rb +++ b/app/models/email_address.rb @@ -50,7 +50,7 @@ check and if channel not exists reset configured channels for email addresses self.email = email.downcase.strip email_address_validation = EmailAddressValidation.new(email) if !email_address_validation.valid_format? - raise Exceptions::UnprocessableEntity, 'Invalid email' + raise Exceptions::UnprocessableEntity, "Invalid email '#{email}'" end true diff --git a/app/models/user.rb b/app/models/user.rb index 151a01a98..f76a57289 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -962,7 +962,7 @@ try to find correct name email_address_validation = EmailAddressValidation.new(email) if !email_address_validation.valid_format? - raise Exceptions::UnprocessableEntity, 'Invalid email' + raise Exceptions::UnprocessableEntity, "Invalid email '#{email}'" end true diff --git a/lib/email_helper/probe.rb b/lib/email_helper/probe.rb index 98e692419..bab4ed198 100644 --- a/lib/email_helper/probe.rb +++ b/lib/email_helper/probe.rb @@ -56,7 +56,7 @@ returns on fail return { result: 'invalid', messages: { - email: 'Invalid email.' + email: "Invalid email '#{params[:email]}'." }, } end diff --git a/spec/requests/user_spec.rb b/spec/requests/user_spec.rb index daf1e14e3..e132e9893 100644 --- a/spec/requests/user_spec.rb +++ b/spec/requests/user_spec.rb @@ -309,7 +309,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('Invalid email') + expect(json_response['error']).to eq("Invalid email 'some_what'") # with valid attributes params = { firstname: 'newfirstname123', note: 'some note' }