Merge pull request #926 from sgmap/fix_925_space_in_avis_email

[Fix #925] strip avis email input
This commit is contained in:
LeSim 2017-10-30 14:24:58 +01:00 committed by GitHub
commit 313ce17d6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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