From 806c41af38490be1bce6609a1e0145209873cf1f Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 28 Aug 2017 15:36:34 +0200 Subject: [PATCH] [Fix #667] Can add an already register gestionnaire with uppercase email --- .../admin/gestionnaires_controller.rb | 3 ++- .../admin/gestionnaires_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/gestionnaires_controller.rb b/app/controllers/admin/gestionnaires_controller.rb index b9057b8ee..1e4ebabe4 100644 --- a/app/controllers/admin/gestionnaires_controller.rb +++ b/app/controllers/admin/gestionnaires_controller.rb @@ -12,7 +12,8 @@ class Admin::GestionnairesController < AdminController end def create - @gestionnaire = Gestionnaire.find_by_email(params[:gestionnaire][:email]) + email = params[:gestionnaire][:email].downcase + @gestionnaire = Gestionnaire.find_by_email(email) procedure_id = params[:procedure_id] if @gestionnaire.nil? diff --git a/spec/controllers/admin/gestionnaires_controller_spec.rb b/spec/controllers/admin/gestionnaires_controller_spec.rb index ff88341ba..8e2c55212 100644 --- a/spec/controllers/admin/gestionnaires_controller_spec.rb +++ b/spec/controllers/admin/gestionnaires_controller_spec.rb @@ -119,6 +119,22 @@ describe Admin::GestionnairesController, type: :controller do it { expect(gestionnaire.administrateurs.size).to eq 2 } end + context 'when an other admin will add the same email with some uppercase in it' do + let(:email) { 'Test@Plop.com' } + let(:gestionnaire) { Gestionnaire.find_by_email(email.downcase) } + + before do + create :gestionnaire, email: email, administrateurs: [admin] + + sign_out admin + sign_in admin_2 + + subject + end + + it { expect(admin_2.gestionnaires).to include gestionnaire } + end + context 'Email notification' do it 'Notification email is sent when accompagnateur is create' do expect(GestionnaireMailer).to receive(:new_gestionnaire).and_return(GestionnaireMailer)