diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb
index 6be66c76a..0d3c0cc6e 100644
--- a/app/models/concerns/tags_substitution_concern.rb
+++ b/app/models/concerns/tags_substitution_concern.rb
@@ -59,14 +59,20 @@ module TagsSubstitutionConcern
{
libelle: 'lien attestation',
description: '',
- lambda: -> (d) {
- links = [external_link(attestation_dossier_url(d))]
- if d.justificatif_motivation.attached?
- links.push external_link("Télécharger le justificatif", url_for_justificatif_motivation(d))
- end
- links.join "
\n"
- },
+ lambda: -> (d) { external_link(attestation_dossier_url(d)) },
available_for_states: [Dossier.states.fetch(:accepte)]
+ },
+ {
+ libelle: 'lien document justificatif',
+ description: '',
+ lambda: -> (d) {
+ if d.justificatif_motivation.attached?
+ external_link(url_for_justificatif_motivation(d), "Télécharger le document justificatif")
+ else
+ return "[l'instructeur n'a pas joint de document supplémentaire]"
+ end
+ },
+ available_for_states: Dossier::SOUMIS
}
]
diff --git a/spec/models/concern/mail_template_concern_spec.rb b/spec/models/concern/mail_template_concern_spec.rb
index 2598aa46a..6ebdc4c7a 100644
--- a/spec/models/concern/mail_template_concern_spec.rb
+++ b/spec/models/concern/mail_template_concern_spec.rb
@@ -89,7 +89,7 @@ describe MailTemplateConcern do
it { expect(dossier.justificatif_motivation).to be_attached }
it { is_expected.to include("http://localhost:3000/dossiers/#{dossier.id}/attestation") }
- it { is_expected.to include("Télécharger le justificatif") }
+ it { is_expected.to_not include("Télécharger le justificatif") }
end
describe "in refuse mail" do
@@ -104,6 +104,61 @@ describe MailTemplateConcern do
it { is_expected.to eq("--lien attestation--") }
end
end
+
+ describe '--lien document justificatif--' do
+ let(:procedure) { create(:procedure) }
+
+ subject { mail.body_for_dossier(dossier) }
+
+ before do
+ mail.body = "--lien document justificatif--"
+ end
+
+ describe "in closed mail" do
+ let(:mail) { create(:closed_mail, procedure: procedure) }
+ describe 'without justificatif' do
+ it { is_expected.to include("[l'instructeur n'a pas joint de document supplémentaire]") }
+ end
+
+ describe 'with justificatif' do
+ before do
+ dossier.justificatif_motivation.attach(justificatif)
+ end
+ it { expect(dossier.justificatif_motivation).to be_attached }
+ it { is_expected.to include("Télécharger le document justificatif") }
+ end
+ end
+
+ describe "in refused mail" do
+ let(:mail) { create(:refused_mail, procedure: procedure) }
+ describe 'without justificatif' do
+ it { is_expected.to include("[l'instructeur n'a pas joint de document supplémentaire]") }
+ end
+
+ describe 'with justificatif' do
+ before do
+ dossier.justificatif_motivation.attach(justificatif)
+ end
+ it { expect(dossier.justificatif_motivation).to be_attached }
+ it { is_expected.to include("Télécharger le document justificatif") }
+ end
+ end
+
+ describe "in without continuation mail" do
+ let(:mail) { create(:without_continuation_mail, procedure: procedure) }
+ describe 'without justificatif' do
+ it { is_expected.to include("[l'instructeur n'a pas joint de document supplémentaire]") }
+ end
+
+ describe 'with justificatif' do
+ before do
+ dossier.justificatif_motivation.attach(justificatif)
+ end
+ it { expect(dossier.justificatif_motivation).to be_attached }
+ it { is_expected.to include("Télécharger le document justificatif") }
+ end
+ end
+ end
end
describe '#replace_tags' do