[fix 363] Dossier: remove next_step!

This commit is contained in:
Simon Lehericey 2017-12-05 17:43:32 +01:00 committed by LeSim
parent e78f5b3a2d
commit 9c354e18eb
4 changed files with 21 additions and 76 deletions

View file

@ -115,20 +115,25 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
case params[:process_action] case params[:process_action]
when "refuse" when "refuse"
next_step = "refuse" dossier.refuse!
notice = "Dossier considéré comme refusé." notice = "Dossier considéré comme refusé."
template = dossier.procedure.refused_mail_template template = dossier.procedure.refused_mail_template
when "without_continuation" when "without_continuation"
next_step = "without_continuation" dossier.sans_suite!
notice = "Dossier considéré comme sans suite." notice = "Dossier considéré comme sans suite."
template = dossier.procedure.without_continuation_mail_template template = dossier.procedure.without_continuation_mail_template
when "close" when "close"
next_step = "close" dossier.attestation = dossier.build_attestation
dossier.accepte!
notice = "Dossier traité avec succès." notice = "Dossier traité avec succès."
template = dossier.procedure.closed_mail_template template = dossier.procedure.closed_mail_template
end 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 # needed to force Carrierwave to provide dossier.attestation.pdf.read
# when the Feature.remote_storage is true, otherwise pdf.read is a closed stream. # when the Feature.remote_storage is true, otherwise pdf.read is a closed stream.

View file

@ -81,20 +81,25 @@ module NewGestionnaire
case params[:process_action] case params[:process_action]
when "refuser" when "refuser"
next_step = "refuse" dossier.refuse!
notice = "Dossier considéré comme refusé." notice = "Dossier considéré comme refusé."
template = procedure.refused_mail_template template = procedure.refused_mail_template
when "classer_sans_suite" when "classer_sans_suite"
next_step = "without_continuation" dossier.sans_suite!
notice = "Dossier considéré comme sans suite." notice = "Dossier considéré comme sans suite."
template = procedure.without_continuation_mail_template template = procedure.without_continuation_mail_template
when "accepter" when "accepter"
next_step = "close" dossier.attestation = dossier.build_attestation
dossier.accepte!
notice = "Dossier traité avec succès." notice = "Dossier traité avec succès."
template = procedure.closed_mail_template template = procedure.closed_mail_template
end 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 # needed to force Carrierwave to provide dossier.attestation.pdf.read
# when the Feature.remote_storage is true, otherwise pdf.read is a closed stream. # when the Feature.remote_storage is true, otherwise pdf.read is a closed stream.

View file

@ -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') 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 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? def brouillon?
BROUILLON.include?(state) BROUILLON.include?(state)
end end
@ -355,14 +324,14 @@ class Dossier < ActiveRecord::Base
end end
end end
private
def build_attestation def build_attestation
if procedure.attestation_template.present? && procedure.attestation_template.activated? if procedure.attestation_template.present? && procedure.attestation_template.activated?
procedure.attestation_template.attestation_for(self) procedure.attestation_template.attestation_for(self)
end end
end end
private
def update_state_dates def update_state_dates
if en_construction? && !self.en_construction_at if en_construction? && !self.en_construction_at
self.en_construction_at = DateTime.now self.en_construction_at = DateTime.now

View file

@ -116,40 +116,6 @@ describe Dossier do
end end
end 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 end
describe '#cerfa_available?' do describe '#cerfa_available?' do
@ -658,7 +624,7 @@ describe Dossier do
let(:procedure) { create(:procedure, attestation_template: attestation_template) } let(:procedure) { create(:procedure, attestation_template: attestation_template) }
before :each do before :each do
dossier.next_step!('gestionnaire', 'close') dossier.attestation = dossier.build_attestation
dossier.reload dossier.reload
end end