Mail Template: Delete

This commit is contained in:
Simon Lehericey 2017-03-06 16:52:07 +01:00
parent 2536774519
commit 335caed65e
4 changed files with 5 additions and 84 deletions

View file

@ -1,58 +0,0 @@
class MailTemplate < ActiveRecord::Base
include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper
belongs_to :procedure
TAGS = {
numero_dossier: {
description: "Permet d'afficher le numéro de dossier de l'utilisateur."
},
lien_dossier: {
description: "Permet d'afficher un lien vers le dossier de l'utilisateur."
},
libelle_procedure: {
description: "Permet d'afficher le libellé de la procédure."
},
email: {
description: "Permet d'afficher l'email du porteur de projet."
},
nom_organisation: {
description: "Permet d'afficher le nom de l'organisation."
}
}
def object_for_dossier dossier
replace_tags(object, dossier)
end
def body_for_dossier dossier
replace_tags(body, dossier)
end
def replace_tags string, dossier
TAGS.inject(string) do |acc, tag|
acc.gsub!("--#{tag.first}--", replace_tag(tag.first.to_sym, dossier)) || acc
end
end
private
def replace_tag tag, dossier
case tag
when :email
dossier.user.email.to_s
when :nom_organisation
dossier.procedure.organisation.to_s
when :numero_dossier
dossier.id.to_s
when :lien_dossier
# TPS::Application::URL # quickfix
link_to users_dossier_recapitulatif_url(dossier), users_dossier_recapitulatif_url(dossier), target: '_blank'
when :libelle_procedure
dossier.procedure.libelle
else
'--BALISE_NON_RECONNUE--'
end
end
end

View file

@ -2,7 +2,8 @@
%h3
= @mail_template.name
= simple_form_for @mail_template.becomes(MailTemplate),
= simple_form_for @mail_template,
as: 'mail_template',
url: admin_procedure_mail_template_path(@procedure, @mail_template.class.slug),
method: :put do |f|
.row
@ -21,7 +22,7 @@
Balise
%th
Description
- MailTemplate::TAGS.each do |balise|
- MailTemplateConcern::TAGS.each do |balise|
%tr
%td.center
= "--#{balise.first}--"

View file

@ -1,5 +1,6 @@
class DeleteAllMailValidatedInDb < ActiveRecord::Migration[5.0]
def change
MailTemplate.where(type: "MailValidated").delete_all
mail_template_exist = Object.const_get(:MailTemplate).is_a?(Class) rescue false
MailTemplate.where(type: "MailValidated").delete_all if mail_template_exist
end
end

View file

@ -1,23 +0,0 @@
require 'spec_helper'
describe MailTemplate do
it { is_expected.to have_db_column(:body) }
it { is_expected.to have_db_column(:type) }
it { is_expected.to belong_to(:procedure) }
describe '.replace_tags' do
let(:dossier) { create :dossier }
let(:initiated_mail) { InitiatedMail.default }
it 'works' do
initiated_mail.object = '[TPS] --numero_dossier-- --libelle_procedure-- --lien_dossier-- --email-- --nom_organisation--'
expected =
"[TPS] 1 Demande de subvention " +
"<a target=\"_blank\" href=\"http://localhost:3000/users/dossiers/1/recapitulatif\">http://localhost:3000/users/dossiers/1/recapitulatif</a> " +
"#{dossier.user.email} Orga SGMAP"
expect(initiated_mail.object_for_dossier(dossier)).to eq(expected)
end
end
end