Refactor Backoffice::DossiersController#process_dossier
This commit is contained in:
parent
0120995533
commit
12d74be668
2 changed files with 86 additions and 143 deletions
|
@ -104,63 +104,33 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
end
|
||||
|
||||
def process_dossier
|
||||
create_dossier_facade params[:dossier_id]
|
||||
|
||||
if params[:dossier] && params[:dossier][:motivation].present?
|
||||
motivation = params[:dossier][:motivation]
|
||||
end
|
||||
|
||||
dossier = @facade.dossier
|
||||
|
||||
case params[:process_action]
|
||||
when "refuse"
|
||||
refuse
|
||||
next_step = "refuse"
|
||||
notice = "Dossier considéré comme refusé."
|
||||
template = dossier.procedure.refused_mail_template
|
||||
when "without_continuation"
|
||||
without_continuation
|
||||
next_step = "without_continuation"
|
||||
notice = "Dossier considéré comme sans suite."
|
||||
template = dossier.procedure.without_continuation_mail_template
|
||||
when "close"
|
||||
close
|
||||
end
|
||||
next_step = "close"
|
||||
notice = "Dossier traité avec succès."
|
||||
template = dossier.procedure.closed_mail_template
|
||||
end
|
||||
|
||||
def refuse
|
||||
create_dossier_facade params[:dossier_id]
|
||||
dossier.next_step! 'gestionnaire', next_step, motivation
|
||||
flash.notice = notice
|
||||
|
||||
if params[:dossier] && params[:dossier][:motivation].present?
|
||||
motivation = params[:dossier][:motivation]
|
||||
end
|
||||
|
||||
dossier = @facade.dossier
|
||||
|
||||
dossier.next_step! 'gestionnaire', 'refuse', motivation
|
||||
flash.notice = 'Dossier considéré comme refusé.'
|
||||
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.refused_mail_template).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
||||
def without_continuation
|
||||
create_dossier_facade params[:dossier_id]
|
||||
|
||||
if params[:dossier] && params[:dossier][:motivation].present?
|
||||
motivation = params[:dossier][:motivation]
|
||||
end
|
||||
|
||||
dossier = @facade.dossier
|
||||
|
||||
dossier.next_step! 'gestionnaire', 'without_continuation', motivation
|
||||
flash.notice = 'Dossier considéré comme sans suite.'
|
||||
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.without_continuation_mail_template).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
||||
def close
|
||||
create_dossier_facade params[:dossier_id]
|
||||
|
||||
if params[:dossier] && params[:dossier][:motivation].present?
|
||||
motivation = params[:dossier][:motivation]
|
||||
end
|
||||
|
||||
dossier = @facade.dossier
|
||||
|
||||
dossier.next_step! 'gestionnaire', 'close', motivation
|
||||
flash.notice = 'Dossier traité avec succès.'
|
||||
|
||||
NotificationMailer.send_notification(dossier, dossier.procedure.closed_mail_template).deliver_now!
|
||||
NotificationMailer.send_notification(dossier, template).deliver_now!
|
||||
|
||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||
end
|
||||
|
|
|
@ -251,43 +251,13 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
describe 'POST #process_dossier' do
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
context "with refuse" do
|
||||
it "calls the refuse method" do
|
||||
expect(controller).to receive(:refuse)
|
||||
|
||||
post :process_dossier, params: { dossier_id: dossier_id, process_action: "refuse" }
|
||||
end
|
||||
end
|
||||
|
||||
context "with without_continuation" do
|
||||
it "calls the without_continuation method" do
|
||||
expect(controller).to receive(:without_continuation)
|
||||
|
||||
post :process_dossier, params: { dossier_id: dossier_id, process_action: "without_continuation" }
|
||||
end
|
||||
end
|
||||
|
||||
context "with close" do
|
||||
it "calls the close method" do
|
||||
expect(controller).to receive(:close)
|
||||
|
||||
post :process_dossier, params: { dossier_id: dossier_id, process_action: "close" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #refuse' do
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
subject { post :refuse, params: {dossier_id: dossier_id} }
|
||||
subject { post :process_dossier, params: { process_action: "refuse", dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to refused' do
|
||||
subject
|
||||
|
@ -307,12 +277,13 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
end
|
||||
|
||||
describe 'POST #without_continuation' do
|
||||
context "with without_continuation" do
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
subject { post :without_continuation, params: {dossier_id: dossier_id} }
|
||||
|
||||
subject { post :process_dossier, params: { process_action: "without_continuation", dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to without_continuation' do
|
||||
subject
|
||||
|
@ -332,12 +303,13 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
end
|
||||
|
||||
describe 'POST #close' do
|
||||
context "with close" do
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
subject { post :close, params: {dossier_id: dossier_id} }
|
||||
|
||||
subject { post :process_dossier, params: { process_action: "close", dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to closed' do
|
||||
subject
|
||||
|
@ -356,6 +328,7 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
|
||||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #toggle_follow' do
|
||||
before do
|
||||
|
|
Loading…
Reference in a new issue