[Fix #1479] Sanitize Avis email before validation
This commit is contained in:
parent
a00114d03d
commit
69f8353b2f
2 changed files with 4 additions and 8 deletions
|
@ -1,11 +1,13 @@
|
|||
class Avis < ApplicationRecord
|
||||
include EmailSanitizableConcern
|
||||
|
||||
belongs_to :dossier, touch: true
|
||||
belongs_to :gestionnaire
|
||||
belongs_to :claimant, class_name: 'Gestionnaire'
|
||||
|
||||
validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true
|
||||
|
||||
before_save :clean_email
|
||||
before_validation -> { sanitize_email(:email) }
|
||||
before_create :try_to_assign_gestionnaire
|
||||
after_create :notify_gestionnaire
|
||||
|
||||
|
@ -31,12 +33,6 @@ class Avis < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def clean_email
|
||||
if email.present?
|
||||
self.email = email.downcase.strip
|
||||
end
|
||||
end
|
||||
|
||||
def notify_gestionnaire
|
||||
AvisMailer.avis_invitation(self).deliver_now
|
||||
end
|
||||
|
|
|
@ -118,7 +118,7 @@ RSpec.describe Avis, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#clean_email" do
|
||||
describe "email sanitization" do
|
||||
subject { Avis.create(claimant: claimant, email: email, dossier: create(:dossier), gestionnaire: create(:gestionnaire)) }
|
||||
|
||||
context "when there is no email" do
|
||||
|
|
Loading…
Add table
Reference in a new issue