From 23677956f3ed28555a8fa1c3e228c33f83e218d1 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Mon, 29 Nov 2021 11:34:31 +0100 Subject: [PATCH 1/2] modify controller --- app/controllers/instructeurs/dossiers_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index 1f9bc3dd9..9b584536f 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -134,6 +134,9 @@ module Instructeurs def repasser_en_instruction begin + if dossier.hidden_by_user_at.present? + dossier.update!(hidden_by_user_at: nil) + end flash.notice = "Le dossier #{dossier.id} a été repassé en instruction." dossier.repasser_en_instruction!(current_instructeur) rescue AASM::InvalidTransition => e From c75a9b627168eda68ee33235c5d5c264823e8387 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Mon, 29 Nov 2021 11:34:42 +0100 Subject: [PATCH 2/2] tests --- .../instructeurs/dossiers_controller_spec.rb | 39 +++++++++++++++---- .../users/dossiers_controller_spec.rb | 10 +++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index 6c7a8720e..49c51606a 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -160,20 +160,29 @@ describe Instructeurs::DossiersController, type: :controller do let(:dossier) { create(:dossier, :refuse, procedure: procedure) } let(:current_user) { instructeur.user } - before do - sign_in current_user + subject do post :repasser_en_instruction, - params: { procedure_id: procedure.id, dossier_id: dossier.id }, - format: 'js' + params: { procedure_id: procedure.id, dossier_id: dossier.id }, + format: 'js' end - it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) } - it { expect(response).to have_http_status(:ok) } - it { expect(response.body).to include('.header-actions') } + before do + sign_in current_user + end + + context 'when the dossier is refuse' do + before { subject } + + it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) } + it { expect(response).to have_http_status(:ok) } + it { expect(response.body).to include('.header-actions') } + end context 'when the dossier has already been put en_instruction' do let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) } + before { subject } + it 'warns about the error' do expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) expect(response).to have_http_status(:ok) @@ -184,11 +193,27 @@ describe Instructeurs::DossiersController, type: :controller do context 'when the dossier is accepte' do let(:dossier) { create(:dossier, :accepte, procedure: procedure) } + before { subject } + it 'it is possible to go back to en_instruction as instructeur' do expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) expect(response).to have_http_status(:ok) end end + + context 'when the dossier is done and the user delete it' do + let!(:dossier) { create(:dossier, :accepte, procedure: procedure, user: current_user) } + + before do + dossier.update!(hidden_by_user_at: Time.zone.now) + subject + end + + it 'reveals the dossier' do + expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) + expect(dossier.reload.hidden_by_user_at).to be_nil + end + end end describe '#terminer' do diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index b9a60f226..9b7517f44 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -850,6 +850,16 @@ describe Users::DossiersController, type: :controller do end it { expect(assigns(:statut)).to eq('en-cours') } end + + context 'when the instructeur archive the dossier' do + before do + own_dossier2.update!(archived: true) + get(:index, params: { statut: 'en-cours' }) + end + it { expect(assigns(:statut)).to eq('en-cours') } + it { expect(assigns(:dossiers_traites).map(&:id)).to eq([own_dossier2.id]) } + it { expect(own_dossier2.archived).to be_truthy } + end end describe 'sort order' do