2017-01-24 14:36:43 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Admin::MailTemplatesController, type: :controller do
|
|
|
|
let(:mail_template) { create :mail_template, :dossier_received }
|
|
|
|
let(:procedure) { create :procedure, mail_templates: [mail_template]}
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in procedure.administrateur
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET index' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
subject { get :index, params: {procedure_id: procedure.id} }
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 200 }
|
|
|
|
it { expect(subject.body).to include("E-mails personnalisables") }
|
|
|
|
it { expect(subject.body).to include(*procedure.mail_templates.map{ |mt| mt.decorate.name }) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH update' do
|
|
|
|
let(:object) { 'plop modif' }
|
|
|
|
let(:body) { 'plip modif' }
|
|
|
|
|
2017-01-26 12:12:52 +01:00
|
|
|
context 'when is mail_template id' do
|
2017-01-24 14:36:43 +01:00
|
|
|
subject { patch :update,
|
|
|
|
params: {procedure_id: mail_template.procedure.id,
|
|
|
|
id: mail_template.id,
|
2017-01-26 12:12:52 +01:00
|
|
|
mail_template: {
|
2017-01-24 14:36:43 +01:00
|
|
|
object: object,
|
|
|
|
body: body
|
|
|
|
}} }
|
|
|
|
|
2017-01-26 12:12:52 +01:00
|
|
|
it { expect(subject).to redirect_to admin_procedure_mail_templates_path(mail_template.procedure) }
|
2017-01-24 14:36:43 +01:00
|
|
|
|
|
|
|
it {
|
|
|
|
expect {
|
|
|
|
subject
|
|
|
|
mail_template.reload
|
2017-01-24 17:14:51 +01:00
|
|
|
}.to change(mail_template, :object).from("[TPS] Accusé de réception pour votre dossier n°--numero_dossier--").to(object)
|
2017-01-24 14:36:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
it {
|
|
|
|
expect {
|
|
|
|
subject
|
|
|
|
mail_template.reload
|
2017-01-24 17:14:51 +01:00
|
|
|
}.to change(mail_template, :body).from("Votre administration vous confirme la bonne réception de votre dossier n°--numero_dossier--").to(body)
|
2017-01-24 14:36:43 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|