ajout du lien vers le justificatif dans la balise --lien attestation--
This commit is contained in:
parent
747dc505cc
commit
f8a2598647
2 changed files with 31 additions and 2 deletions
|
@ -59,7 +59,13 @@ module TagsSubstitutionConcern
|
|||
{
|
||||
libelle: 'lien attestation',
|
||||
description: '',
|
||||
lambda: -> (d) { external_link(attestation_dossier_url(d)) },
|
||||
lambda: -> (d) {
|
||||
links = [external_link(attestation_dossier_url(d))]
|
||||
if d.justificatif_motivation.attached?
|
||||
links.push external_link_with_body("Télécharger le justificatif", url_for_justificatif_motivation(d))
|
||||
end
|
||||
links.join "<br />\n"
|
||||
},
|
||||
available_for_states: [Dossier.states.fetch(:accepte)]
|
||||
}
|
||||
]
|
||||
|
@ -142,6 +148,16 @@ module TagsSubstitutionConcern
|
|||
link_to(url, url, target: '_blank', rel: 'noopener')
|
||||
end
|
||||
|
||||
def external_link_with_body(body, url)
|
||||
link_to(body, url, target: '_blank', rel: 'noopener')
|
||||
end
|
||||
|
||||
def url_for_justificatif_motivation(dossier)
|
||||
if dossier.justificatif_motivation.attached?
|
||||
Rails.application.routes.url_helpers.url_for(dossier.justificatif_motivation)
|
||||
end
|
||||
end
|
||||
|
||||
def dossier_tags
|
||||
# Overridden by MailTemplateConcern
|
||||
DOSSIER_TAGS
|
||||
|
|
|
@ -5,6 +5,7 @@ describe MailTemplateConcern do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:dossier2) { create(:dossier, procedure: procedure) }
|
||||
let(:initiated_mail) { create(:initiated_mail, procedure: procedure) }
|
||||
let(:justificatif) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||
|
||||
shared_examples "can replace tokens in template" do
|
||||
describe 'with no token to replace' do
|
||||
|
@ -74,10 +75,22 @@ describe MailTemplateConcern do
|
|||
mail.body = "--lien attestation--"
|
||||
end
|
||||
|
||||
describe "in closed mail" do
|
||||
describe "in closed mail without justificatif" do
|
||||
let(:mail) { create(:closed_mail, procedure: procedure) }
|
||||
|
||||
it { is_expected.to eq("<a target=\"_blank\" rel=\"noopener\" href=\"http://localhost:3000/dossiers/#{dossier.id}/attestation\">http://localhost:3000/dossiers/#{dossier.id}/attestation</a>") }
|
||||
it { is_expected.to_not include("Télécharger le justificatif") }
|
||||
end
|
||||
|
||||
describe "in closed mail with justificatif" do
|
||||
before do
|
||||
dossier.justificatif_motivation.attach(justificatif)
|
||||
end
|
||||
let(:mail) { create(:closed_mail, procedure: procedure) }
|
||||
|
||||
it { expect(dossier.justificatif_motivation).to be_attached }
|
||||
it { is_expected.to start_with("<a target=\"_blank\" rel=\"noopener\" href=\"http://localhost:3000/dossiers/#{dossier.id}/attestation\">http://localhost:3000/dossiers/#{dossier.id}/attestation</a><br />\n") }
|
||||
it { is_expected.to include("Télécharger le justificatif") }
|
||||
end
|
||||
|
||||
describe "in refuse mail" do
|
||||
|
|
Loading…
Reference in a new issue