Merge pull request #1150 from sgmap/fix_1143-motivation_in_attestation

[Fix #1143] Set motivation before generating attestation
This commit is contained in:
Frederic Merizen 2017-12-22 10:29:18 +01:00 committed by GitHub
commit 51bf2ef374
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 13 deletions

View file

@ -107,12 +107,12 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
def process_dossier
create_dossier_facade params[:dossier_id]
if params[:dossier] && params[:dossier][:motivation].present?
motivation = params[:dossier][:motivation]
end
dossier = @facade.dossier
if params[:dossier] && params[:dossier][:motivation].present?
dossier.motivation = params[:dossier][:motivation]
end
case params[:process_action]
when "refuse"
dossier.refuse!
@ -129,10 +129,6 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
template = dossier.procedure.closed_mail_template
end
if motivation
dossier.motivation = motivation
end
dossier.save
# needed to force Carrierwave to provide dossier.attestation.pdf.read

View file

@ -76,7 +76,7 @@ module NewGestionnaire
def terminer
if params[:dossier] && params[:dossier][:motivation].present?
motivation = params[:dossier][:motivation]
dossier.motivation = params[:dossier][:motivation]
end
case params[:process_action]
@ -95,10 +95,6 @@ module NewGestionnaire
template = procedure.closed_mail_template
end
if motivation
dossier.motivation = motivation
end
dossier.save
# needed to force Carrierwave to provide dossier.attestation.pdf.read

View file

@ -349,6 +349,22 @@ describe Backoffice::DossiersController, type: :controller do
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

View file

@ -223,6 +223,27 @@ describe NewGestionnaire::DossiersController, type: :controller do
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