From 6a2d2ae0a7a8449783243d9185ba3e9f79079a89 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 26 Apr 2023 07:43:31 +0200 Subject: [PATCH 1/2] bug(instructeurs/avis_controller#remind): ETQ instructeur, je peux relancer une demande d'avis meme si celui ci contient une question --- .../instructeurs/avis_controller_spec.rb | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 0a01e8108..6f1b57a8a 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -9,12 +9,13 @@ describe Instructeurs::AvisController, type: :controller do let(:instructeur) { create(:instructeur) } let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } - let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) } let!(:avis_without_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure) } before { sign_in(instructeur.user) } describe "#revoker" do + let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) } + before do patch :revoquer, params: { procedure_id: procedure.id, id: avis.id } end @@ -28,12 +29,26 @@ describe Instructeurs::AvisController, type: :controller do before do allow(AvisMailer).to receive(:avis_invitation).and_return(double(deliver_later: nil)) end + context 'without question' do + let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) } - it 'sends a reminder to the expert' do - get :remind, params: { procedure_id: procedure.id, id: avis.id } - expect(AvisMailer).to have_received(:avis_invitation).once.with(avis) - expect(flash.notice).to eq("Un mail de relance a été envoyé à #{avis.expert.email}") - expect(avis.reload.reminded_at).to be_present + it 'sends a reminder to the expert' do + get :remind, params: { procedure_id: procedure.id, id: avis.id } + expect(AvisMailer).to have_received(:avis_invitation).once.with(avis) + expect(flash.notice).to eq("Un mail de relance a été envoyé à #{avis.expert.email}") + expect(avis.reload.reminded_at).to be_present + end + end + + context 'with question' do + let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, question_label: '123') } + + it 'sends a reminder to the expert' do + get :remind, params: { procedure_id: procedure.id, id: avis.id } + expect(AvisMailer).to have_received(:avis_invitation).once.with(avis) + expect(flash.notice).to eq("Un mail de relance a été envoyé à #{avis.expert.email}") + expect(avis.reload.reminded_at).to be_present + end end end end From 1ae40f1a2286b71d62df3860a80b75104fd453db Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 26 Apr 2023 07:45:11 +0200 Subject: [PATCH 2/2] correctif(instructeurs/avis_controller#remind): ETQ instructeur, je peux relancer une demande d'avis meme si celui ci contient une question --- app/models/avis.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/avis.rb b/app/models/avis.rb index fed16957d..2cc17d25b 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -111,7 +111,7 @@ class Avis < ApplicationRecord def remind_by!(revocator) return false if !remindable_by?(revocator) || answer.present? - update!(reminded_at: Time.zone.now) + update_column(:reminded_at, Time.zone.now) end private