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
|
end
|
||||||
|
|
||||||
def process_dossier
|
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]
|
case params[:process_action]
|
||||||
when "refuse"
|
when "refuse"
|
||||||
refuse
|
next_step = "refuse"
|
||||||
|
notice = "Dossier considéré comme refusé."
|
||||||
|
template = dossier.procedure.refused_mail_template
|
||||||
when "without_continuation"
|
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"
|
when "close"
|
||||||
close
|
next_step = "close"
|
||||||
end
|
notice = "Dossier traité avec succès."
|
||||||
end
|
template = dossier.procedure.closed_mail_template
|
||||||
|
|
||||||
def refuse
|
|
||||||
create_dossier_facade params[:dossier_id]
|
|
||||||
|
|
||||||
if params[:dossier] && params[:dossier][:motivation].present?
|
|
||||||
motivation = params[:dossier][:motivation]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
dossier = @facade.dossier
|
dossier.next_step! 'gestionnaire', next_step, motivation
|
||||||
|
flash.notice = notice
|
||||||
|
|
||||||
dossier.next_step! 'gestionnaire', 'refuse', motivation
|
NotificationMailer.send_notification(dossier, template).deliver_now!
|
||||||
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!
|
|
||||||
|
|
||||||
redirect_to backoffice_dossier_path(id: dossier.id)
|
redirect_to backoffice_dossier_path(id: dossier.id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -251,112 +251,85 @@ describe Backoffice::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #process_dossier' do
|
describe 'POST #process_dossier' do
|
||||||
before do
|
|
||||||
dossier.received!
|
|
||||||
sign_in gestionnaire
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with refuse" do
|
context "with refuse" do
|
||||||
it "calls the refuse method" do
|
before do
|
||||||
expect(controller).to receive(:refuse)
|
dossier.received!
|
||||||
|
sign_in gestionnaire
|
||||||
post :process_dossier, params: { dossier_id: dossier_id, process_action: "refuse" }
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "with without_continuation" do
|
context "with without_continuation" do
|
||||||
it "calls the without_continuation method" do
|
before do
|
||||||
expect(controller).to receive(:without_continuation)
|
dossier.received!
|
||||||
|
sign_in gestionnaire
|
||||||
post :process_dossier, params: { dossier_id: dossier_id, process_action: "without_continuation" }
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "with close" do
|
context "with close" do
|
||||||
it "calls the close method" do
|
before do
|
||||||
expect(controller).to receive(:close)
|
dossier.received!
|
||||||
|
sign_in gestionnaire
|
||||||
post :process_dossier, params: { dossier_id: dossier_id, process_action: "close" }
|
|
||||||
end
|
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
|
||||||
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
|
describe 'PUT #toggle_follow' do
|
||||||
before do
|
before do
|
||||||
sign_in gestionnaire
|
sign_in gestionnaire
|
||||||
|
|
Loading…
Add table
Reference in a new issue