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
|
||||
end
|
||||
|
||||
def refuse
|
||||
create_dossier_facade params[:dossier_id]
|
||||
|
||||
if params[:dossier] && params[:dossier][:motivation].present?
|
||||
motivation = params[:dossier][:motivation]
|
||||
next_step = "close"
|
||||
notice = "Dossier traité avec succès."
|
||||
template = dossier.procedure.closed_mail_template
|
||||
end
|
||||
|
||||
dossier = @facade.dossier
|
||||
dossier.next_step! 'gestionnaire', next_step, motivation
|
||||
flash.notice = notice
|
||||
|
||||
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,112 +251,85 @@ 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" }
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
subject { post :process_dossier, params: { process_action: "refuse", dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to refused' do
|
||||
subject
|
||||
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('refused')
|
||||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::RefusedMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
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" }
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
subject { post :process_dossier, params: { process_action: "without_continuation", dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to without_continuation' do
|
||||
subject
|
||||
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('without_continuation')
|
||||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::WithoutContinuationMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
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" }
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
subject { post :process_dossier, params: { process_action: "close", dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to closed' do
|
||||
subject
|
||||
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('closed')
|
||||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::ClosedMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #refuse' do
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
subject { post :refuse, params: {dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to refused' do
|
||||
subject
|
||||
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('refused')
|
||||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::RefusedMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
end
|
||||
|
||||
describe 'POST #without_continuation' do
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
subject { post :without_continuation, params: {dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to without_continuation' do
|
||||
subject
|
||||
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('without_continuation')
|
||||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::WithoutContinuationMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
end
|
||||
|
||||
describe 'POST #close' do
|
||||
before do
|
||||
dossier.received!
|
||||
sign_in gestionnaire
|
||||
end
|
||||
subject { post :close, params: {dossier_id: dossier_id} }
|
||||
|
||||
it 'change state to closed' do
|
||||
subject
|
||||
|
||||
dossier.reload
|
||||
expect(dossier.state).to eq('closed')
|
||||
end
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_notification)
|
||||
.with(dossier, kind_of(Mails::ClosedMail)).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to backoffice_dossier_path(id: dossier.id) }
|
||||
end
|
||||
|
||||
describe 'PUT #toggle_follow' do
|
||||
before do
|
||||
sign_in gestionnaire
|
||||
|
|
Loading…
Reference in a new issue