Make MailTemplateConcern.slug a constant

This commit is contained in:
gregoirenovel 2017-05-27 00:52:32 +02:00
parent 18d6204980
commit 07ea0ceea1
10 changed files with 9 additions and 8 deletions

View file

@ -29,7 +29,7 @@ class Admin::MailTemplatesController < AdminController
end
def find_mail_template_by_slug(slug)
mails.find { |m| m.class.slug == slug }
mails.find { |m| m.class.const_get(:SLUG) == slug }
end
def update_params

View file

@ -37,10 +37,6 @@ module MailTemplateConcern
end
module ClassMethods
def slug
self.name.demodulize.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)

View file

@ -2,6 +2,7 @@ module Mails
class ClosedMail < ApplicationRecord
include MailTemplateConcern
SLUG = "closed_mail"
DISPLAYED_NAME = "Accusé d'acceptation"
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été accepté'
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION]

View file

@ -2,6 +2,7 @@ module Mails
class InitiatedMail < ApplicationRecord
include MailTemplateConcern
SLUG = "initiated_mail"
DISPLAYED_NAME = 'Accusé de réception'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été bien reçu'
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE]

View file

@ -2,6 +2,7 @@ module Mails
class ReceivedMail < ApplicationRecord
include MailTemplateConcern
SLUG = "received_mail"
DISPLAYED_NAME = 'Accusé de passage en instruction'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- va être instruit'
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE]

View file

@ -2,6 +2,7 @@ module Mails
class RefusedMail < ApplicationRecord
include MailTemplateConcern
SLUG = "refused_mail"
DISPLAYED_NAME = 'Accusé de rejet du dossier'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été refusé'
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION]

View file

@ -2,6 +2,7 @@ module Mails
class WithoutContinuationMail < ApplicationRecord
include MailTemplateConcern
SLUG = "without_continuation"
DISPLAYED_NAME = 'Accusé de classement sans suite'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été classé sans suite'
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION]

View file

@ -4,7 +4,7 @@
= simple_form_for @mail_template,
as: 'mail_template',
url: admin_procedure_mail_template_path(@procedure, @mail_template.class.slug),
url: admin_procedure_mail_template_path(@procedure, @mail_template.class.const_get(:SLUG)),
method: :put do |f|
.row
.col-md-6

View file

@ -10,4 +10,4 @@
%td
= 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)
= link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mail.class.const_get(:SLUG))

View file

@ -25,7 +25,7 @@ describe Admin::MailTemplatesController, type: :controller do
before :each do
patch :update,
params: { procedure_id: procedure.id,
id: initiated_mail.class.slug,
id: initiated_mail.class.const_get(:SLUG),
mail_template: { object: object, body: body }
}
end