From fc987a730df4dafb4eb9a412f83acc1f6abb0670 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 27 Oct 2017 16:27:55 +0200 Subject: [PATCH] [Fix #925] strip avis email input --- app/models/avis.rb | 6 +++--- spec/models/avis_spec.rb | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/avis.rb b/app/models/avis.rb index c3bef4b3f..39ef291ae 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -3,7 +3,7 @@ class Avis < ApplicationRecord belongs_to :gestionnaire belongs_to :claimant, class_name: 'Gestionnaire' - before_save :downcase_email + before_save :clean_email before_create :try_to_assign_gestionnaire after_create :notify_gestionnaire @@ -28,9 +28,9 @@ class Avis < ApplicationRecord private - def downcase_email + def clean_email if email.present? - email.downcase! + self.email = email.downcase.strip end end diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb index 0dd7ef2ac..2581602d0 100644 --- a/spec/models/avis_spec.rb +++ b/spec/models/avis_spec.rb @@ -118,7 +118,7 @@ RSpec.describe Avis, type: :model do end end - describe "#downcase_email" do + describe "#clean_email" do subject { Avis.create(claimant: claimant, email: email, dossier: create(:dossier), gestionnaire: create(:gestionnaire)) } context "when there is no email" do @@ -138,5 +138,11 @@ RSpec.describe Avis, type: :model do it { expect(subject.email).to eq("toto@tps.fr") } end + + context "when the email has some spaces before and after" do + let(:email) { " toto@tps.fr " } + + it { expect(subject.email).to eq("toto@tps.fr") } + end end end