From ae5e6653cb1e591dd90a75aeb393b9be0ca40205 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 30 Oct 2017 16:16:20 +0100 Subject: [PATCH] [Fix #888] New UI : Add upload on commentaire form --- .../new_gestionnaire/dossiers_controller.rb | 2 +- .../dossiers/messagerie.html.haml | 16 +++++++++++----- .../new_gestionnaire/dossiers_controller_spec.rb | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index 5adafcdf3..cdd786a1f 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -99,7 +99,7 @@ module NewGestionnaire end def commentaire_params - params.require(:commentaire).permit(:body) + params.require(:commentaire).permit(:body, :file) end def avis_params diff --git a/app/views/new_gestionnaire/dossiers/messagerie.html.haml b/app/views/new_gestionnaire/dossiers/messagerie.html.haml index 09e456ed3..ee5b92180 100644 --- a/app/views/new_gestionnaire/dossiers/messagerie.html.haml +++ b/app/views/new_gestionnaire/dossiers/messagerie.html.haml @@ -15,15 +15,21 @@ - if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email) %span.guest Invité %span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y') - .rich-text - = sanitize(commentaire.body) - - if file = commentaire.piece_justificative + %p.rich-text= sanitize(commentaire.body) + + - if commentaire.file.present? .attachment-link - = link_to file.content_url, class: "button", target: "_blank", title: "Télécharger" do + = link_to commentaire.file.url, class: "button", target: "_blank", title: "Télécharger" do .icon.attachment - = file.original_filename + = commentaire.file_identifier + - elsif commentaire.piece_justificative + .attachment-link + = link_to commentaire.piece_justificative.content_url, class: "button", target: "_blank", title: "Télécharger" do + .icon.attachment + = commentaire.piece_justificative.original_filename = form_for(Commentaire.new, url: commentaire_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' }) do |f| = f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true + = f.file_field :file .send-wrapper = f.submit 'Envoyer', class: 'button send', data: { disable_with: "Envoi..." } diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index a3b7416d1..5783dd869 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -111,12 +111,18 @@ describe NewGestionnaire::DossiersController, type: :controller do describe "#create_commentaire" do let(:saved_commentaire) { dossier.commentaires.first } + let(:file) { nil } before do + allow(ClamavService).to receive(:safe_file?).and_return(true) + post :create_commentaire, params: { procedure_id: procedure.id, dossier_id: dossier.id, - commentaire: { body: 'body' } + commentaire: { + body: 'body', + file: file + } } end @@ -125,6 +131,13 @@ describe NewGestionnaire::DossiersController, type: :controller do it { expect(saved_commentaire.dossier).to eq(dossier) } it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) } it { expect(gestionnaire.followed_dossiers).to include(dossier) } + it { expect(saved_commentaire.file.present?).to eq(false) } + + context "with a file" do + let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') } + + it { expect(saved_commentaire.file.present?).to eq(true) } + end end describe "#create_avis" do