Merge pull request #1201 from sgmap/fix_1186-rename_object_to_subject

[Fix #1186] Rename object to subject for mail templates
This commit is contained in:
gregoirenovel 2018-01-09 16:14:15 +01:00 committed by GitHub
commit 8d6d8026a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 45 additions and 36 deletions

View file

@ -34,7 +34,7 @@ class Admin::MailTemplatesController < AdminController
def update_params
{
procedure_id: params[:procedure_id],
object: params[:mail_template][:object],
subject: params[:mail_template][:subject],
body: params[:mail_template][:body],
}
end

View file

@ -11,22 +11,22 @@ class NotificationMailer < ApplicationMailer
def send_notification(dossier, mail_template, attestation = nil)
vars_mailer(dossier)
@object = mail_template.object_for_dossier dossier
@subject = mail_template.subject_for_dossier dossier
@body = mail_template.body_for_dossier dossier
if attestation.present?
attachments['attestation.pdf'] = attestation
end
mail(subject: @object) { |format| format.html { @body } }
mail(subject: @subject) { |format| format.html { @body } }
end
def send_draft_notification(dossier)
vars_mailer(dossier)
@object = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}"
@subject = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}"
mail(subject: @object)
mail(subject: @subject)
end
def new_answer(dossier)
@ -39,7 +39,7 @@ class NotificationMailer < ApplicationMailer
Commentaire.create(
dossier: @dossier,
email: I18n.t("dynamics.contact_email"),
body: ["[#{@object}]", @body].join("<br><br>")
body: ["[#{@subject}]", @body].join("<br><br>")
)
end

View file

@ -5,8 +5,8 @@ module MailTemplateConcern
include ActionView::Helpers::UrlHelper
include TagsSubstitutionConcern
def object_for_dossier(dossier)
replace_tags(object, dossier)
def subject_for_dossier(dossier)
replace_tags(subject, dossier)
end
def body_for_dossier(dossier)
@ -20,7 +20,7 @@ module MailTemplateConcern
module ClassMethods
def default_for_procedure(procedure)
body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME))
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body, procedure: procedure)
self.new(subject: self.const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure)
end
end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "closed_mail"
TEMPLATE_NAME = "mails/closed_mail"
DISPLAYED_NAME = "Accusé d'acceptation"
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été accepté'
DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été accepté'
IS_DOSSIER_TERMINE = true
end
end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "initiated_mail"
TEMPLATE_NAME = "mails/initiated_mail"
DISPLAYED_NAME = 'Accusé de réception'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- a bien été reçu'
DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- a bien été reçu'
IS_DOSSIER_TERMINE = false
end
end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "received_mail"
TEMPLATE_NAME = "mails/received_mail"
DISPLAYED_NAME = 'Accusé de passage en instruction'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- va être instruit'
DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- va être instruit'
IS_DOSSIER_TERMINE = false
end
end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "refused_mail"
TEMPLATE_NAME = "mails/refused_mail"
DISPLAYED_NAME = 'Accusé de rejet du dossier'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été refusé'
DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été refusé'
IS_DOSSIER_TERMINE = true
end
end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "without_continuation"
TEMPLATE_NAME = "mails/without_continuation_mail"
DISPLAYED_NAME = 'Accusé de classement sans suite'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été classé sans suite'
DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été classé sans suite'
IS_DOSSIER_TERMINE = true
end
end

View file

@ -8,7 +8,7 @@
method: :put do |f|
.row
.col-md-6
= f.input :object, label: "Objet de l'email"
= f.input :subject, label: "Objet de l'email"
= f.input :body, label: "Corps de l'email", input_html: { class: 'wysihtml5' }
.text-right
= link_to "Annuler", admin_procedure_mail_templates_path(@procedure), class: "btn btn-default"

View file

@ -0,0 +1,9 @@
class RenameObjectToSubjectInMails < ActiveRecord::Migration[5.0]
def change
rename_column :closed_mails, :object, :subject
rename_column :initiated_mails, :object, :subject
rename_column :received_mails, :object, :subject
rename_column :refused_mails, :object, :subject
rename_column :without_continuation_mails, :object, :subject
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180108144114) do
ActiveRecord::Schema.define(version: 20180108152958) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -149,7 +149,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
create_table "closed_mails", force: :cascade do |t|
t.text "body"
t.string "object"
t.string "subject"
t.integer "procedure_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@ -307,7 +307,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
end
create_table "initiated_mails", force: :cascade do |t|
t.string "object"
t.string "subject"
t.text "body"
t.integer "procedure_id"
t.datetime "created_at", null: false
@ -430,7 +430,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
create_table "received_mails", force: :cascade do |t|
t.text "body"
t.string "object"
t.string "subject"
t.integer "procedure_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@ -439,7 +439,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
create_table "refused_mails", force: :cascade do |t|
t.text "body"
t.string "object"
t.string "subject"
t.integer "procedure_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@ -500,7 +500,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
create_table "without_continuation_mails", force: :cascade do |t|
t.text "body"
t.string "object"
t.string "subject"
t.integer "procedure_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false

