From 07ea0ceea1283face289eadaa4a5033e7b60c0d3 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:52:32 +0200 Subject: [PATCH] Make MailTemplateConcern.slug a constant --- app/controllers/admin/mail_templates_controller.rb | 2 +- app/models/concerns/mail_template_concern.rb | 4 ---- app/models/mails/closed_mail.rb | 1 + app/models/mails/initiated_mail.rb | 1 + app/models/mails/received_mail.rb | 1 + app/models/mails/refused_mail.rb | 1 + app/models/mails/without_continuation_mail.rb | 1 + app/views/admin/mail_templates/edit.html.haml | 2 +- app/views/admin/mail_templates/index.html.haml | 2 +- spec/controllers/admin/mail_templates_controller_spec.rb | 2 +- 10 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb index 71136038e..76766c526 100644 --- a/app/controllers/admin/mail_templates_controller.rb +++ b/app/controllers/admin/mail_templates_controller.rb @@ -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 diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index 4ac7fe34f..1a2e179f1 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -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) diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index 410662a6d..4860dc4aa 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -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] diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index 8f7c67c84..05a59648d 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -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] diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index 69ac71a02..203aead0b 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -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] diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index ac0bb650b..459042812 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -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] diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb index ae44e9b24..4961ee055 100644 --- a/app/models/mails/without_continuation_mail.rb +++ b/app/models/mails/without_continuation_mail.rb @@ -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] diff --git a/app/views/admin/mail_templates/edit.html.haml b/app/views/admin/mail_templates/edit.html.haml index cac9b1e50..af010fb95 100644 --- a/app/views/admin/mail_templates/edit.html.haml +++ b/app/views/admin/mail_templates/edit.html.haml @@ -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 diff --git a/app/views/admin/mail_templates/index.html.haml b/app/views/admin/mail_templates/index.html.haml index b8eff250a..695f4e304 100644 --- a/app/views/admin/mail_templates/index.html.haml +++ b/app/views/admin/mail_templates/index.html.haml @@ -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)) diff --git a/spec/controllers/admin/mail_templates_controller_spec.rb b/spec/controllers/admin/mail_templates_controller_spec.rb index 31adfd4ee..6545d1b77 100644 --- a/spec/controllers/admin/mail_templates_controller_spec.rb +++ b/spec/controllers/admin/mail_templates_controller_spec.rb @@ -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