Merge pull request #722 from sgmap/fix_721
[Fix #721] If an avis is created with uppercase email, downcase it be…
This commit is contained in:
commit
05ca8d37fa
3 changed files with 30 additions and 1 deletions
|
@ -7,7 +7,7 @@ class Backoffice::AvisController < ApplicationController
|
||||||
avis = Avis.new(create_params.merge(claimant: current_gestionnaire, dossier: dossier))
|
avis = Avis.new(create_params.merge(claimant: current_gestionnaire, dossier: dossier))
|
||||||
|
|
||||||
if avis.save
|
if avis.save
|
||||||
flash[:notice] = "Votre demande d'avis a bien été envoyée à #{create_params[:email]}"
|
flash[:notice] = "Votre demande d'avis a bien été envoyée à #{avis.email}"
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to backoffice_dossier_path(dossier)
|
redirect_to backoffice_dossier_path(dossier)
|
||||||
|
|
|
@ -3,6 +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_create :try_to_assign_gestionnaire
|
before_create :try_to_assign_gestionnaire
|
||||||
after_create :notify_gestionnaire
|
after_create :notify_gestionnaire
|
||||||
|
|
||||||
|
@ -27,6 +28,12 @@ class Avis < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def downcase_email
|
||||||
|
if email.present?
|
||||||
|
email.downcase!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def notify_gestionnaire
|
def notify_gestionnaire
|
||||||
AvisMailer.avis_invitation(self).deliver_now
|
AvisMailer.avis_invitation(self).deliver_now
|
||||||
end
|
end
|
||||||
|
|
|
@ -117,4 +117,26 @@ RSpec.describe Avis, type: :model do
|
||||||
it { expect(avis.email).to eq(email) }
|
it { expect(avis.email).to eq(email) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#downcase_email" do
|
||||||
|
subject { Avis.create(claimant: claimant, email: email, dossier: create(:dossier), gestionnaire: create(:gestionnaire)) }
|
||||||
|
|
||||||
|
context "when there is no email" do
|
||||||
|
let(:email) { nil }
|
||||||
|
|
||||||
|
it { expect(subject.email).to be_nil }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the email is in lowercase" do
|
||||||
|
let(:email) { "toto@tps.fr" }
|
||||||
|
|
||||||
|
it { expect(subject.email).to eq("toto@tps.fr") }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the email is not in lowercase" do
|
||||||
|
let(:email) { "TOTO@tps.fr" }
|
||||||
|
|
||||||
|
it { expect(subject.email).to eq("toto@tps.fr") }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue