[#1563] Generate a helpful alert on attestation / closed mail mismatch

This commit is contained in:
Frederic Merizen 2018-04-03 14:20:21 +02:00
parent 809638df79
commit a2ffc4357d
2 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,22 @@
- case @procedure.closed_mail_template_attestation_inconsistency_state
- when :missing_tag
.center
.alert{ class: flash_class('alert') }
Cette procédure comporte une attestation, mais laccusé dacceptation ne la mentionne pas :
- if !@procedure.locked?
= link_to('désactivez lattestation', edit_admin_procedure_attestation_template_path(@procedure))
ou
= link_to('ajoutez la balise', edit_admin_procedure_mail_template_path(@procedure, Mails::ClosedMail::SLUG))
%code{ style: "white-space: pre-wrap;" }
\--lien attestation--
à laccusé dacceptation
- when :extraneous_tag
.center
.alert{ class: flash_class('alert') }
Cette procédure ne comporte pas dattestation, mais laccusé dacceptation en mentionne une :
= link_to('activez lattestation', edit_admin_procedure_attestation_template_path(@procedure))
ou
= link_to('enlevez la balise', edit_admin_procedure_mail_template_path(@procedure, Mails::ClosedMail::SLUG))
%code{ style: "white-space: pre-wrap;" }
\--lien attestation--
de laccusé dacceptation

View file

@ -0,0 +1,46 @@
require 'spec_helper'
describe 'admin/_closed_mail_template_attestation_inconsistency_alert.html.haml', type: :view do
let(:procedure) { create(:procedure, closed_mail: closed_mail, published_at: published_at) }
let(:published_at) { nil }
def alert
assign(:procedure, procedure)
render
rendered
end
context 'when there is no inconsistency' do
let(:closed_mail) { nil }
it { expect(alert).to be_empty }
end
context 'when there is no active attestation but the closed mail template mentions one' do
let(:closed_mail) { create(:closed_mail, body: '--lien attestation--') }
it { expect(alert).to include("Cette procédure ne comporte pas dattestation, mais laccusé dacceptation en mentionne une") }
it { expect(alert).to include(edit_admin_procedure_attestation_template_path(procedure)) }
it { expect(alert).to include(edit_admin_procedure_mail_template_path(procedure, Mails::ClosedMail::SLUG)) }
end
context 'when there is an active attestation but the closed mail template does not mention it' do
let(:closed_mail) { create(:closed_mail) }
let!(:attestation_template) { create(:attestation_template, procedure: procedure, activated: true) }
it { expect(alert).to include("Cette procédure comporte une attestation, mais laccusé dacceptation ne la mentionne pas") }
it { expect(alert).to include(edit_admin_procedure_mail_template_path(procedure, Mails::ClosedMail::SLUG)) }
context 'when the procedure has been published, the attestation cannot be deactivated' do
let(:published_at) { Time.now }
it { expect(procedure.locked?).to be_truthy }
it { expect(alert).not_to include(edit_admin_procedure_attestation_template_path(procedure)) }
end
context 'when the procedure is still a draft' do
it { expect(procedure.locked?).to be_falsey }
it { expect(alert).to include(edit_admin_procedure_attestation_template_path(procedure)) }
end
end
end