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 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