MailTemplateController: use new initiated_mail
This commit is contained in:
parent
c22c84f1f9
commit
89763ec8d4
4 changed files with 38 additions and 34 deletions
|
@ -2,23 +2,34 @@ class Admin::MailTemplatesController < AdminController
|
||||||
before_action :retrieve_procedure
|
before_action :retrieve_procedure
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@mail_templates = @procedure.mail_templates
|
@mails = mails
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@mail_template = @procedure.mail_templates.find(params[:id])
|
@mail_template = find_the_right_mail params[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
mail_template = @procedure.mail_templates.find(params[:id])
|
mail_template = find_the_right_mail params[:id]
|
||||||
mail_template.update_attributes(update_params)
|
mail_template.update_attributes(update_params)
|
||||||
|
|
||||||
redirect_to admin_procedure_mail_templates_path
|
redirect_to admin_procedure_mail_templates_path
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def mails
|
||||||
|
[@procedure.initiated_mail]
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_the_right_mail type
|
||||||
|
mails.find { |m| m.class.slug == type }
|
||||||
|
end
|
||||||
|
|
||||||
def update_params
|
def update_params
|
||||||
params.require(:mail_template).permit(:body, :object)
|
{
|
||||||
|
procedure_id: params[:procedure_id],
|
||||||
|
object: params[:mail_template][:object],
|
||||||
|
body: params[:mail_template][:body],
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
%h3
|
%h3
|
||||||
= @mail_template.name
|
= @mail_template.name
|
||||||
|
|
||||||
= simple_form_for @mail_template.becomes(MailTemplate), url: admin_procedure_mail_template_path(@procedure, @mail_template) do |f|
|
= simple_form_for @mail_template.becomes(MailTemplate),
|
||||||
|
url: admin_procedure_mail_template_path(@procedure, @mail_template.class.slug),
|
||||||
|
method: :put do |f|
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
= f.input :object, label: "Objet de l'email"
|
= f.input :object, label: "Objet de l'email"
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
%tr
|
%tr
|
||||||
%th{ colspan: 2 }
|
%th{ colspan: 2 }
|
||||||
Type d'email
|
Type d'email
|
||||||
- @procedure.mail_templates.each do |mt|
|
- @mails.each do |mail|
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
= mt.name
|
= mail.name
|
||||||
%td.text-right
|
%td.text-right
|
||||||
= link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mt)
|
= link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mail.class.slug)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Admin::MailTemplatesController, type: :controller do
|
describe Admin::MailTemplatesController, type: :controller do
|
||||||
let(:mail_template) { create :mail_template, :dossier_received }
|
let(:initiated_mail) { InitiatedMail.default }
|
||||||
let(:procedure) { create :procedure, mail_templates: [mail_template]}
|
let(:procedure) { create :procedure }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in procedure.administrateur
|
sign_in procedure.administrateur
|
||||||
|
@ -11,41 +11,32 @@ describe Admin::MailTemplatesController, type: :controller do
|
||||||
describe 'GET index' do
|
describe 'GET index' do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
subject { get :index, params: {procedure_id: procedure.id} }
|
subject { get :index, params: { procedure_id: procedure.id } }
|
||||||
|
|
||||||
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(*procedure.mail_templates.map{ |mt| mt.decorate.name }) }
|
it { expect(subject.body).to include(initiated_mail.name ) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PATCH update' do
|
describe 'PATCH update' do
|
||||||
let(:object) { 'plop modif' }
|
let(:object) { 'plop modif' }
|
||||||
let(:body) { 'plip modif' }
|
let(:body) { 'plip modif' }
|
||||||
|
|
||||||
context 'when is mail_template id' do
|
before :each do
|
||||||
subject { patch :update,
|
patch :update,
|
||||||
params: {procedure_id: mail_template.procedure.id,
|
params: { procedure_id: procedure.id,
|
||||||
id: mail_template.id,
|
id: initiated_mail.class.slug,
|
||||||
mail_template: {
|
mail_template: { object: object, body: body }
|
||||||
object: object,
|
|
||||||
body: body
|
|
||||||
}} }
|
|
||||||
|
|
||||||
it { expect(subject).to redirect_to admin_procedure_mail_templates_path(mail_template.procedure) }
|
|
||||||
|
|
||||||
it {
|
|
||||||
expect {
|
|
||||||
subject
|
|
||||||
mail_template.reload
|
|
||||||
}.to change(mail_template, :object).from("[TPS] Accusé de réception pour votre dossier n°--numero_dossier--").to(object)
|
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
it {
|
it { expect(response).to redirect_to admin_procedure_mail_templates_path(procedure) }
|
||||||
expect {
|
|
||||||
subject
|
context 'the mail template' do
|
||||||
mail_template.reload
|
subject { procedure.reload ; procedure.initiated_mail }
|
||||||
}.to change(mail_template, :body).from("Votre administration vous confirme la bonne réception de votre dossier n°--numero_dossier--").to(body)
|
|
||||||
}
|
it { expect(subject.object).to eq(object) }
|
||||||
|
it { expect(subject.body).to eq(body) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue