New UI : Regular messagerie and avis messagerie should use same partials

This commit is contained in:
Mathieu Magnin 2017-11-07 17:53:11 +01:00
parent 886d278d77
commit eae16f7746
3 changed files with 50 additions and 27 deletions

View file

@ -2,6 +2,8 @@ module NewGestionnaire
class AvisController < ApplicationController class AvisController < ApplicationController
layout 'new_application' layout 'new_application'
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire]
A_DONNER_STATUS = 'a-donner' A_DONNER_STATUS = 'a-donner'
DONNES_STATUS = 'donnes' DONNES_STATUS = 'donnes'
@ -23,13 +25,9 @@ module NewGestionnaire
end end
def show def show
@avis = avis
@dossier = avis.dossier
end end
def instruction def instruction
@avis = avis
@dossier = avis.dossier
end end
def update def update
@ -39,13 +37,19 @@ module NewGestionnaire
end end
def messagerie def messagerie
@avis = avis @commentaire = Commentaire.new
@dossier = avis.dossier
end end
def create_commentaire def create_commentaire
Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier)) @commentaire = Commentaire.new(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier))
redirect_to messagerie_avis_path(avis)
if @commentaire.save
flash.notice = "Message envoyé"
redirect_to messagerie_avis_path(avis)
else
flash.alert = @commentaire.errors.full_messages
render :messagerie
end
end end
def create_avis def create_avis
@ -56,6 +60,11 @@ module NewGestionnaire
private private
def set_avis_and_dossier
@avis = avis
@dossier = avis.dossier
end
def avis def avis
current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id]) current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id])
end end
@ -65,7 +74,7 @@ module NewGestionnaire
end end
def commentaire_params def commentaire_params
params.require(:commentaire).permit(:body) params.require(:commentaire).permit(:body, :file)
end end
def create_avis_params def create_avis_params

View file

@ -3,21 +3,9 @@
= render partial: 'header', locals: { avis: @avis, dossier: @dossier } = render partial: 'header', locals: { avis: @avis, dossier: @dossier }
.messagerie.container .messagerie.container
%ul %ul.messages-list
- @dossier.commentaires.each do |commentaire| - @dossier.commentaires.each do |commentaire|
%li %li
= render partial: 'new_gestionnaire/dossiers/commentaire_icon', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire } = render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire }
.width-100 = render partial: "new_gestionnaire/shared/commentaires/form", locals: { commentaire: @commentaire, form_url: commentaire_avis_path(@avis) }
%h2
%span.mail
= render partial: 'new_gestionnaire/dossiers/commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
- 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')
%p= sanitize(commentaire.body)
= form_for(Commentaire.new, url: commentaire_avis_path(@avis), html: { class: 'form' }) do |f|
= f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true
.send-wrapper
= f.submit 'Envoyer', class: 'button send'

View file

@ -63,12 +63,38 @@ describe NewGestionnaire::AvisController, type: :controller do
end end
describe '#create_commentaire' do describe '#create_commentaire' do
let(:file) { nil }
let(:scan_result) { true }
subject { post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body', file: file } } }
before do before do
post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body' } } allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
end end
it { expect(response).to redirect_to(messagerie_avis_path(avis_without_answer)) } it do
it { expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) } subject
expect(response).to redirect_to(messagerie_avis_path(avis_without_answer))
expect(dossier.commentaires.map(&:body)).to match(['commentaire body'])
end
context "with a file" do
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
it do
subject
expect(Commentaire.last.file.path).to include("piece_justificative_0.pdf")
end
it { expect { subject }.to change(Commentaire, :count).by(1) }
context "and a virus" do
let(:scan_result) { false }
it { expect { subject }.not_to change(Commentaire, :count) }
end
end
end end
describe '#create_avis' do describe '#create_avis' do