add flash alert if email field empty
This commit is contained in:
parent
1cbafd1e0b
commit
eddd7a2192
4 changed files with 24 additions and 0 deletions
|
@ -4,6 +4,11 @@ module CreateAvisConcern
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_avis_from_params(dossier, instructeur_or_expert, confidentiel = false)
|
def create_avis_from_params(dossier, instructeur_or_expert, confidentiel = false)
|
||||||
|
if create_avis_params[:emails].empty?
|
||||||
|
flash.alert = t('activerecord.errors.models.email.empty')
|
||||||
|
return Avis.new(create_avis_params)
|
||||||
|
end
|
||||||
|
|
||||||
confidentiel ||= create_avis_params[:confidentiel]
|
confidentiel ||= create_avis_params[:confidentiel]
|
||||||
# Because of a limitation of the email_field rails helper,
|
# Because of a limitation of the email_field rails helper,
|
||||||
# the :emails parameter is a 1-element array.
|
# the :emails parameter is a 1-element array.
|
||||||
|
|
|
@ -7,6 +7,10 @@ en:
|
||||||
answer: "Answer"
|
answer: "Answer"
|
||||||
claimant: Claimant
|
claimant: Claimant
|
||||||
confidentiel: Confidential
|
confidentiel: Confidential
|
||||||
|
errors:
|
||||||
|
models:
|
||||||
|
email:
|
||||||
|
empty: Email field can not be empty
|
||||||
helpers:
|
helpers:
|
||||||
label:
|
label:
|
||||||
invite_linked_dossiers:
|
invite_linked_dossiers:
|
||||||
|
|
|
@ -7,6 +7,10 @@ fr:
|
||||||
answer: "Réponse"
|
answer: "Réponse"
|
||||||
claimant: Demandeur
|
claimant: Demandeur
|
||||||
confidentiel: confidentiel
|
confidentiel: confidentiel
|
||||||
|
errors:
|
||||||
|
models:
|
||||||
|
email:
|
||||||
|
empty: Le champ email ne peut pas être vide
|
||||||
helpers:
|
helpers:
|
||||||
label:
|
label:
|
||||||
invite_linked_dossiers:
|
invite_linked_dossiers:
|
||||||
|
|
|
@ -628,6 +628,17 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with no email" do
|
||||||
|
let(:emails) { "" }
|
||||||
|
|
||||||
|
before { subject }
|
||||||
|
|
||||||
|
it { expect(response).to render_template :avis }
|
||||||
|
it { expect(flash.alert).to eq("Le champ email ne peut pas être vide") }
|
||||||
|
it { expect { subject }.not_to change(Avis, :count) }
|
||||||
|
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
||||||
|
end
|
||||||
|
|
||||||
context 'with multiple emails' do
|
context 'with multiple emails' do
|
||||||
let(:emails) { "[\"toto.fr\",\"titi@titimail.com\"]" }
|
let(:emails) { "[\"toto.fr\",\"titi@titimail.com\"]" }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue