Merge pull request #5445 from betagouv/fix-attestation-rendering
Attestations : correction du rendu des PDFs
This commit is contained in:
commit
1e9da059d3
2 changed files with 13 additions and 7 deletions
|
@ -109,8 +109,11 @@ class AttestationTemplate < ApplicationRecord
|
||||||
|
|
||||||
def build_pdf(dossier)
|
def build_pdf(dossier)
|
||||||
attestation = render_attributes_for(dossier: dossier)
|
attestation = render_attributes_for(dossier: dossier)
|
||||||
action_view = ActionView::Base.new(ActionController::Base.view_paths, attestation: attestation)
|
attestation_view = ApplicationController.render(
|
||||||
attestation_view = action_view.render(file: 'new_administrateur/attestation_templates/show', formats: [:pdf])
|
file: 'new_administrateur/attestation_templates/show',
|
||||||
|
formats: :pdf,
|
||||||
|
assigns: { attestation: attestation }
|
||||||
|
)
|
||||||
|
|
||||||
StringIO.new(attestation_view)
|
StringIO.new(attestation_view)
|
||||||
end
|
end
|
||||||
|
|
|
@ -122,12 +122,11 @@ describe AttestationTemplate, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:view_args) do
|
let(:view_args) do
|
||||||
original_new = ActionView::Base.method(:new)
|
|
||||||
arguments = nil
|
arguments = nil
|
||||||
|
|
||||||
allow(ActionView::Base).to receive(:new) do |paths, args|
|
allow(ApplicationController).to receive(:render).and_wrap_original do |m, *args|
|
||||||
arguments = args
|
arguments = args.first[:assigns]
|
||||||
original_new.call(paths, args)
|
m.call(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
attestation_template.attestation_for(dossier)
|
attestation_template.attestation_for(dossier)
|
||||||
|
@ -162,10 +161,14 @@ describe AttestationTemplate, type: :model do
|
||||||
.update(value: 'libelle2')
|
.update(value: 'libelle2')
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it 'passes the correct parameters to the view' do
|
||||||
expect(view_args[:attestation][:title]).to eq('title libelle1')
|
expect(view_args[:attestation][:title]).to eq('title libelle1')
|
||||||
expect(view_args[:attestation][:body]).to eq('body libelle2')
|
expect(view_args[:attestation][:body]).to eq('body libelle2')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'generates an attestation' do
|
||||||
expect(attestation.title).to eq('title libelle1')
|
expect(attestation.title).to eq('title libelle1')
|
||||||
|
expect(attestation.pdf).to be_attached
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue