Mails: factorize default and change slug

This commit is contained in:
Simon Lehericey 2017-03-06 23:18:16 +01:00
parent 02bbf0543f
commit 65e83dd6ec
14 changed files with 19 additions and 44 deletions

View file

@ -32,7 +32,12 @@ module MailTemplateConcern
module ClassMethods
def slug
self.name.underscore
self.name.underscore.parameterize
end
def default
body = ActionController::Base.new.render_to_string(template: self.name.underscore)
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body)
end
end

View file

@ -2,14 +2,8 @@ module Mails
class ClosedMail < ActiveRecord::Base
include MailTemplateConcern
def name
"Accusé d'acceptation"
end
DISPLAYED_NAME = "Accusé d'acceptation"
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été accepté'
def self.default
obj = "Votre dossier TPS N°--numero_dossier-- a été accepté"
body = ActionController::Base.new.render_to_string(template: 'notification_mailer/closed_mail')
ClosedMail.new(object: obj, body: body)
end
end
end

View file

@ -2,14 +2,8 @@ module Mails
class InitiatedMail < ActiveRecord::Base
include MailTemplateConcern
def name
"Accusé de réception"
end
DISPLAYED_NAME = 'Accusé de réception'
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été bien reçu'
def self.default
obj = "Votre dossier TPS N°--numero_dossier-- a été bien reçu"
body = ActionController::Base.new.render_to_string(template: 'notification_mailer/initiated_mail')
InitiatedMail.new(object: obj, body: body)
end
end
end

View file

@ -2,14 +2,8 @@ module Mails
class ReceivedMail < ActiveRecord::Base
include MailTemplateConcern
def name
"Accusé de passage en instruction"
end
DISPLAYED_NAME = 'Accusé de passage en instruction'
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- va être instruit'
def self.default
obj = "Votre dossier TPS N°--numero_dossier-- va être instruit"
body = ActionController::Base.new.render_to_string(template: 'notification_mailer/received_mail')
ReceivedMail.new(object: obj, body: body)
end
end
end

View file

@ -2,14 +2,8 @@ module Mails
class RefusedMail < ApplicationRecord
include MailTemplateConcern
def name
"Accusé de rejet du dossier"
end
DISPLAYED_NAME = 'Accusé de rejet du dossier'
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été refusé'
def self.default
obj = "Votre dossier TPS N°--numero_dossier-- a été refusé"
body = ActionController::Base.new.render_to_string(template: 'notification_mailer/refused_mail')
RefusedMail.new(object: obj, body: body)
end
end
end

View file

@ -2,14 +2,8 @@ module Mails
class WithoutContinuationMail < ApplicationRecord
include MailTemplateConcern
def name
"Accusé de classement sans suite"
end
DISPLAYED_NAME = 'Accusé de classement sans suite'
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été classé sans suite'
def self.default
obj = "Votre dossier TPS N°--numero_dossier-- a été classé sans suite"
body = ActionController::Base.new.render_to_string(template: 'notification_mailer/without_continuation_mail')
WithoutContinuationMail.new(object: obj, body: body)
end
end
end

View file

@ -1,6 +1,6 @@
.white-back
%h3
= @mail_template.name
= @mail_template.class.const_get(:DISPLAYED_NAME)
= simple_form_for @mail_template,
as: 'mail_template',

View file

@ -8,6 +8,6 @@
- @mails.each do |mail|
%tr
%td
= mail.name
= mail.class.const_get(:DISPLAYED_NAME)
%td.text-right
= link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mail.class.slug)

View file

@ -15,7 +15,7 @@ describe Admin::MailTemplatesController, type: :controller do
it { expect(subject.status).to eq 200 }
it { expect(subject.body).to include("E-mails personnalisables") }
it { expect(subject.body).to include(initiated_mail.name ) }
it { expect(subject.body).to include(Mails::InitiatedMail::DISPLAYED_NAME) }
end
describe 'PATCH update' do