Merge pull request #926 from sgmap/fix_925_space_in_avis_email
[Fix #925] strip avis email input
This commit is contained in:
commit
313ce17d6f
2 changed files with 10 additions and 4 deletions
|
@ -3,7 +3,7 @@ class Avis < ApplicationRecord
|
||||||
belongs_to :gestionnaire
|
belongs_to :gestionnaire
|
||||||
belongs_to :claimant, class_name: 'Gestionnaire'
|
belongs_to :claimant, class_name: 'Gestionnaire'
|
||||||
|
|
||||||
before_save :downcase_email
|
before_save :clean_email
|
||||||
before_create :try_to_assign_gestionnaire
|
before_create :try_to_assign_gestionnaire
|
||||||
after_create :notify_gestionnaire
|
after_create :notify_gestionnaire
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ class Avis < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def downcase_email
|
def clean_email
|
||||||
if email.present?
|
if email.present?
|
||||||
email.downcase!
|
self.email = email.downcase.strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ RSpec.describe Avis, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#downcase_email" do
|
describe "#clean_email" do
|
||||||
subject { Avis.create(claimant: claimant, email: email, dossier: create(:dossier), gestionnaire: create(:gestionnaire)) }
|
subject { Avis.create(claimant: claimant, email: email, dossier: create(:dossier), gestionnaire: create(:gestionnaire)) }
|
||||||
|
|
||||||
context "when there is no email" do
|
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") }
|
it { expect(subject.email).to eq("toto@tps.fr") }
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue