Merge pull request #4853 from betagouv/feat/1357-invite-expert-with-pj

feat/1357 - add attachment when instructor asking for a review
This commit is contained in:
Keirua 2020-03-04 14:52:07 +01:00 committed by GitHub
commit 60251013f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 4 deletions

View file

@ -23,6 +23,7 @@ module CreateAvisConcern
{ {
email: email, email: email,
introduction: create_avis_params[:introduction], introduction: create_avis_params[:introduction],
introduction_file: create_avis_params[:introduction_file],
claimant: current_instructeur, claimant: current_instructeur,
dossier: dossier, dossier: dossier,
confidentiel: confidentiel confidentiel: confidentiel
@ -43,7 +44,6 @@ module CreateAvisConcern
sent_emails_addresses << avis.email_to_display sent_emails_addresses << avis.email_to_display
end end
end end
flash.notice = "Une demande d'avis a été envoyée à #{sent_emails_addresses.uniq.join(", ")}" flash.notice = "Une demande d'avis a été envoyée à #{sent_emails_addresses.uniq.join(", ")}"
end end
@ -61,6 +61,6 @@ module CreateAvisConcern
end end
def create_avis_params def create_avis_params
params.require(:avis).permit(:introduction, :confidentiel, :invite_linked_dossiers, emails: []) params.require(:avis).permit(:introduction_file, :introduction, :confidentiel, :invite_linked_dossiers, emails: [])
end end
end end

View file

@ -6,6 +6,7 @@ class Avis < ApplicationRecord
belongs_to :claimant, class_name: 'Instructeur' belongs_to :claimant, class_name: 'Instructeur'
has_one_attached :piece_justificative_file has_one_attached :piece_justificative_file
has_one_attached :introduction_file
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

View file

@ -11,6 +11,10 @@
%span.date Demande d'avis envoyée le #{l(@avis.created_at, format: '%d/%m/%y')} %span.date Demande d'avis envoyée le #{l(@avis.created_at, format: '%d/%m/%y')}
%p.introduction= @avis.introduction %p.introduction= @avis.introduction
- if @avis.introduction_file.attached?
= render partial: 'shared/attachment/show', locals: { attachment: @avis.introduction_file.attachment }
%br/
= form_for @avis, url: instructeur_avis_path(@avis), html: { class: 'form' } do |f| = form_for @avis, url: instructeur_avis_path(@avis), html: { class: 'form' } do |f|
= f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true
= render 'shared/attachment/edit', = render 'shared/attachment/edit',

View file

@ -5,6 +5,12 @@
= form_for avis, url: url, html: { class: 'form' } do |f| = form_for avis, url: url, html: { class: 'form' } do |f|
= f.email_field :emails, placeholder: 'Adresses email, séparées par des virgules', required: true, multiple: true, onchange: "javascript:DS.replaceSemicolonByComma(event);" = f.email_field :emails, placeholder: 'Adresses email, séparées par des virgules', required: true, multiple: true, onchange: "javascript:DS.replaceSemicolonByComma(event);"
= f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true = f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
%p.tab-title Ajouter une pièce jointe
.form-group
= render 'shared/attachment/edit',
{ form: f,
attached_file: avis.introduction_file,
user_can_destroy: true }
- if linked_dossiers.present? - if linked_dossiers.present?
= f.check_box :invite_linked_dossiers, {}, true, false = f.check_box :invite_linked_dossiers, {}, true, false

View file

@ -126,7 +126,9 @@ describe Instructeurs::AvisController, type: :controller do
let(:invite_linked_dossiers) { nil } let(:invite_linked_dossiers) { nil }
before do before do
post :create_avis, params: { id: previous_avis.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers } } @introduction_file = Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf')
post :create_avis, params: { id: previous_avis.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } }
created_avis.reload
end end
context 'when an invalid email' do context 'when an invalid email' do
@ -139,6 +141,16 @@ describe Instructeurs::AvisController, type: :controller do
it { expect(Avis.last).to eq(previous_avis) } it { expect(Avis.last).to eq(previous_avis) }
end end
context 'ask review with attachment' do
let(:previous_avis_confidentiel) { false }
let(:asked_confidentiel) { false }
let(:emails) { ["toto@totomail.com"] }
it { expect(created_avis.introduction_file).to be_attached }
it { expect(created_avis.introduction_file.filename).to eq("piece_justificative_0.pdf") }
it { expect(flash.notice).to eq("Une demande d'avis a été envoyée à toto@totomail.com") }
end
context 'with multiple emails' do context 'with multiple emails' do
let(:asked_confidentiel) { false } let(:asked_confidentiel) { false }
let(:previous_avis_confidentiel) { false } let(:previous_avis_confidentiel) { false }

View file

@ -113,7 +113,7 @@ feature 'Inviting an expert:' do
expect(page).to have_text('Cet avis est confidentiel') expect(page).to have_text('Cet avis est confidentiel')
fill_in 'avis_answer', with: 'Ma réponse dexpert : cest un oui.' fill_in 'avis_answer', with: 'Ma réponse dexpert : cest un oui.'
find('.attachment input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf') find('.attachment input[name="avis[piece_justificative_file]"]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf')
click_on 'Envoyer votre avis' click_on 'Envoyer votre avis'
expect(page).to have_content('Votre réponse est enregistrée') expect(page).to have_content('Votre réponse est enregistrée')