From 0093db18a1110c4272ecb0c660ecb553f08d3431 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Apr 2018 11:43:25 +0200 Subject: [PATCH 01/11] Individual: add a second birthdate which is a date --- ...180403094135_add_second_birthdate_column_to_individual.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180403094135_add_second_birthdate_column_to_individual.rb diff --git a/db/migrate/20180403094135_add_second_birthdate_column_to_individual.rb b/db/migrate/20180403094135_add_second_birthdate_column_to_individual.rb new file mode 100644 index 000000000..a3a8c1c4f --- /dev/null +++ b/db/migrate/20180403094135_add_second_birthdate_column_to_individual.rb @@ -0,0 +1,5 @@ +class AddSecondBirthdateColumnToIndividual < ActiveRecord::Migration[5.2] + def change + add_column :individuals, :second_birthdate, :date + end +end diff --git a/db/schema.rb b/db/schema.rb index 0e708a7fe..303a660fd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_03_23_101837) do +ActiveRecord::Schema.define(version: 2018_04_03_094135) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -366,6 +366,7 @@ ActiveRecord::Schema.define(version: 2018_03_23_101837) do t.string "gender" t.datetime "created_at" t.datetime "updated_at" + t.date "second_birthdate" t.index ["dossier_id"], name: "index_individuals_on_dossier_id" end From 8828663880240e2c66d511e088513e93ac19c89d Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Apr 2018 11:57:16 +0200 Subject: [PATCH 02/11] Individual: save the birthdate in Y --- app/models/individual.rb | 10 ++++++++++ spec/models/individual_spec.rb | 3 +++ 2 files changed, 13 insertions(+) diff --git a/app/models/individual.rb b/app/models/individual.rb index 3a0c1410c..b5ac55067 100644 --- a/app/models/individual.rb +++ b/app/models/individual.rb @@ -8,6 +8,7 @@ class Individual < ApplicationRecord validates :birthdate, format: { with: /\A\d{4}\-\d{2}\-\d{2}\z/, message: "La date n'est pas au format AAAA-MM-JJ" }, allow_nil: true before_validation :set_iso_date, if: -> { birthdate_changed? } + before_save :save_birthdate_in_datetime_format private @@ -17,4 +18,13 @@ class Individual < ApplicationRecord self.birthdate = Date.parse(birthdate).iso8601 end end + + def save_birthdate_in_datetime_format + if birthdate.present? + begin + self.second_birthdate = Date.parse(birthdate) + rescue + end + end + end end diff --git a/spec/models/individual_spec.rb b/spec/models/individual_spec.rb index c101a1ca7..43d627139 100644 --- a/spec/models/individual_spec.rb +++ b/spec/models/individual_spec.rb @@ -23,6 +23,7 @@ describe Individual do it { expect(individual.valid?).to be true } it { expect(individual.birthdate).to eq("1980-11-12") } + it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) } end context "and the format is ISO" do @@ -30,6 +31,7 @@ describe Individual do it { expect(individual.valid?).to be true } it { expect(individual.birthdate).to eq("1980-11-12") } + it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) } end context "and the format is WTF" do @@ -37,6 +39,7 @@ describe Individual do it { expect(individual.valid?).to be false } it { expect(individual.birthdate).to eq("1980 1 12") } + it { expect(individual.second_birthdate).to be_nil } end end end From 6370365fe430a93de1794513604bc555689b4b14 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Apr 2018 12:11:17 +0200 Subject: [PATCH 03/11] Task: parse individual_date --- lib/tasks/2018_04_03_type_individual_date.rake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/tasks/2018_04_03_type_individual_date.rake diff --git a/lib/tasks/2018_04_03_type_individual_date.rake b/lib/tasks/2018_04_03_type_individual_date.rake new file mode 100644 index 000000000..b9af6d731 --- /dev/null +++ b/lib/tasks/2018_04_03_type_individual_date.rake @@ -0,0 +1,14 @@ +namespace :'2018_04_03_type_individual_date' do + task set: :environment do + Individual.all.each { |individual| save_birthdate_in_datetime_format(individual) } + end + + def save_birthdate_in_datetime_format(individual) + if individual.birthdate.present? + begin + individual.update_column(:second_birthdate, Date.parse(individual.birthdate)) + rescue + end + end + end +end From 9749365cc7b42cb0719afdab01eb215dad50d507 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Apr 2018 18:25:42 +0200 Subject: [PATCH 04/11] Etape2 individual: procedure with individual uses the new system --- app/views/dossiers/etapes/_etape2.html.haml | 5 +- .../etapes/etape_2/_individual.html.haml | 47 ------------------- 2 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 app/views/dossiers/etapes/etape_2/_individual.html.haml diff --git a/app/views/dossiers/etapes/_etape2.html.haml b/app/views/dossiers/etapes/_etape2.html.haml index 0c18f10e7..4dbf20800 100644 --- a/app/views/dossiers/etapes/_etape2.html.haml +++ b/app/views/dossiers/etapes/_etape2.html.haml @@ -1,4 +1 @@ -- if @facade.procedure.for_individual? - = render partial: 'dossiers/etapes/etape_2/individual' -- else - = render partial: 'dossiers/etapes/etape_2/entreprise' += render partial: 'dossiers/etapes/etape_2/entreprise' diff --git a/app/views/dossiers/etapes/etape_2/_individual.html.haml b/app/views/dossiers/etapes/etape_2/_individual.html.haml deleted file mode 100644 index e1cce9eb9..000000000 --- a/app/views/dossiers/etapes/etape_2/_individual.html.haml +++ /dev/null @@ -1,47 +0,0 @@ -.col-xs-3.center - %h3 Mes informations - %p - Les informations de bases - %br - vous concernant. - -.etape.etapes-informations.col-xs-9 - = form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f| - .row - .col-xs-12.padding-left-30 - = f.hidden_field :id - - = f.fields_for :individual, @facade.individual do |ff| - .form-group - %label - %h4 - Civilité - = ff.select :gender, ['M.', 'Mme'] - .form-group - %label - %h4 - Nom * - = ff.text_field :nom, { class: 'form-control', required: true } - .form-group - %label - %h4 - Prénom * - = ff.text_field :prenom, { class: 'form-control', required: true } - - - if @facade.procedure.ask_birthday? - .form-group - %label - %h4 - Date de naissance * - = ff.date_field :birthdate, { value: @facade.individual.birthdate, class: 'form-control', placeholder: 'jj/mm/aaaa', required: true } - - %p - %label{ style: 'font-weight: normal;' } - = f.check_box :autorisation_donnees -  J'accepte - = link_to "les CGU", CGU_URL, target: :blank - .row - .col-xs-5.col-xs-5 - .col-xs-2.col-xs-2 - = f.submit 'Etape suivante', class: "action", id: 'etape_suivante' - .col-xs-5.col-xs-5 From 46fd213ad2fa2f68715f6be60a7e0e59b20c0266 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Apr 2018 21:15:50 +0200 Subject: [PATCH 05/11] Individual: old controller does not care about individual anymore --- app/controllers/users/dossiers_controller.rb | 27 +------------------ .../users/dossiers_controller_spec.rb | 23 ---------------- 2 files changed, 1 insertion(+), 49 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index c67c8818c..a32f5d522 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -148,7 +148,7 @@ class Users::DossiersController < UsersController flash.alert = individual_errors redirect_to users_dossier_path(id: @facade.dossier.id) else - if !Dossier.find(@facade.dossier.id).update update_params_with_formatted_birthdate + if !Dossier.find(@facade.dossier.id).update(update_params) flash.alert = @facade.dossier.errors.full_messages return redirect_to users_dossier_path(id: @facade.dossier.id) @@ -201,24 +201,6 @@ class Users::DossiersController < UsersController params.require(:dossier).permit(:id, :autorisation_donnees, individual_attributes: [:gender, :nom, :prenom, :birthdate]) end - def update_params_with_formatted_birthdate - editable_params = update_params - - if editable_params && - editable_params[:individual_attributes] && - editable_params[:individual_attributes][:birthdate] - - iso_date = begin - Date.parse(editable_params[:individual_attributes][:birthdate]).iso8601 - rescue - nil - end - editable_params[:individual_attributes][:birthdate] = iso_date - end - - editable_params - end - def individual_errors errors = [] @@ -226,13 +208,6 @@ class Users::DossiersController < UsersController errors << "La validation des conditions d'utilisation est obligatoire" end - if update_params[:individual_attributes].present? && - update_params[:individual_attributes][:birthdate] && - !/^\d{4}\-\d{2}\-\d{2}$/.match(update_params[:individual_attributes][:birthdate]) && - !/^\d{2}\/\d{2}\/\d{4}$/.match(update_params[:individual_attributes][:birthdate]) - errors << "Le format de la date de naissance doit être JJ/MM/AAAA" - end - errors end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index bdc08979e..53a550401 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -345,29 +345,6 @@ describe Users::DossiersController, type: :controller do subject end - context 'when procedure is for individual' do - let(:autorisation_donnees) { "1" } - let(:procedure) { create(:procedure, :published, for_individual: true) } - - before do - dossier.reload - end - - it { expect(dossier.individual.gender).to eq 'M.' } - it { expect(dossier.individual.nom).to eq 'Julien' } - it { expect(dossier.individual.prenom).to eq 'Xavier' } - it { expect(dossier.individual.birthdate).to eq '1991-01-20' } - it { expect(dossier.procedure.for_individual).to eq true } - - context "and birthdate is ISO (YYYY-MM-DD) formatted" do - let(:birthdate) { "1991-11-01" } - before do - dossier.reload - end - it { expect(dossier.individual.birthdate).to eq '1991-11-01' } - end - end - context 'when Checkbox is checked' do let(:autorisation_donnees) { '1' } From abf938ff1b8533ce540618a420a33ba64e3511f4 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 16 Mar 2018 17:11:19 +0100 Subject: [PATCH 06/11] [#1563] Generalise external link generation for mails --- app/models/concerns/tags_substitution_concern.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index b6ce914d0..b88dd65c3 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -47,7 +47,7 @@ module TagsSubstitutionConcern { libelle: 'lien dossier', description: '', - lambda: -> (d) { users_dossier_recapitulatif_link(d) }, + lambda: -> (d) { external_link(users_dossier_recapitulatif_url(d)) }, available_for_states: Dossier::SOUMIS } ] @@ -126,8 +126,7 @@ module TagsSubstitutionConcern end end - def users_dossier_recapitulatif_link(dossier) - url = users_dossier_recapitulatif_url(dossier) + def external_link(url) link_to(url, url, target: '_blank') end From 84c864ed11ad435db056a5d91042e6eade3a2a62 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 16 Mar 2018 17:17:26 +0100 Subject: [PATCH 07/11] [#1563] Add lien attestation link to closed mail template --- .../concerns/tags_substitution_concern.rb | 6 +++++ .../concern/mail_template_concern_spec.rb | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index b88dd65c3..e3ee333bd 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -49,6 +49,12 @@ module TagsSubstitutionConcern description: '', lambda: -> (d) { external_link(users_dossier_recapitulatif_url(d)) }, available_for_states: Dossier::SOUMIS + }, + { + libelle: 'lien attestation', + description: '', + lambda: -> (d) { external_link(dossier_attestation_url(d)) }, + available_for_states: ['accepte'] } ] diff --git a/spec/models/concern/mail_template_concern_spec.rb b/spec/models/concern/mail_template_concern_spec.rb index 9eddc36ad..2a968be58 100644 --- a/spec/models/concern/mail_template_concern_spec.rb +++ b/spec/models/concern/mail_template_concern_spec.rb @@ -61,6 +61,31 @@ describe MailTemplateConcern do expect(received_mail.tags).to include(include({ libelle: 'date de passage en instruction' })) end end + + describe '--lien attestation--' do + let(:attestation_template) { AttestationTemplate.new(activated: true) } + let(:procedure) { create(:procedure, attestation_template: attestation_template) } + + subject { mail.body_for_dossier(dossier) } + + before do + dossier.attestation = dossier.build_attestation + dossier.reload + mail.body = "--lien attestation--" + end + + describe "in closed mail" do + let(:mail) { create(:closed_mail, procedure: procedure) } + + it { is_expected.to eq("http://localhost:3000/dossiers/#{dossier.id}/attestation") } + end + + describe "in refuse mail" do + let(:mail) { create(:refused_mail, procedure: procedure) } + + it { is_expected.to eq("--lien attestation--") } + end + end end describe '#replace_tags' do From 66aca609575d99f684531a33d0bd662e3944aa46 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 16 Mar 2018 18:30:23 +0100 Subject: [PATCH 08/11] [#1563] Remove useless self keywords --- app/models/concerns/mail_template_concern.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index 387b515e2..162df7e98 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -13,8 +13,8 @@ module MailTemplateConcern module ClassMethods def default_for_procedure(procedure) - body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME)) - self.new(subject: self.const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure) + body = ActionController::Base.new.render_to_string(template: const_get(:TEMPLATE_NAME)) + new(subject: const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure) end end From 7bf7347b9cb7fe040fe33ceb8cf074e0c89aabf7 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 4 Apr 2018 09:40:55 +0200 Subject: [PATCH 09/11] =?UTF-8?q?[#1563]=20Clarify=20constant=E2=80=99s=20?= =?UTF-8?q?role?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/mail_template_concern.rb | 2 +- app/models/mails/closed_mail.rb | 2 +- app/models/mails/initiated_mail.rb | 2 +- app/models/mails/received_mail.rb | 2 +- app/models/mails/refused_mail.rb | 2 +- app/models/mails/without_continuation_mail.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index 162df7e98..ad455cd4b 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -13,7 +13,7 @@ module MailTemplateConcern module ClassMethods def default_for_procedure(procedure) - body = ActionController::Base.new.render_to_string(template: const_get(:TEMPLATE_NAME)) + body = ActionController::Base.new.render_to_string(template: const_get(:DEFAULT_TEMPLATE_NAME)) new(subject: const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure) end end diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index be289584d..8dae9d9ee 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "closed_mail" - TEMPLATE_NAME = "mails/closed_mail" + DEFAULT_TEMPLATE_NAME = "mails/closed_mail" DISPLAYED_NAME = "Accusé d'acceptation" DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a été accepté' DOSSIER_STATE = 'accepte' diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index 1cc4067ea..0bcac1da0 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "initiated_mail" - TEMPLATE_NAME = "mails/initiated_mail" + DEFAULT_TEMPLATE_NAME = "mails/initiated_mail" DISPLAYED_NAME = 'Accusé de réception' DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a bien été reçu' DOSSIER_STATE = 'en_construction' diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index 6afda62b4..ca6163cbf 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "received_mail" - TEMPLATE_NAME = "mails/received_mail" + DEFAULT_TEMPLATE_NAME = "mails/received_mail" DISPLAYED_NAME = 'Accusé de passage en instruction' DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- va être instruit' DOSSIER_STATE = 'en_instruction' diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index f3446a4cc..aef42ee89 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "refused_mail" - TEMPLATE_NAME = "mails/refused_mail" + DEFAULT_TEMPLATE_NAME = "mails/refused_mail" DISPLAYED_NAME = 'Accusé de rejet du dossier' DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a été refusé' DOSSIER_STATE = 'refuse' diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb index 9d5e59de1..c7768d131 100644 --- a/app/models/mails/without_continuation_mail.rb +++ b/app/models/mails/without_continuation_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "without_continuation" - TEMPLATE_NAME = "mails/without_continuation_mail" + DEFAULT_TEMPLATE_NAME = "mails/without_continuation_mail" DISPLAYED_NAME = 'Accusé de classement sans suite' DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a été classé sans suite' DOSSIER_STATE = 'sans_suite' From db0937d1eb58a98e8af6dc65158c9eaaf9c11755 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 16 Mar 2018 18:32:43 +0100 Subject: [PATCH 10/11] [#1563] Allow default template name to depend on procedure --- app/models/concerns/mail_template_concern.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index ad455cd4b..107451969 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -13,9 +13,14 @@ module MailTemplateConcern module ClassMethods def default_for_procedure(procedure) - body = ActionController::Base.new.render_to_string(template: const_get(:DEFAULT_TEMPLATE_NAME)) + template_name = default_template_name_for_procedure(procedure) + body = ActionController::Base.new.render_to_string(template: template_name) new(subject: const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure) end + + def default_template_name_for_procedure(procedure) + const_get(:DEFAULT_TEMPLATE_NAME) + end end def dossier_tags From 3e56b6fe9b99cf815e910d4bd0bcb6653b2998e9 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 16 Mar 2018 19:39:48 +0100 Subject: [PATCH 11/11] [#1563] Include attestation link in default closed mail when it makes sense --- app/models/mails/closed_mail.rb | 10 ++++++- .../closed_mail_with_attestation.html.haml | 22 ++++++++++++++++ spec/models/procedure_spec.rb | 26 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 app/views/mails/closed_mail_with_attestation.html.haml diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index 8dae9d9ee..757593a3a 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -5,9 +5,17 @@ module Mails belongs_to :procedure SLUG = "closed_mail" - DEFAULT_TEMPLATE_NAME = "mails/closed_mail" DISPLAYED_NAME = "Accusé d'acceptation" DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a été accepté' DOSSIER_STATE = 'accepte' + + def self.default_template_name_for_procedure(procedure) + attestation_template = procedure.attestation_template + if attestation_template.present? && attestation_template.activated? + "mails/closed_mail_with_attestation" + else + "mails/closed_mail" + end + end end end diff --git a/app/views/mails/closed_mail_with_attestation.html.haml b/app/views/mails/closed_mail_with_attestation.html.haml new file mode 100644 index 000000000..069fb6e77 --- /dev/null +++ b/app/views/mails/closed_mail_with_attestation.html.haml @@ -0,0 +1,22 @@ +Bonjour, +%br +%br +Votre dossier nº --numéro du dossier-- a été accepté le --date de décision--. +%br +%br +Vous pouvez télécharger votre attestation à l'adresse suivante : --lien attestation-- +%br +%br +A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien dossier-- +%br +%br +Bonne journée, +%br +%br +L'équipe demarches-simplifiees.fr (anciennement Téléprocédures Simplifiées) +%br +%br +— +%br +%br +Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 5dfb915b0..f513f0244 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -41,6 +41,32 @@ describe Procedure do end end + describe 'closed mail template body' do + let(:procedure) { create(:procedure) } + + subject { procedure.closed_mail_template.body } + + context 'for procedures without an attestation' do + it { is_expected.not_to include('lien attestation') } + end + + context 'for procedures with an attestation' do + before { create(:attestation_template, procedure: procedure, activated: activated) } + + context 'when the attestation is inactive' do + let(:activated) { false } + + it { is_expected.not_to include('lien attestation') } + end + + context 'when the attestation is inactive' do + let(:activated) { true } + + it { is_expected.to include('lien attestation') } + end + end + end + describe 'validation' do context 'libelle' do it { is_expected.not_to allow_value(nil).for(:libelle) }