[fix 363] Dossier: remove next_step!
This commit is contained in:
parent
e78f5b3a2d
commit
9c354e18eb
4 changed files with 21 additions and 76 deletions
|
@ -115,20 +115,25 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
|
||||
case params[:process_action]
|
||||
when "refuse"
|
||||
next_step = "refuse"
|
||||
dossier.refuse!
|
||||
notice = "Dossier considéré comme refusé."
|
||||
template = dossier.procedure.refused_mail_template
|
||||
when "without_continuation"
|
||||
next_step = "without_continuation"
|
||||
dossier.sans_suite!
|
||||
notice = "Dossier considéré comme sans suite."
|
||||
template = dossier.procedure.without_continuation_mail_template
|
||||
when "close"
|
||||
next_step = "close"
|
||||
dossier.attestation = dossier.build_attestation
|
||||
dossier.accepte!
|
||||
notice = "Dossier traité avec succès."
|
||||
template = dossier.procedure.closed_mail_template
|
||||
end
|
||||
|
||||
dossier.next_step! 'gestionnaire', next_step, motivation
|
||||
if motivation
|
||||
dossier.motivation = motivation
|
||||
end
|
||||
|
||||
dossier.save
|
||||
|
||||
# needed to force Carrierwave to provide dossier.attestation.pdf.read
|
||||
# when the Feature.remote_storage is true, otherwise pdf.read is a closed stream.
|
||||
|
|
|
@ -81,20 +81,25 @@ module NewGestionnaire
|
|||
|
||||
case params[:process_action]
|
||||
when "refuser"
|
||||
next_step = "refuse"
|
||||
dossier.refuse!
|
||||
notice = "Dossier considéré comme refusé."
|
||||
template = procedure.refused_mail_template
|
||||
when "classer_sans_suite"
|
||||
next_step = "without_continuation"
|
||||
dossier.sans_suite!
|
||||
notice = "Dossier considéré comme sans suite."
|
||||
template = procedure.without_continuation_mail_template
|
||||
when "accepter"
|
||||
next_step = "close"
|
||||
dossier.attestation = dossier.build_attestation
|
||||
dossier.accepte!
|
||||
notice = "Dossier traité avec succès."
|
||||
template = procedure.closed_mail_template
|
||||
end
|
||||
|
||||
dossier.next_step!('gestionnaire', next_step, motivation)
|
||||
if motivation
|
||||
dossier.motivation = motivation
|
||||
end
|
||||
|
||||
dossier.save
|
||||
|
||||
# needed to force Carrierwave to provide dossier.attestation.pdf.read
|
||||
# when the Feature.remote_storage is true, otherwise pdf.read is a closed stream.
|
||||
|
|
|
@ -144,37 +144,6 @@ class Dossier < ActiveRecord::Base
|
|||
champs.joins(', types_de_piece_justificative').where("pieces_justificatives.type_de_piece_justificative_id = types_de_piece_justificative.id AND types_de_piece_justificative.procedure_id = #{procedure.id}").order('order_place ASC')
|
||||
end
|
||||
|
||||
def next_step!(action, motivation = nil)
|
||||
unless %w(receive refuse without_continuation close).include?(action)
|
||||
fail 'action is not valid'
|
||||
end
|
||||
|
||||
case action
|
||||
when 'close'
|
||||
if en_instruction?
|
||||
self.attestation = build_attestation
|
||||
save
|
||||
|
||||
accepte!
|
||||
end
|
||||
when 'refuse'
|
||||
if en_instruction?
|
||||
refuse!
|
||||
end
|
||||
when 'without_continuation'
|
||||
if en_instruction?
|
||||
sans_suite!
|
||||
end
|
||||
end
|
||||
|
||||
if motivation
|
||||
self.motivation = motivation
|
||||
save
|
||||
end
|
||||
|
||||
state
|
||||
end
|
||||
|
||||
def brouillon?
|
||||
BROUILLON.include?(state)
|
||||
end
|
||||
|
@ -355,14 +324,14 @@ class Dossier < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_attestation
|
||||
if procedure.attestation_template.present? && procedure.attestation_template.activated?
|
||||
procedure.attestation_template.attestation_for(self)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_state_dates
|
||||
if en_construction? && !self.en_construction_at
|
||||
self.en_construction_at = DateTime.now
|
||||
|
|
|
@ -116,40 +116,6 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#next_step' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:role) { 'user' }
|
||||
let(:action) { 'receive' }
|
||||
|
||||
subject { dossier.next_step! role, action }
|
||||
|
||||
context 'when action is not valid' do
|
||||
let(:action) { 'test' }
|
||||
it { expect { subject }.to raise_error('action is not valid') }
|
||||
end
|
||||
|
||||
context 'when role is not valid' do
|
||||
let(:role) { 'test' }
|
||||
it { expect { subject }.to raise_error('role is not valid') }
|
||||
end
|
||||
|
||||
context 'when dossier is at state en_instruction' do
|
||||
before do
|
||||
dossier.en_instruction!
|
||||
end
|
||||
|
||||
context 'when gestionnaire is connect' do
|
||||
let(:role) { 'gestionnaire' }
|
||||
|
||||
context 'when he closes the dossier' do
|
||||
let(:action) { 'close' }
|
||||
|
||||
it { is_expected.to eq('accepte') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#cerfa_available?' do
|
||||
|
@ -658,7 +624,7 @@ describe Dossier do
|
|||
let(:procedure) { create(:procedure, attestation_template: attestation_template) }
|
||||
|
||||
before :each do
|
||||
dossier.next_step!('gestionnaire', 'close')
|
||||
dossier.attestation = dossier.build_attestation
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue