Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-01-09 16:59:31 +01:00
commit e7bcef8868
18 changed files with 52 additions and 47 deletions

View file

@ -93,7 +93,7 @@ client_secret: ''
AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later
WeeklyOverviewJob.set(cron: "0 8 * * 0").perform_later WeeklyOverviewJob.set(cron: "0 8 * * 0").perform_later
AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, "received") AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, "received")
FindDubiousProcedureJob.set(cron: "0 0 * * *").perform_later FindDubiousProceduresJob.set(cron: "0 0 * * *").perform_later
## Exécution des tests (RSpec) ## Exécution des tests (RSpec)

View file

@ -34,7 +34,7 @@ class Admin::MailTemplatesController < AdminController
def update_params def update_params
{ {
procedure_id: params[:procedure_id], procedure_id: params[:procedure_id],
object: params[:mail_template][:object], subject: params[:mail_template][:subject],
body: params[:mail_template][:body], body: params[:mail_template][:body],
} }
end end

View file

@ -11,22 +11,22 @@ class NotificationMailer < ApplicationMailer
def send_notification(dossier, mail_template, attestation = nil) def send_notification(dossier, mail_template, attestation = nil)
vars_mailer(dossier) vars_mailer(dossier)
@object = mail_template.object_for_dossier dossier @subject = mail_template.subject_for_dossier dossier
@body = mail_template.body_for_dossier dossier @body = mail_template.body_for_dossier dossier
if attestation.present? if attestation.present?
attachments['attestation.pdf'] = attestation attachments['attestation.pdf'] = attestation
end end
mail(subject: @object) { |format| format.html { @body } } mail(subject: @subject) { |format| format.html { @body } }
end end
def send_draft_notification(dossier) def send_draft_notification(dossier)
vars_mailer(dossier) vars_mailer(dossier)
@object = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}" @subject = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}"
mail(subject: @object) mail(subject: @subject)
end end
def new_answer(dossier) def new_answer(dossier)
@ -39,7 +39,7 @@ class NotificationMailer < ApplicationMailer
Commentaire.create( Commentaire.create(
dossier: @dossier, dossier: @dossier,
email: I18n.t("dynamics.contact_email"), email: I18n.t("dynamics.contact_email"),
body: ["[#{@object}]", @body].join("<br><br>") body: ["[#{@subject}]", @body].join("<br><br>")
) )
end end

View file

@ -5,8 +5,8 @@ module MailTemplateConcern
include ActionView::Helpers::UrlHelper include ActionView::Helpers::UrlHelper
include TagsSubstitutionConcern include TagsSubstitutionConcern
def object_for_dossier(dossier) def subject_for_dossier(dossier)
replace_tags(object, dossier) replace_tags(subject, dossier)
end end
def body_for_dossier(dossier) def body_for_dossier(dossier)
@ -20,7 +20,7 @@ module MailTemplateConcern
module ClassMethods module ClassMethods
def default_for_procedure(procedure) def default_for_procedure(procedure)
body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME)) body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME))
self.new(object: self.const_get(:DEFAULT_OBJECT), body: body, procedure: procedure) self.new(subject: self.const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure)
end end
end end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "closed_mail" SLUG = "closed_mail"
TEMPLATE_NAME = "mails/closed_mail" TEMPLATE_NAME = "mails/closed_mail"
DISPLAYED_NAME = "Accusé d'acceptation" DISPLAYED_NAME = "Accusé d'acceptation"
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été accepté' DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été accepté'
IS_DOSSIER_TERMINE = true IS_DOSSIER_TERMINE = true
end end
end end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "initiated_mail" SLUG = "initiated_mail"
TEMPLATE_NAME = "mails/initiated_mail" TEMPLATE_NAME = "mails/initiated_mail"
DISPLAYED_NAME = 'Accusé de réception' DISPLAYED_NAME = 'Accusé de réception'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- a bien été reçu' DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- a bien été reçu'
IS_DOSSIER_TERMINE = false IS_DOSSIER_TERMINE = false
end end
end end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "received_mail" SLUG = "received_mail"
TEMPLATE_NAME = "mails/received_mail" TEMPLATE_NAME = "mails/received_mail"
DISPLAYED_NAME = 'Accusé de passage en instruction' DISPLAYED_NAME = 'Accusé de passage en instruction'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- va être instruit' DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- va être instruit'
IS_DOSSIER_TERMINE = false IS_DOSSIER_TERMINE = false
end end
end end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "refused_mail" SLUG = "refused_mail"
TEMPLATE_NAME = "mails/refused_mail" TEMPLATE_NAME = "mails/refused_mail"
DISPLAYED_NAME = 'Accusé de rejet du dossier' DISPLAYED_NAME = 'Accusé de rejet du dossier'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été refusé' DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été refusé'
IS_DOSSIER_TERMINE = true IS_DOSSIER_TERMINE = true
end end
end end

View file

@ -7,7 +7,7 @@ module Mails
SLUG = "without_continuation" SLUG = "without_continuation"
TEMPLATE_NAME = "mails/without_continuation_mail" TEMPLATE_NAME = "mails/without_continuation_mail"
DISPLAYED_NAME = 'Accusé de classement sans suite' DISPLAYED_NAME = 'Accusé de classement sans suite'
DEFAULT_OBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été classé sans suite' DEFAULT_SUBJECT = 'Votre dossier TPS nº --numéro du dossier-- a été classé sans suite'
IS_DOSSIER_TERMINE = true IS_DOSSIER_TERMINE = true
end end
end end

View file

@ -8,7 +8,7 @@
method: :put do |f| method: :put do |f|
.row .row
.col-md-6 .col-md-6
= f.input :object, label: "Objet de l'email" = f.input :subject, label: "Objet de l'email"
= f.input :body, label: "Corps de l'email", input_html: { class: 'wysihtml5' } = f.input :body, label: "Corps de l'email", input_html: { class: 'wysihtml5' }
.text-right .text-right
= link_to "Annuler", admin_procedure_mail_templates_path(@procedure), class: "btn btn-default" = link_to "Annuler", admin_procedure_mail_templates_path(@procedure), class: "btn btn-default"

View file

@ -0,0 +1,9 @@
class RenameObjectToSubjectInMails < ActiveRecord::Migration[5.0]
def change
rename_column :closed_mails, :object, :subject
rename_column :initiated_mails, :object, :subject
rename_column :received_mails, :object, :subject
rename_column :refused_mails, :object, :subject
rename_column :without_continuation_mails, :object, :subject
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180108144114) do ActiveRecord::Schema.define(version: 20180108152958) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -149,7 +149,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
create_table "closed_mails", force: :cascade do |t| create_table "closed_mails", force: :cascade do |t|
t.text "body" t.text "body"
t.string "object" t.string "subject"
t.integer "procedure_id" t.integer "procedure_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
@ -307,7 +307,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
end end
create_table "initiated_mails", force: :cascade do |t| create_table "initiated_mails", force: :cascade do |t|
t.string "object" t.string "subject"
t.text "body" t.text "body"
t.integer "procedure_id" t.integer "procedure_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
@ -430,7 +430,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
create_table "received_mails", force: :cascade do |t| create_table "received_mails", force: :cascade do |t|
t.text "body" t.text "body"
t.string "object" t.string "subject"
t.integer "procedure_id" t.integer "procedure_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
@ -439,7 +439,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
create_table "refused_mails", force: :cascade do |t| create_table "refused_mails", force: :cascade do |t|
t.text "body" t.text "body"
t.string "object" t.string "subject"
t.integer "procedure_id" t.integer "procedure_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
@ -500,7 +500,7 @@ ActiveRecord::Schema.define(version: 20180108144114) do
create_table "without_continuation_mails", force: :cascade do |t| create_table "without_continuation_mails", force: :cascade do |t|
t.text "body" t.text "body"
t.string "object" t.string "subject"
t.integer "procedure_id" t.integer "procedure_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false

View file

@ -19,14 +19,14 @@ describe Admin::MailTemplatesController, type: :controller do
end end
describe 'PATCH update' do describe 'PATCH update' do
let(:object) { 'plop modif' } let(:mail_subject) { 'plop modif' }
let(:body) { 'plip modif' } let(:mail_body) { 'plip modif' }
before :each do before :each do
patch :update, patch :update,
params: { procedure_id: procedure.id, params: { procedure_id: procedure.id,
id: initiated_mail.class.const_get(:SLUG), id: initiated_mail.class.const_get(:SLUG),
mail_template: { object: object, body: body } mail_template: { subject: mail_subject, body: mail_body }
} }
end end
@ -35,8 +35,8 @@ describe Admin::MailTemplatesController, type: :controller do
context 'the mail template' do context 'the mail template' do
subject { procedure.reload ; procedure.initiated_mail_template } subject { procedure.reload ; procedure.initiated_mail_template }
it { expect(subject.object).to eq(object) } it { expect(subject.subject).to eq(mail_subject) }
it { expect(subject.body).to eq(body) } it { expect(subject.body).to eq(mail_body) }
end end
end end
end end

View file

@ -1,14 +1,16 @@
FactoryGirl.define do FactoryGirl.define do
factory :mail_template, class: Mails::ClosedMail do factory :closed_mail, class: Mails::ClosedMail do
object "Object, voila voila" subject "Subject, voila voila"
body "Blabla ceci est mon body" body "Blabla ceci est mon body"
factory :dossier_submitted_mail_template, class: Mails::ReceivedMail factory :received_mail, class: Mails::ReceivedMail
factory :dossier_refused_mail_template, class: Mails::RefusedMail factory :refused_mail, class: Mails::RefusedMail
factory :dossier_en_instruction_mail_template, class: Mails::InitiatedMail do factory :without_continuation_mail, class: Mails::WithoutContinuationMail
object "[TPS] Accusé de réception pour votre dossier nº --numéro du dossier--"
factory :initiated_mail, class: Mails::InitiatedMail do
subject "[TPS] Accusé de réception pour votre dossier nº --numéro du dossier--"
body "Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--" body "Votre administration vous confirme la bonne réception de votre dossier nº --numéro du dossier--"
end end
end end

View file

@ -1,6 +0,0 @@
FactoryGirl.define do
factory :received_mail, class: Mails::ReceivedMail do
object "Mail d'accusé de bonne reception de votre dossier"
body "Votre dossier est correctement reçu"
end
end

View file

@ -8,7 +8,7 @@ RSpec.describe NotificationMailer, type: :mailer do
subject.deliver_now subject.deliver_now
commentaire = Commentaire.last commentaire = Commentaire.last
expect(commentaire.body).to include(email_template.object_for_dossier(dossier), email_template.body_for_dossier(dossier)) expect(commentaire.body).to include(email_template.subject_for_dossier(dossier), email_template.body_for_dossier(dossier))
expect(commentaire.dossier).to eq(dossier) expect(commentaire.dossier).to eq(dossier)
end end
end end
@ -17,13 +17,13 @@ RSpec.describe NotificationMailer, type: :mailer do
let(:dossier) { create(:dossier, user: user) } let(:dossier) { create(:dossier, user: user) }
describe '.send_notification' do describe '.send_notification' do
let(:email_template) { instance_double('email_template', object_for_dossier: 'object', body_for_dossier: 'body') } let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }
let(:attestation) { nil } let(:attestation) { nil }
let(:notifications_count_before) { Notification.count } let(:notifications_count_before) { Notification.count }
subject { described_class.send_notification(dossier, email_template, attestation) } subject { described_class.send_notification(dossier, email_template, attestation) }
it { expect(subject.subject).to eq(email_template.object_for_dossier) } it { expect(subject.subject).to eq(email_template.subject_for_dossier) }
it { expect(subject.body).to eq(email_template.body_for_dossier) } it { expect(subject.body).to eq(email_template.body_for_dossier) }
it { expect(subject.attachments['attestation.pdf']).to eq(nil) } it { expect(subject.attachments['attestation.pdf']).to eq(nil) }
@ -50,7 +50,7 @@ RSpec.describe NotificationMailer, type: :mailer do
end end
it do it do
expect(subject.subject).to eq(email_template.object) expect(subject.subject).to eq(email_template.subject)
expect(subject.body).to eq(email_template.body) expect(subject.body).to eq(email_template.body)
end end

View file

@ -33,9 +33,9 @@ describe MailTemplateConcern do
end end
end end
describe '.object_for_dossier' do describe '.subject_for_dossier' do
before { initiated_mail.object = template } before { initiated_mail.subject = template }
subject { initiated_mail.object_for_dossier(dossier) } subject { initiated_mail.subject_for_dossier(dossier) }
it_behaves_like "can replace tokens in template" it_behaves_like "can replace tokens in template"
end end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe 'admin/mail_templates/edit.html.haml', type: :view do describe 'admin/mail_templates/edit.html.haml', type: :view do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:mail_template) { create(:mail_template, procedure: procedure) } let(:mail_template) { create(:received_mail, procedure: procedure) }
let(:all_tags) { mail_template.tags } let(:all_tags) { mail_template.tags }
before do before do