Make MailTemplateConcern.slug a constant
This commit is contained in:
parent
18d6204980
commit
07ea0ceea1
10 changed files with 9 additions and 8 deletions
|
@ -29,7 +29,7 @@ class Admin::MailTemplatesController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_mail_template_by_slug(slug)
|
def find_mail_template_by_slug(slug)
|
||||||
mails.find { |m| m.class.slug == slug }
|
mails.find { |m| m.class.const_get(:SLUG) == slug }
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_params
|
def update_params
|
||||||
|
|
|
@ -37,10 +37,6 @@ module MailTemplateConcern
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def slug
|
|
||||||
self.name.demodulize.underscore.parameterize
|
|
||||||
end
|
|
||||||
|
|
||||||
def default
|
def default
|
||||||
body = ActionController::Base.new.render_to_string(template: self.name.underscore)
|
body = ActionController::Base.new.render_to_string(template: self.name.underscore)
|
||||||
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body)
|
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body)
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Mails
|
||||||
class ClosedMail < ApplicationRecord
|
class ClosedMail < ApplicationRecord
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
|
SLUG = "closed_mail"
|
||||||
DISPLAYED_NAME = "Accusé d'acceptation"
|
DISPLAYED_NAME = "Accusé d'acceptation"
|
||||||
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été accepté'
|
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]
|
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION]
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Mails
|
||||||
class InitiatedMail < ApplicationRecord
|
class InitiatedMail < ApplicationRecord
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
|
SLUG = "initiated_mail"
|
||||||
DISPLAYED_NAME = 'Accusé de réception'
|
DISPLAYED_NAME = 'Accusé de réception'
|
||||||
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été bien reçu'
|
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été bien reçu'
|
||||||
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE]
|
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE]
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Mails
|
||||||
class ReceivedMail < ApplicationRecord
|
class ReceivedMail < ApplicationRecord
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
|
SLUG = "received_mail"
|
||||||
DISPLAYED_NAME = 'Accusé de passage en instruction'
|
DISPLAYED_NAME = 'Accusé de passage en instruction'
|
||||||
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- va être instruit'
|
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- va être instruit'
|
||||||
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE]
|
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE]
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Mails
|
||||||
class RefusedMail < ApplicationRecord
|
class RefusedMail < ApplicationRecord
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
|
SLUG = "refused_mail"
|
||||||
DISPLAYED_NAME = 'Accusé de rejet du dossier'
|
DISPLAYED_NAME = 'Accusé de rejet du dossier'
|
||||||
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été refusé'
|
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]
|
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION]
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Mails
|
||||||
class WithoutContinuationMail < ApplicationRecord
|
class WithoutContinuationMail < ApplicationRecord
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
|
SLUG = "without_continuation"
|
||||||
DISPLAYED_NAME = 'Accusé de classement sans suite'
|
DISPLAYED_NAME = 'Accusé de classement sans suite'
|
||||||
DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été classé 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]
|
ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION]
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
= simple_form_for @mail_template,
|
= simple_form_for @mail_template,
|
||||||
as: '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|
|
method: :put do |f|
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
|
|
|
@ -10,4 +10,4 @@
|
||||||
%td
|
%td
|
||||||
= mail.class.const_get(:DISPLAYED_NAME)
|
= mail.class.const_get(:DISPLAYED_NAME)
|
||||||
%td.text-right
|
%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))
|
||||||
|
|
|
@ -25,7 +25,7 @@ describe Admin::MailTemplatesController, type: :controller do
|
||||||
before :each do
|
before :each do
|
||||||
patch :update,
|
patch :update,
|
||||||
params: { procedure_id: procedure.id,
|
params: { procedure_id: procedure.id,
|
||||||
id: initiated_mail.class.slug,
|
id: initiated_mail.class.const_get(:SLUG),
|
||||||
mail_template: { object: object, body: body }
|
mail_template: { object: object, body: body }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue