Merge pull request #6691 from betagouv/fix-delete-dossier-by-user
Fix delete dossier by user
This commit is contained in:
commit
8e2122cb62
3 changed files with 45 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue