pr feedbacks - add validation for yes/no answer - improve locales use
This commit is contained in:
parent
3b3d5182bf
commit
ee2f795dec
8 changed files with 23 additions and 12 deletions
|
@ -5,8 +5,13 @@ module CreateAvisConcern
|
||||||
|
|
||||||
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?
|
if create_avis_params[:emails].empty?
|
||||||
flash.alert = t('activerecord.errors.models.email.empty')
|
avis = Avis.new(create_avis_params)
|
||||||
return Avis.new(create_avis_params)
|
errors = avis.errors
|
||||||
|
errors.add(:emails, :blank)
|
||||||
|
|
||||||
|
flash.alert = errors.full_message(:emails, errors[:emails].first)
|
||||||
|
|
||||||
|
return avis
|
||||||
end
|
end
|
||||||
|
|
||||||
confidentiel ||= create_avis_params[:confidentiel]
|
confidentiel ||= create_avis_params[:confidentiel]
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Avis < ApplicationRecord
|
||||||
|
|
||||||
validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true
|
validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true
|
||||||
validates :claimant, presence: true
|
validates :claimant, presence: true
|
||||||
|
validates :question_answer, presence: { on: :update, if: -> { question_label.present? } }
|
||||||
validates :piece_justificative_file, size: { less_than: FILE_MAX_SIZE }
|
validates :piece_justificative_file, size: { less_than: FILE_MAX_SIZE }
|
||||||
validates :introduction_file, size: { less_than: FILE_MAX_SIZE }
|
validates :introduction_file, size: { less_than: FILE_MAX_SIZE }
|
||||||
before_validation -> { sanitize_email(:email) }
|
before_validation -> { sanitize_email(:email) }
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
%span.date.fr-text--xs.fr-text-mention--grey{ class: highlight_if_unseen_class(avis_seen_at, avis.created_at) }
|
%span.date.fr-text--xs.fr-text-mention--grey{ class: highlight_if_unseen_class(avis_seen_at, avis.created_at) }
|
||||||
= t('demande_envoyee_le', scope: 'views.shared.avis', date: l(avis.created_at, format: '%d/%m/%y à %H:%M'))
|
= t('demande_envoyee_le', scope: 'views.shared.avis', date: l(avis.created_at, format: '%d/%m/%y à %H:%M'))
|
||||||
%p= avis.introduction
|
%p= avis.introduction
|
||||||
|
- if avis.question_label
|
||||||
|
%p= avis.question_label
|
||||||
|
|
||||||
.answer.flex.align-start
|
.answer.flex.align-start
|
||||||
%span.icon.bubble.avis-icon
|
%span.icon.bubble.avis-icon
|
||||||
|
|
|
@ -26,7 +26,10 @@
|
||||||
= f.text_area :introduction, rows: 3, class: 'fr-input', value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
|
= f.text_area :introduction, rows: 3, class: 'fr-input', value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
|
||||||
|
|
||||||
.fr-input-group
|
.fr-input-group
|
||||||
= f.label :question_label, t('helpers.label.question_label'), class: 'fr-label'
|
= f.label :question_label, class: 'fr-label' do
|
||||||
|
= t('helpers.label.question_label')
|
||||||
|
%span.fr-hint-text
|
||||||
|
= t('helpers.label.question_label_hint')
|
||||||
= f.text_area :question_label, label: "question", class: 'fr-input'
|
= f.text_area :question_label, label: "question", class: 'fr-input'
|
||||||
%p.tab-title Ajouter une pièce jointe
|
%p.tab-title Ajouter une pièce jointe
|
||||||
.form-group
|
.form-group
|
||||||
|
|
|
@ -7,10 +7,7 @@ en:
|
||||||
answer: "Answer"
|
answer: "Answer"
|
||||||
claimant: Claimant
|
claimant: Claimant
|
||||||
confidentiel: Confidential
|
confidentiel: Confidential
|
||||||
errors:
|
question_answer: "Answer yes/no"
|
||||||
models:
|
|
||||||
email:
|
|
||||||
empty: Email field can not be empty
|
|
||||||
helpers:
|
helpers:
|
||||||
label:
|
label:
|
||||||
invite_linked_dossiers:
|
invite_linked_dossiers:
|
||||||
|
@ -19,6 +16,7 @@ en:
|
||||||
revoke: Revoke opinion request
|
revoke: Revoke opinion request
|
||||||
remind: Remind the expert
|
remind: Remind the expert
|
||||||
question_label: Ask a question to the expert
|
question_label: Ask a question to the expert
|
||||||
|
question_label_hint: (optional field) the expert could answer by yes/no
|
||||||
introduction: Introduction message
|
introduction: Introduction message
|
||||||
question_answer:
|
question_answer:
|
||||||
true: 'yes'
|
true: 'yes'
|
||||||
|
|
|
@ -7,10 +7,7 @@ fr:
|
||||||
answer: "Réponse"
|
answer: "Réponse"
|
||||||
claimant: Demandeur
|
claimant: Demandeur
|
||||||
confidentiel: confidentiel
|
confidentiel: confidentiel
|
||||||
errors:
|
question_answer: "Réponse oui/non"
|
||||||
models:
|
|
||||||
email:
|
|
||||||
empty: Le champ email ne peut pas être vide
|
|
||||||
helpers:
|
helpers:
|
||||||
label:
|
label:
|
||||||
invite_linked_dossiers:
|
invite_linked_dossiers:
|
||||||
|
@ -19,6 +16,7 @@ fr:
|
||||||
revoke: Révoquer la demande d’avis
|
revoke: Révoquer la demande d’avis
|
||||||
remind: Relancer l’expert
|
remind: Relancer l’expert
|
||||||
question_label: Posez une question à l'expert
|
question_label: Posez une question à l'expert
|
||||||
|
question_label_hint: (champ optionnel) l'expert pourra répondre par oui/non
|
||||||
introduction: Message d'introduction
|
introduction: Message d'introduction
|
||||||
question_answer:
|
question_answer:
|
||||||
true: oui
|
true: oui
|
||||||
|
|
|
@ -634,7 +634,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
before { subject }
|
before { subject }
|
||||||
|
|
||||||
it { expect(response).to render_template :avis }
|
it { expect(response).to render_template :avis }
|
||||||
it { expect(flash.alert).to eq("Le champ email ne peut pas être vide") }
|
it { expect(flash.alert).to eq("Le champ « Emails » doit être rempli") }
|
||||||
it { expect { subject }.not_to change(Avis, :count) }
|
it { expect { subject }.not_to change(Avis, :count) }
|
||||||
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,6 +98,10 @@ describe 'Inviting an expert:' do
|
||||||
expect(page).to have_text('Question ?')
|
expect(page).to have_text('Question ?')
|
||||||
expect(page).to have_text('Cet avis est confidentiel')
|
expect(page).to have_text('Cet avis est confidentiel')
|
||||||
|
|
||||||
|
# check validation
|
||||||
|
click_on 'Envoyer votre avis'
|
||||||
|
expect(page).to have_content('Le champ « Réponse oui/non » doit être rempli')
|
||||||
|
|
||||||
choose 'oui'
|
choose 'oui'
|
||||||
fill_in 'avis_answer', with: 'Ma réponse d’expert.'
|
fill_in 'avis_answer', with: 'Ma réponse d’expert.'
|
||||||
click_on 'Envoyer votre avis'
|
click_on 'Envoyer votre avis'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue