Merge pull request #1150 from sgmap/fix_1143-motivation_in_attestation
[Fix #1143] Set motivation before generating attestation
This commit is contained in:
commit
51bf2ef374
4 changed files with 42 additions and 13 deletions
|
@ -107,12 +107,12 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
||||||
def process_dossier
|
def process_dossier
|
||||||
create_dossier_facade params[:dossier_id]
|
create_dossier_facade params[:dossier_id]
|
||||||
|
|
||||||
if params[:dossier] && params[:dossier][:motivation].present?
|
|
||||||
motivation = params[:dossier][:motivation]
|
|
||||||
end
|
|
||||||
|
|
||||||
dossier = @facade.dossier
|
dossier = @facade.dossier
|
||||||
|
|
||||||
|
if params[:dossier] && params[:dossier][:motivation].present?
|
||||||
|
dossier.motivation = params[:dossier][:motivation]
|
||||||
|
end
|
||||||
|
|
||||||
case params[:process_action]
|
case params[:process_action]
|
||||||
when "refuse"
|
when "refuse"
|
||||||
dossier.refuse!
|
dossier.refuse!
|
||||||
|
@ -129,10 +129,6 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
||||||
template = dossier.procedure.closed_mail_template
|
template = dossier.procedure.closed_mail_template
|
||||||
end
|
end
|
||||||
|
|
||||||
if motivation
|
|
||||||
dossier.motivation = motivation
|
|
||||||
end
|
|
||||||
|
|
||||||
dossier.save
|
dossier.save
|
||||||
|
|
||||||
# needed to force Carrierwave to provide dossier.attestation.pdf.read
|
# needed to force Carrierwave to provide dossier.attestation.pdf.read
|
||||||
|
|
|
@ -76,7 +76,7 @@ module NewGestionnaire
|
||||||
|
|
||||||
def terminer
|
def terminer
|
||||||
if params[:dossier] && params[:dossier][:motivation].present?
|
if params[:dossier] && params[:dossier][:motivation].present?
|
||||||
motivation = params[:dossier][:motivation]
|
dossier.motivation = params[:dossier][:motivation]
|
||||||
end
|
end
|
||||||
|
|
||||||
case params[:process_action]
|
case params[:process_action]
|
||||||
|
@ -95,10 +95,6 @@ module NewGestionnaire
|
||||||
template = procedure.closed_mail_template
|
template = procedure.closed_mail_template
|
||||||
end
|
end
|
||||||
|
|
||||||
if motivation
|
|
||||||
dossier.motivation = motivation
|
|
||||||
end
|
|
||||||
|
|
||||||
dossier.save
|
dossier.save
|
||||||
|
|
||||||
# needed to force Carrierwave to provide dossier.attestation.pdf.read
|
# needed to force Carrierwave to provide dossier.attestation.pdf.read
|
||||||
|
|
|
@ -349,6 +349,22 @@ describe Backoffice::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the attestation template uses the motivation field', focus: true do
|
||||||
|
let(:emailable) { false }
|
||||||
|
let(:template) { create(:attestation_template) }
|
||||||
|
let(:procedure) { create(:procedure, :published, attestation_template: template, gestionnaires: [gestionnaire]) }
|
||||||
|
|
||||||
|
subject { post :process_dossier, params: { process_action: "close", dossier_id: dossier_id, dossier: { motivation: "Yallah" }}}
|
||||||
|
|
||||||
|
before do
|
||||||
|
expect_any_instance_of(AttestationTemplate)
|
||||||
|
.to receive(:attestation_for)
|
||||||
|
.with(have_attributes(motivation: "Yallah"))
|
||||||
|
end
|
||||||
|
|
||||||
|
it { subject }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,27 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the attestation template uses the motivation field', focus: true do
|
||||||
|
let(:emailable) { false }
|
||||||
|
let(:template) { create(:attestation_template) }
|
||||||
|
let(:procedure) { create(:procedure, :published, attestation_template: template, gestionnaires: [gestionnaire]) }
|
||||||
|
|
||||||
|
subject do
|
||||||
|
post :terminer, params: { process_action: "accepter",
|
||||||
|
procedure_id: procedure.id,
|
||||||
|
dossier_id: dossier.id,
|
||||||
|
dossier: { motivation: "Yallah" }}
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
expect_any_instance_of(AttestationTemplate)
|
||||||
|
.to receive(:attestation_for)
|
||||||
|
.with(have_attributes(motivation: "Yallah"))
|
||||||
|
end
|
||||||
|
|
||||||
|
it { subject }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue