Mails: factorize default and change slug
This commit is contained in:
parent
02bbf0543f
commit
65e83dd6ec
14 changed files with 19 additions and 44 deletions
|
@ -32,7 +32,12 @@ module MailTemplateConcern
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def slug
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,8 @@ module Mails
|
||||||
class ClosedMail < ActiveRecord::Base
|
class ClosedMail < ActiveRecord::Base
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
def name
|
DISPLAYED_NAME = "Accusé d'acceptation"
|
||||||
"Accusé d'acceptation"
|
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été accepté'
|
||||||
end
|
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,8 @@ module Mails
|
||||||
class InitiatedMail < ActiveRecord::Base
|
class InitiatedMail < ActiveRecord::Base
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
def name
|
DISPLAYED_NAME = 'Accusé de réception'
|
||||||
"Accusé de réception"
|
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été bien reçu'
|
||||||
end
|
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,8 @@ module Mails
|
||||||
class ReceivedMail < ActiveRecord::Base
|
class ReceivedMail < ActiveRecord::Base
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
def name
|
DISPLAYED_NAME = 'Accusé de passage en instruction'
|
||||||
"Accusé de passage en instruction"
|
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- va être instruit'
|
||||||
end
|
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,8 @@ module Mails
|
||||||
class RefusedMail < ApplicationRecord
|
class RefusedMail < ApplicationRecord
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
def name
|
DISPLAYED_NAME = 'Accusé de rejet du dossier'
|
||||||
"Accusé de rejet du dossier"
|
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été refusé'
|
||||||
end
|
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,8 @@ module Mails
|
||||||
class WithoutContinuationMail < ApplicationRecord
|
class WithoutContinuationMail < ApplicationRecord
|
||||||
include MailTemplateConcern
|
include MailTemplateConcern
|
||||||
|
|
||||||
def name
|
DISPLAYED_NAME = 'Accusé de classement sans suite'
|
||||||
"Accusé de classement sans suite"
|
DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été classé sans suite'
|
||||||
end
|
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
.white-back
|
.white-back
|
||||||
%h3
|
%h3
|
||||||
= @mail_template.name
|
= @mail_template.class.const_get(:DISPLAYED_NAME)
|
||||||
|
|
||||||
= simple_form_for @mail_template,
|
= simple_form_for @mail_template,
|
||||||
as: 'mail_template',
|
as: 'mail_template',
|
||||||
|
|
|
@ -8,6 +8,6 @@
|
||||||
- @mails.each do |mail|
|
- @mails.each do |mail|
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
= mail.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.slug)
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe Admin::MailTemplatesController, type: :controller do
|
||||||
|
|
||||||
it { expect(subject.status).to eq 200 }
|
it { expect(subject.status).to eq 200 }
|
||||||
it { expect(subject.body).to include("E-mails personnalisables") }
|
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
|
end
|
||||||
|
|
||||||
describe 'PATCH update' do
|
describe 'PATCH update' do
|
||||||
|
|
Loading…
Reference in a new issue