View file

@ -19,14 +19,14 @@ describe Admin::MailTemplatesController, type: :controller do
end
describe 'PATCH update' do
let(:object) { 'plop modif' }
let(:body) { 'plip modif' }
let(:mail_subject) { 'plop modif' }
let(:mail_body) { 'plip modif' }
before :each do
patch :update,
params: { procedure_id: procedure.id,
id: initiated_mail.class.const_get(:SLUG),
mail_template: { object: object, body: body }
mail_template: { subject: mail_subject, body: mail_body }
}
end
@ -35,8 +35,8 @@ describe Admin::MailTemplatesController, type: :controller do
context 'the mail template' do
subject { procedure.reload ; procedure.initiated_mail_template }
it { expect(subject.object).to eq(object) }
it { expect(subject.body).to eq(body) }
it { expect(subject.subject).to eq(mail_subject) }
it { expect(subject.body).to eq(mail_body) }
end
end
end

View file

@ -1,6 +1,6 @@
FactoryGirl.define do
factory :mail_template, class: Mails::ClosedMail do
object "Object, voila voila"
subject "Subject, voila voila"
body "Blabla ceci est mon body"
factory :dossier_submitted_mail_template, class: Mails::ReceivedMail
@ -8,7 +8,7 @@ FactoryGirl.define do
factory :dossier_refused_mail_template, class: Mails::RefusedMail
factory :dossier_en_instruction_mail_template, class: Mails::InitiatedMail do
object "[TPS] Accusé de réception pour votre dossier nº --numéro du dossier--"
subject "[TPS] Accusé de réception pour votre dossier nº --numéro du dossier--"
body "Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--"
end
end

View file

@ -1,6 +1,6 @@
FactoryGirl.define do
factory :received_mail, class: Mails::ReceivedMail do
object "Mail d'accusé de bonne reception de votre dossier"
subject "Mail d'accusé de bonne reception de votre dossier"
body "Votre dossier est correctement reçu"
end
end

View file

@ -8,7 +8,7 @@ RSpec.describe NotificationMailer, type: :mailer do
subject.deliver_now
commentaire = Commentaire.last
expect(commentaire.body).to include(email_template.object_for_dossier(dossier), email_template.body_for_dossier(dossier))
expect(commentaire.body).to include(email_template.subject_for_dossier(dossier), email_template.body_for_dossier(dossier))
expect(commentaire.dossier).to eq(dossier)
end
end
@ -17,13 +17,13 @@ RSpec.describe NotificationMailer, type: :mailer do
let(:dossier) { create(:dossier, user: user) }
describe '.send_notification' do
let(:email_template) { instance_double('email_template', object_for_dossier: 'object', body_for_dossier: 'body') }
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }
let(:attestation) { nil }
let(:notifications_count_before) { Notification.count }
subject { described_class.send_notification(dossier, email_template, attestation) }
it { expect(subject.subject).to eq(email_template.object_for_dossier) }
it { expect(subject.subject).to eq(email_template.subject_for_dossier) }
it { expect(subject.body).to eq(email_template.body_for_dossier) }
it { expect(subject.attachments['attestation.pdf']).to eq(nil) }
@ -50,7 +50,7 @@ RSpec.describe NotificationMailer, type: :mailer do
end
it do
expect(subject.subject).to eq(email_template.object)
expect(subject.subject).to eq(email_template.subject)
expect(subject.body).to eq(email_template.body)
end

View file

@ -33,9 +33,9 @@ describe MailTemplateConcern do
end
end
describe '.object_for_dossier' do
before { initiated_mail.object = template }
subject { initiated_mail.object_for_dossier(dossier) }
describe '.subject_for_dossier' do
before { initiated_mail.subject = template }
subject { initiated_mail.subject_for_dossier(dossier) }
it_behaves_like "can replace tokens in template"
end