update dossier after saving commentaire
update last_commentaire_updated_at without hook Co-authored-by: Christophe Robillard <christophe.robillard@beta.gouv.fr>
This commit is contained in:
parent
667b7d9876
commit
f3a675c3bc
6 changed files with 18 additions and 0 deletions
|
@ -60,6 +60,7 @@ module Instructeurs
|
|||
@commentaire = CommentaireService.build(current_instructeur, avis.dossier, commentaire_params)
|
||||
|
||||
if @commentaire.save
|
||||
@commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now)
|
||||
flash.notice = "Message envoyé"
|
||||
redirect_to messagerie_instructeur_avis_path(avis.procedure, avis)
|
||||
else
|
||||
|
|
|
@ -169,6 +169,7 @@ module Instructeurs
|
|||
@commentaire = CommentaireService.build(current_instructeur, dossier, commentaire_params)
|
||||
|
||||
if @commentaire.save
|
||||
@commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now)
|
||||
current_instructeur.follow(dossier)
|
||||
flash.notice = "Message envoyé"
|
||||
redirect_to messagerie_instructeur_dossier_path(procedure, dossier)
|
||||
|
|
|
@ -198,6 +198,7 @@ module Users
|
|||
@commentaire = CommentaireService.build(current_user, dossier, commentaire_params)
|
||||
|
||||
if @commentaire.save
|
||||
@commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now)
|
||||
dossier.followers_instructeurs
|
||||
.with_instant_email_message_notifications
|
||||
.each do |instructeur|
|
||||
|
|
|
@ -117,18 +117,23 @@ describe Instructeurs::AvisController, type: :controller do
|
|||
describe '#create_commentaire' do
|
||||
let(:file) { nil }
|
||||
let(:scan_result) { true }
|
||||
let(:now) { Time.zone.parse("14/07/1789") }
|
||||
|
||||
subject { post :create_commentaire, params: { id: avis_without_answer.id, procedure_id: procedure.id, commentaire: { body: 'commentaire body', piece_jointe: file } } }
|
||||
|
||||
before do
|
||||
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
||||
Timecop.freeze(now)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
||||
it do
|
||||
subject
|
||||
|
||||
expect(response).to redirect_to(messagerie_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer))
|
||||
expect(dossier.commentaires.map(&:body)).to match(['commentaire body'])
|
||||
expect(dossier.reload.last_commentaire_updated_at).to eq(now)
|
||||
end
|
||||
|
||||
context "with a file" do
|
||||
|
|
|
@ -390,6 +390,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
let(:body) { "avant\napres" }
|
||||
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
|
||||
let(:scan_result) { true }
|
||||
let(:now) { Timecop.freeze("09/11/1989") }
|
||||
|
||||
subject {
|
||||
post :create_commentaire, params: {
|
||||
|
@ -404,14 +405,18 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
|
||||
before do
|
||||
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
||||
Timecop.freeze(now)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
||||
it "creates a commentaire" do
|
||||
expect { subject }.to change(Commentaire, :count).by(1)
|
||||
expect(instructeur.followed_dossiers).to include(dossier)
|
||||
|
||||
expect(response).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
expect(flash.notice).to be_present
|
||||
expect(dossier.reload.last_commentaire_updated_at).to eq(now)
|
||||
end
|
||||
|
||||
context "when the commentaire created with virus file" do
|
||||
|
|
|
@ -802,6 +802,7 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:body) { "avant\napres" }
|
||||
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
|
||||
let(:scan_result) { true }
|
||||
let(:now) { Time.zone.parse("18/09/1981") }
|
||||
|
||||
subject {
|
||||
post :create_commentaire, params: {
|
||||
|
@ -814,6 +815,7 @@ describe Users::DossiersController, type: :controller do
|
|||
}
|
||||
|
||||
before do
|
||||
Timecop.freeze(now)
|
||||
sign_in(user)
|
||||
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
||||
allow(DossierMailer).to receive(:notify_new_commentaire_to_instructeur).and_return(double(deliver_later: nil))
|
||||
|
@ -823,6 +825,8 @@ describe Users::DossiersController, type: :controller do
|
|||
create(:assign_to, instructeur: instructeur_without_instant_message, procedure: procedure, instant_email_message_notifications_enabled: false, groupe_instructeur: procedure.defaut_groupe_instructeur)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
||||
it "creates a commentaire" do
|
||||
expect { subject }.to change(Commentaire, :count).by(1)
|
||||
|
||||
|
@ -830,6 +834,7 @@ describe Users::DossiersController, type: :controller do
|
|||
expect(DossierMailer).to have_received(:notify_new_commentaire_to_instructeur).with(dossier, instructeur_with_instant_message.email)
|
||||
expect(DossierMailer).not_to have_received(:notify_new_commentaire_to_instructeur).with(dossier, instructeur_without_instant_message.email)
|
||||
expect(flash.notice).to be_present
|
||||
expect(dossier.reload.last_commentaire_updated_at).to eq(now)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue