NewDesign: gestionnaire can add a new commentaire

This commit is contained in:
Simon Lehericey 2017-07-19 14:04:49 +02:00 committed by Mathieu Magnin
parent 3ecc4f1327
commit 714b2a5f08
5 changed files with 42 additions and 0 deletions

View file

@ -34,4 +34,13 @@
.date {
float: right;
}
form {
overflow: hidden;
}
.send {
float: right;
margin-bottom: $default-padding;
}
}

View file

@ -36,10 +36,19 @@ module NewGestionnaire
redirect_back(fallback_location: procedures_url)
end
def create_commentaire
Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: dossier))
redirect_to messagerie_dossier_path(dossier.procedure, dossier)
end
private
def dossier
current_gestionnaire.dossiers.find(params[:dossier_id])
end
def commentaire_params
params.require(:commentaire).permit(:body)
end
end
end

View file

@ -14,3 +14,7 @@
%span.guest Invité
%span.date= I18n.l(commentaire.created_at.localtime, format: '%d/%m/%y')
%p= sanitize(commentaire.body)
= form_for(Commentaire.new, url: commentaire_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' }) do |f|
= f.text_area :body, class: 'new-commentaire', rows: 5, placeholder: 'Répondre ici', required: true
= f.submit 'Envoyer', class: 'button send'

View file

@ -247,6 +247,7 @@ Rails.application.routes.draw do
patch 'unfollow'
patch 'archive'
patch 'unarchive'
post 'commentaire' => 'dossiers#create_commentaire'
end
end
end

View file

@ -101,4 +101,23 @@ describe NewGestionnaire::DossiersController, type: :controller do
end
end
end
describe "commentaire" do
let(:saved_commentaire) { dossier.commentaires.first }
before do
sign_in(gestionnaire)
post :create_commentaire, params: {
procedure_id: procedure.id,
dossier_id: dossier.id,
commentaire: { body: 'body' }
}
end
it { expect(saved_commentaire.body).to eq('body') }
it { expect(saved_commentaire.email).to eq(gestionnaire.email) }
it { expect(saved_commentaire.dossier).to eq(dossier) }
it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) }
end
end