diff --git a/Gemfile b/Gemfile
index 080855505..a389a030a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -110,7 +110,7 @@ group :test do
gem 'poltergeist'
gem 'timecop'
gem 'guard'
- # gem 'guard-rspec', require: false
+ gem 'guard-rspec', require: false
gem 'guard-livereload', '~> 2.4', require: false
gem 'vcr'
gem 'rails-controller-testing'
@@ -134,8 +134,8 @@ group :development, :test do
gem 'pry-byebug'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
- # gem 'spring'
- # gem 'spring-commands-rspec'
+ gem 'spring'
+ gem 'spring-commands-rspec'
gem 'rspec-rails', '~> 3.0'
gem 'railroady'
diff --git a/Gemfile.lock b/Gemfile.lock
index ffe16811d..aa235f499 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -295,6 +295,10 @@ GEM
guard (~> 2.8)
guard-compat (~> 1.0)
multi_json (~> 1.8)
+ guard-rspec (4.7.3)
+ guard (~> 2.1)
+ guard-compat (~> 1.1)
+ rspec (>= 2.99.0, < 4.0)
haml (4.0.7)
tilt
haml-rails (0.9.0)
@@ -483,6 +487,10 @@ GEM
activesupport (>= 3.0, < 6.0)
builder (~> 3.0)
rubyzip (~> 1.0)
+ rspec (3.5.0)
+ rspec-core (~> 3.5.0)
+ rspec-expectations (~> 3.5.0)
+ rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
@@ -557,6 +565,10 @@ GEM
spreadsheet_architect (1.4.8)
axlsx (>= 2.0)
rodf (= 0.3.7)
+ spring (2.0.1)
+ activesupport (>= 4.2)
+ spring-commands-rspec (1.0.4)
+ spring (>= 0.9.1)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
@@ -657,6 +669,7 @@ DEPENDENCIES
font-awesome-rails
guard
guard-livereload (~> 2.4)
+ guard-rspec
haml-rails
hashie
jbuilder (~> 2.0)
@@ -696,6 +709,8 @@ DEPENDENCIES
simplecov
smart_listing
spreadsheet_architect
+ spring
+ spring-commands-rspec
sqlite3
therubyracer
timecop
diff --git a/Guardfile b/Guardfile
index a937e06b8..22f0a831c 100644
--- a/Guardfile
+++ b/Guardfile
@@ -64,24 +64,24 @@ guard 'livereload' do
watch(%r{config/locales/.+\.yml})
end
-# guard :rspec, cmd: 'bin/rspec' do
-# watch(%r{^spec/.+_spec\.rb$})
-# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
-# watch('spec/spec_helper.rb') { "spec" }
-#
-# # Rails example
-# watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
-# watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
-# watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
-# watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
-# watch('config/routes.rb') { "spec/routing" }
-# watch('app/controllers/application_controller.rb') { "spec/controllers" }
-# watch('spec/rails_helper.rb') { "spec" }
-#
-# # Capybara features specs
-# watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
-#
-# # Turnip features and steps
-# watch(%r{^spec/acceptance/(.+)\.feature$})
-# watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
-# end
+guard :rspec, cmd: 'spring rspec' do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ watch('spec/rails_helper.rb') { "spec" }
+
+ # Capybara features specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
+
+ # Turnip features and steps
+ watch(%r{^spec/acceptance/(.+)\.feature$})
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
+end
diff --git a/app/assets/stylesheets/custom-mails.scss b/app/assets/stylesheets/custom-mails.scss
new file mode 100644
index 000000000..6552f757f
--- /dev/null
+++ b/app/assets/stylesheets/custom-mails.scss
@@ -0,0 +1,11 @@
+#custom-mails {
+ padding: 20px;
+
+ .wrapper {
+ background-color: #FFF;
+ box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.5);
+ margin: 15px auto;
+ max-width: 800px;
+ padding: 20px;
+ }
+}
diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb
index 39f2b7955..7c94d4a0f 100644
--- a/app/controllers/admin/mail_templates_controller.rb
+++ b/app/controllers/admin/mail_templates_controller.rb
@@ -2,23 +2,35 @@ class Admin::MailTemplatesController < AdminController
before_action :retrieve_procedure
def index
- @mail_templates = @procedure.mail_templates
+ @mails = mails
end
def edit
- @mail_template = @procedure.mail_templates.find(params[:id])
+ @mail_template = find_the_right_mail params[:id]
end
def update
- mail_template = @procedure.mail_templates.find(params[:id])
+ mail_template = find_the_right_mail params[:id]
mail_template.update_attributes(update_params)
-
redirect_to admin_procedure_mail_templates_path
end
private
+ def mails
+ %w(initiated received closed refused without_continuation)
+ .map { |name| @procedure.send(name + "_mail") }
+ end
+
+ def find_the_right_mail type
+ mails.find { |m| m.class.slug == type }
+ end
+
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
diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb
index 14dd0a230..7edc11989 100644
--- a/app/controllers/backoffice/dossiers_controller.rb
+++ b/app/controllers/backoffice/dossiers_controller.rb
@@ -88,45 +88,53 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
def receive
create_dossier_facade params[:dossier_id]
- @facade.dossier.received!
+ dossier = @facade.dossier
+
+ dossier.received!
flash.notice = 'Dossier considéré comme reçu.'
- NotificationMailer.dossier_received(@facade.dossier).deliver_now!
+ NotificationMailer.send_notification(dossier, dossier.procedure.received_mail).deliver_now!
- redirect_to backoffice_dossier_path(id: @facade.dossier.id)
+ redirect_to backoffice_dossier_path(id: dossier.id)
end
def refuse
create_dossier_facade params[:dossier_id]
- @facade.dossier.next_step! 'gestionnaire', 'refuse'
+ dossier = @facade.dossier
+
+ dossier.next_step! 'gestionnaire', 'refuse'
flash.notice = 'Dossier considéré comme refusé.'
- NotificationMailer.dossier_refused(@facade.dossier).deliver_now!
+ NotificationMailer.send_notification(dossier, dossier.procedure.refused_mail).deliver_now!
- redirect_to backoffice_dossier_path(id: @facade.dossier.id)
+ redirect_to backoffice_dossier_path(id: dossier.id)
end
def without_continuation
create_dossier_facade params[:dossier_id]
- @facade.dossier.next_step! 'gestionnaire', 'without_continuation'
+ dossier = @facade.dossier
+
+ dossier.next_step! 'gestionnaire', 'without_continuation'
flash.notice = 'Dossier considéré comme sans suite.'
- NotificationMailer.dossier_without_continuation(@facade.dossier).deliver_now!
+ NotificationMailer.send_notification(dossier, dossier.procedure.without_continuation_mail).deliver_now!
- redirect_to backoffice_dossier_path(id: @facade.dossier.id)
+ redirect_to backoffice_dossier_path(id: dossier.id)
end
def close
create_dossier_facade params[:dossier_id]
- @facade.dossier.next_step! 'gestionnaire', 'close'
+ dossier = @facade.dossier
+
+ dossier.next_step! 'gestionnaire', 'close'
flash.notice = 'Dossier traité avec succès.'
- NotificationMailer.dossier_closed(@facade.dossier).deliver_now!
+ NotificationMailer.send_notification(dossier, dossier.procedure.closed_mail).deliver_now!
- redirect_to backoffice_dossier_path(id: @facade.dossier.id)
+ redirect_to backoffice_dossier_path(id: dossier.id)
end
def follow
diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb
index fa2d26f8d..71bc8aa29 100644
--- a/app/controllers/users/description_controller.rb
+++ b/app/controllers/users/description_controller.rb
@@ -72,6 +72,7 @@ class Users::DescriptionController < UsersController
if mandatory
if @dossier.draft?
@dossier.initiated!
+ NotificationMailer.send_notification(@dossier, @dossier.procedure.initiated_mail).deliver_now!
end
flash.notice = 'Félicitations, votre demande a bien été enregistrée.'
diff --git a/app/decorators/mail_template_decorator.rb b/app/decorators/mail_template_decorator.rb
deleted file mode 100644
index b9c153553..000000000
--- a/app/decorators/mail_template_decorator.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-class MailTemplateDecorator < Draper::Decorator
- delegate_all
-
- def name
- case object.type
- when "MailReceived"
- "E-mail d'accusé de réception"
- else
- object.type
- end
- end
-end
diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb
index d88191812..185543d22 100644
--- a/app/mailers/notification_mailer.rb
+++ b/app/mailers/notification_mailer.rb
@@ -1,28 +1,20 @@
class NotificationMailer < ApplicationMailer
+ default from: 'tps@apientreprise.fr',
+ to: Proc.new { @user.email }
+
+ def send_notification dossier, mail_template
+ vars_mailer(dossier)
+
+ obj = mail_template.object_for_dossier dossier
+ body = mail_template.body_for_dossier dossier
+
+ mail(subject: obj) { |format| format.html { body } }
+ end
+
def new_answer dossier
send_mail dossier, "Nouveau message pour votre dossier TPS N°#{dossier.id}"
end
- def dossier_received dossier
- send_mail dossier, dossier.procedure.mail_received.object_for_dossier(dossier)
- end
-
- def dossier_submitted dossier
- send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été déposé"
- end
-
- def dossier_without_continuation dossier
- send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été classé sans suite"
- end
-
- def dossier_refused dossier
- send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été refusé"
- end
-
- def dossier_closed dossier
- send_mail dossier, "Votre dossier TPS N°#{dossier.id} a été accepté"
- end
-
private
def vars_mailer dossier
@@ -33,7 +25,6 @@ class NotificationMailer < ApplicationMailer
def send_mail dossier, subject
vars_mailer dossier
- mail(from: "tps@apientreprise.fr", to: @user.email,
- subject: subject)
+ mail(subject: subject)
end
end
diff --git a/app/models/mail_template.rb b/app/models/concerns/mail_template_concern.rb
similarity index 57%
rename from app/models/mail_template.rb
rename to app/models/concerns/mail_template_concern.rb
index eac1020f9..0da40c322 100644
--- a/app/models/mail_template.rb
+++ b/app/models/concerns/mail_template_concern.rb
@@ -1,9 +1,9 @@
-class MailTemplate < ActiveRecord::Base
+module MailTemplateConcern
+ extend ActiveSupport::Concern
+
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."
@@ -30,19 +30,29 @@ class MailTemplate < ActiveRecord::Base
end
end
+ module ClassMethods
+ def slug
+ self.name.demodulize.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
+
private
def replace_tag tag, dossier
case tag
- 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--'
+ when :numero_dossier
+ dossier.id.to_s
+ when :lien_dossier
+ 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
diff --git a/app/models/mail_received.rb b/app/models/mail_received.rb
deleted file mode 100644
index d2980f188..000000000
--- a/app/models/mail_received.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-class MailReceived < MailTemplate
- before_save :default_values
-
- def default_values
- self.object ||= "[TPS] Accusé de réception pour votre dossier n°--numero_dossier--"
- self.body ||= "Bonjour,
-
-
- Votre administration vous confirme la bonne réception de votre dossier n°--numero_dossier-- complet. Celui-ci sera instruit dans le délai légal déclaré par votre interlocuteur.
-
- En vous souhaitant une bonne journée,
-
-
- ---
-
- L'équipe TPS"
- end
-end
diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb
new file mode 100644
index 000000000..3db0d84dc
--- /dev/null
+++ b/app/models/mails/closed_mail.rb
@@ -0,0 +1,9 @@
+module Mails
+ class ClosedMail < ActiveRecord::Base
+ include MailTemplateConcern
+
+ DISPLAYED_NAME = "Accusé d'acceptation"
+ DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été accepté'
+
+ end
+end
diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb
new file mode 100644
index 000000000..e39aa0e7a
--- /dev/null
+++ b/app/models/mails/initiated_mail.rb
@@ -0,0 +1,9 @@
+module Mails
+ class InitiatedMail < ActiveRecord::Base
+ include MailTemplateConcern
+
+ DISPLAYED_NAME = 'Accusé de réception'
+ DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été bien reçu'
+
+ end
+end
diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb
new file mode 100644
index 000000000..41344f6ca
--- /dev/null
+++ b/app/models/mails/received_mail.rb
@@ -0,0 +1,9 @@
+module Mails
+ class ReceivedMail < ActiveRecord::Base
+ include MailTemplateConcern
+
+ DISPLAYED_NAME = 'Accusé de passage en instruction'
+ DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- va être instruit'
+
+ end
+end
diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb
new file mode 100644
index 000000000..a1a1af8b4
--- /dev/null
+++ b/app/models/mails/refused_mail.rb
@@ -0,0 +1,9 @@
+module Mails
+ class RefusedMail < ApplicationRecord
+ include MailTemplateConcern
+
+ DISPLAYED_NAME = 'Accusé de rejet du dossier'
+ DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été refusé'
+
+ end
+end
diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb
new file mode 100644
index 000000000..da9724cf6
--- /dev/null
+++ b/app/models/mails/without_continuation_mail.rb
@@ -0,0 +1,9 @@
+module Mails
+ class WithoutContinuationMail < ApplicationRecord
+ include MailTemplateConcern
+
+ DISPLAYED_NAME = 'Accusé de classement sans suite'
+ DEFAULT_OBJECT = 'Votre dossier TPS N°--numero_dossier-- a été classé sans suite'
+
+ end
+end
diff --git a/app/models/procedure.rb b/app/models/procedure.rb
index 8c6f55b1e..947499b30 100644
--- a/app/models/procedure.rb
+++ b/app/models/procedure.rb
@@ -3,8 +3,6 @@ class Procedure < ActiveRecord::Base
has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy
has_many :types_de_champ_private, dependent: :destroy
has_many :dossiers
- has_many :mail_templates
- has_one :mail_received
has_one :procedure_path, dependent: :destroy
@@ -29,10 +27,23 @@ class Procedure < ActiveRecord::Base
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :description, presence: true, allow_blank: false, allow_nil: false
- after_create :build_default_mails
+ # for all those mails do
+ # has_one :initiated_mail, class_name: 'Mails::InitiatedMail'
+ #
+ # add a method to return default mail if none is saved
+ # def initiated_mail_with_override
+ # self.initiated_mail_without_override || InitiatedMail.default
+ # end
+ # alias_method_chain :initiated_mail, :override
- def build_default_mails
- MailReceived.create(procedure: self) unless mail_received
+ MAIL_TEMPLATE_TYPES = %w(InitiatedMail ReceivedMail ClosedMail RefusedMail WithoutContinuationMail)
+
+ MAIL_TEMPLATE_TYPES.each do |name|
+ has_one "#{name.underscore}".to_sym, class_name: "Mails::#{name}"
+ define_method("#{name.underscore}_with_override") do
+ self.send("#{name.underscore}_without_override") || Object.const_get("Mails::#{name}").default
+ end
+ alias_method_chain "#{name.underscore.to_sym}".to_s, :override
end
def path
@@ -89,11 +100,22 @@ class Procedure < ActiveRecord::Base
end
def clone
- procedure = self.deep_clone(include: [:types_de_piece_justificative, :types_de_champ, :types_de_champ_private, :module_api_carto, :mail_templates, types_de_champ: [:drop_down_list]])
+ procedure = self.deep_clone(include:
+ [:types_de_piece_justificative,
+ :types_de_champ,
+ :types_de_champ_private,
+ :module_api_carto,
+ types_de_champ: [:drop_down_list]
+ ])
procedure.archived = false
procedure.published = false
procedure.logo_secure_token = nil
procedure.remote_logo_url = self.logo_url
+
+ MAIL_TEMPLATE_TYPES.each do |mtt|
+ procedure.send("#{mtt.underscore}=", self.send("#{mtt.underscore}_without_override").try(:dup))
+ end
+
return procedure if procedure.save
end
diff --git a/app/views/admin/mail_templates/edit.html.haml b/app/views/admin/mail_templates/edit.html.haml
index f166c6879..35efe2506 100644
--- a/app/views/admin/mail_templates/edit.html.haml
+++ b/app/views/admin/mail_templates/edit.html.haml
@@ -1,8 +1,11 @@
.white-back
%h3
- = @mail_template.decorate.name
+ = @mail_template.class.const_get(:DISPLAYED_NAME)
- = simple_form_for @mail_template.becomes(MailTemplate), url: admin_procedure_mail_template_path(@procedure, @mail_template) do |f|
+ = simple_form_for @mail_template,
+ as: 'mail_template',
+ url: admin_procedure_mail_template_path(@procedure, @mail_template.class.slug),
+ method: :put do |f|
.row
.col-md-6
= f.input :object, label: "Objet de l'email"
@@ -19,7 +22,7 @@
Balise
%th
Description
- - MailTemplate::TAGS.each do |balise|
+ - MailTemplateConcern::TAGS.each do |balise|
%tr
%td.center
= "--#{balise.first}--"
diff --git a/app/views/admin/mail_templates/index.html.haml b/app/views/admin/mail_templates/index.html.haml
index 8f7df9420..b8eff250a 100644
--- a/app/views/admin/mail_templates/index.html.haml
+++ b/app/views/admin/mail_templates/index.html.haml
@@ -1,15 +1,13 @@
-.row.white-back
- %h1 E-mails personnalisables
-
- .row
- .col-md-6
- %table.table
+#custom-mails
+ .wrapper
+ %h1 E-mails personnalisables
+ %table.table
+ %tr
+ %th{ colspan: 2 }
+ Type d'email
+ - @mails.each do |mail|
%tr
- %th{ colspan: 2 }
- Type d'email
- - @procedure.mail_templates.each do |mt|
- %tr
- %td
- = mt.decorate.name
- %td.text-right
- = link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mt)
+ %td
+ = mail.class.const_get(:DISPLAYED_NAME)
+ %td.text-right
+ = link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mail.class.slug)
diff --git a/app/views/layouts/_main_container.html.haml b/app/views/layouts/_main_container.html.haml
index 9e04a4a32..a1d728b3a 100644
--- a/app/views/layouts/_main_container.html.haml
+++ b/app/views/layouts/_main_container.html.haml
@@ -1,6 +1,6 @@
-%div#main-container{class: "col-xs-#{main_container_size}"}
- %div.row
+#main-container{ class: "col-xs-#{main_container_size}" }
+ .row
= render partial: 'layouts/flash_messages'
- %div.row
+ .row
= yield
- %div.row
+ .row
diff --git a/app/views/mails/closed_mail.html.haml b/app/views/mails/closed_mail.html.haml
new file mode 100644
index 000000000..636817517
--- /dev/null
+++ b/app/views/mails/closed_mail.html.haml
@@ -0,0 +1,17 @@
+Bonjour
+%br
+%br
+Votre dossier N°--numero_dossier-- a été accepté.
+%br
+%br
+A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien_dossier--
+%br
+%br
+Bonne journée
+%br
+%br
+\---
+%br
+Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
+%br
+\---
diff --git a/app/views/mails/initiated_mail.html.haml b/app/views/mails/initiated_mail.html.haml
new file mode 100644
index 000000000..d1e0ab917
--- /dev/null
+++ b/app/views/mails/initiated_mail.html.haml
@@ -0,0 +1,17 @@
+Bonjour
+%br
+%br
+Votre administration vous confirme la bonne réception de votre dossier n°--numero_dossier--.
+%br
+%br
+A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien_dossier--
+%br
+%br
+Bonne journée
+%br
+%br
+\---
+%br
+Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
+%br
+\---
diff --git a/app/views/mails/received_mail.html.haml b/app/views/mails/received_mail.html.haml
new file mode 100644
index 000000000..bc0b64ffa
--- /dev/null
+++ b/app/views/mails/received_mail.html.haml
@@ -0,0 +1,14 @@
+Bonjour
+%br
+%br
+Votre administration vous confirme la bonne réception de votre dossier n°--numero_dossier--. Celui-ci sera instruit dans le délai légal déclaré par votre interlocuteur.
+%br
+%br
+Bonne journée
+%br
+%br
+\---
+%br
+Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
+%br
+\---
diff --git a/app/views/mails/refused_mail.html.haml b/app/views/mails/refused_mail.html.haml
new file mode 100644
index 000000000..d98bacab6
--- /dev/null
+++ b/app/views/mails/refused_mail.html.haml
@@ -0,0 +1,17 @@
+Bonjour
+%br
+%br
+Votre dossier N°--numero_dossier-- a été refusé.
+%br
+%br
+Pour en savoir plus sur le motif du refus, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien_dossier--
+%br
+%br
+Bonne journée
+%br
+%br
+\---
+%br
+Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
+%br
+\---
diff --git a/app/views/mails/without_continuation_mail.html.haml b/app/views/mails/without_continuation_mail.html.haml
new file mode 100644
index 000000000..5277c51a6
--- /dev/null
+++ b/app/views/mails/without_continuation_mail.html.haml
@@ -0,0 +1,17 @@
+Bonjour
+%br
+%br
+Votre dossier N°--numero_dossier-- a été classé sans suite.
+%br
+%br
+Pour en savoir plus sur les raisons de ce classement sans suite, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien_dossier--
+%br
+%br
+Bonne journée
+%br
+%br
+\---
+%br
+Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
+%br
+\---
diff --git a/app/views/notification_mailer/dossier_closed.text.erb b/app/views/notification_mailer/dossier_closed.text.erb
deleted file mode 100644
index 81d692a64..000000000
--- a/app/views/notification_mailer/dossier_closed.text.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-Bonjour <%= @user.email %>
-
-votre dossier N°<%=@dossier.id%> déposé auprès de <%= @dossier.procedure.organisation %> a été accepté ce jour à <%= @dossier.updated_at %>.
-
-A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : <%=users_dossier_recapitulatif_url(dossier_id: @dossier.id)%>
-
-Bonne journée
-
----
-Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
----
-
----
-L'équide TPS - tps@apientreprise.fr
\ No newline at end of file
diff --git a/app/views/notification_mailer/dossier_received.html.erb b/app/views/notification_mailer/dossier_received.html.erb
deleted file mode 100644
index 6c2c537d2..000000000
--- a/app/views/notification_mailer/dossier_received.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= @dossier.procedure.mail_received.body_for_dossier(@dossier).html_safe %>
diff --git a/app/views/notification_mailer/dossier_refused.text.erb b/app/views/notification_mailer/dossier_refused.text.erb
deleted file mode 100644
index 2024297be..000000000
--- a/app/views/notification_mailer/dossier_refused.text.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-Bonjour <%= @user.email %>
-
-votre dossier N°<%=@dossier.id%> déposé auprès de <%= @dossier.procedure.organisation %> a été refusé ce jour à <%= @dossier.updated_at %>.
-
-Pour en savoir plus sur le motif du refus, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : <%=users_dossier_recapitulatif_url(dossier_id: @dossier.id)%>
-
-Bonne journée,
-
----
-Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
----
-
----
-L'équide TPS - tps@apientreprise.fr
\ No newline at end of file
diff --git a/app/views/notification_mailer/dossier_submitted.text.erb b/app/views/notification_mailer/dossier_submitted.text.erb
deleted file mode 100644
index 2357b8bbf..000000000
--- a/app/views/notification_mailer/dossier_submitted.text.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-Bonjour <%= @user.email %>
-
-Nous vous confirmons que votre dossier N°<%=@dossier.id%> a été déposé auprès de <%= @dossier.procedure.organisation %> avec succès ce jour à <%= @dossier.updated_at %>.
-
-Bonne journée,
-
----
-Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
----
-
----
-L'équide TPS - tps@apientreprise.fr
\ No newline at end of file
diff --git a/app/views/notification_mailer/dossier_without_continuation.text.erb b/app/views/notification_mailer/dossier_without_continuation.text.erb
deleted file mode 100644
index 73fe7d8e2..000000000
--- a/app/views/notification_mailer/dossier_without_continuation.text.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-Bonjour <%= @user.email %>
-
-votre dossier N°<%=@dossier.id%> déposé auprès de <%= @dossier.procedure.organisation %> a été classé sans suite ce jour à <%= @dossier.updated_at %>.
-
-Pour en savoir plus sur les raisons de ce classement sans suite, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : <%=users_dossier_recapitulatif_url(dossier_id: @dossier.id)%>
-
-Bonne journée,
-
----
-Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme.
----
-
----
-L'équide TPS - tps@apientreprise.fr
\ No newline at end of file
diff --git a/db/migrate/20170223170808_delete_all_mail_validated_in_db.rb b/db/migrate/20170223170808_delete_all_mail_validated_in_db.rb
index 74d89af2a..dbd8860d1 100644
--- a/db/migrate/20170223170808_delete_all_mail_validated_in_db.rb
+++ b/db/migrate/20170223170808_delete_all_mail_validated_in_db.rb
@@ -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
diff --git a/db/migrate/20170302105557_create_initiated_mails.rb b/db/migrate/20170302105557_create_initiated_mails.rb
new file mode 100644
index 000000000..91e005e6a
--- /dev/null
+++ b/db/migrate/20170302105557_create_initiated_mails.rb
@@ -0,0 +1,11 @@
+class CreateInitiatedMails < ActiveRecord::Migration[5.0]
+ def change
+ create_table :initiated_mails do |t|
+ t.string :object
+ t.text :body
+ t.belongs_to :procedure, index: true, unique: true, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20170302112312_remove_deposit_datetime_from_dossiers.rb b/db/migrate/20170302112312_remove_deposit_datetime_from_dossiers.rb
index 600beb4a3..823290306 100644
--- a/db/migrate/20170302112312_remove_deposit_datetime_from_dossiers.rb
+++ b/db/migrate/20170302112312_remove_deposit_datetime_from_dossiers.rb
@@ -1,8 +1,17 @@
class RemoveDepositDatetimeFromDossiers < ActiveRecord::Migration[5.0]
def change
+ remove_column :dossiers, :deposit_datetime, :datetime
+ end
+
+ def up
Dossier.where.not(deposit_datetime: nil).each do |dossier|
dossier.update(initiated_at: dossier.deposit_datetime)
end
- remove_column :dossiers, :deposit_datetime, :datetime
+ end
+
+ def down
+ Dossier.where.not(initiated_at: nil).each do |dossier|
+ dossier.update(deposit_datetime: dossier.initiated_at)
+ end
end
end
diff --git a/db/migrate/20170306102116_create_received_mails.rb b/db/migrate/20170306102116_create_received_mails.rb
new file mode 100644
index 000000000..aaaaefb42
--- /dev/null
+++ b/db/migrate/20170306102116_create_received_mails.rb
@@ -0,0 +1,12 @@
+class CreateReceivedMails < ActiveRecord::Migration[5.0]
+ def change
+ create_table :received_mails do |t|
+ t.text :body
+ t.string :object
+ t.references :procedure, foreign_key: true
+
+ t.column :created_at, :timestamp, null: true
+ t.column :updated_at, :timestamp, null: true
+ end
+ end
+end
diff --git a/db/migrate/20170306102238_create_closed_mails.rb b/db/migrate/20170306102238_create_closed_mails.rb
new file mode 100644
index 000000000..49f3bf5e8
--- /dev/null
+++ b/db/migrate/20170306102238_create_closed_mails.rb
@@ -0,0 +1,11 @@
+class CreateClosedMails < ActiveRecord::Migration[5.0]
+ def change
+ create_table :closed_mails do |t|
+ t.text :body
+ t.string :object
+ t.belongs_to :procedure, index: true, unique: true, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20170306102256_create_refused_mails.rb b/db/migrate/20170306102256_create_refused_mails.rb
new file mode 100644
index 000000000..ea7b58846
--- /dev/null
+++ b/db/migrate/20170306102256_create_refused_mails.rb
@@ -0,0 +1,11 @@
+class CreateRefusedMails < ActiveRecord::Migration[5.0]
+ def change
+ create_table :refused_mails do |t|
+ t.text :body
+ t.string :object
+ t.belongs_to :procedure, index: true, unique: true, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20170306102320_create_without_continuation_mails.rb b/db/migrate/20170306102320_create_without_continuation_mails.rb
new file mode 100644
index 000000000..09dbe1b8e
--- /dev/null
+++ b/db/migrate/20170306102320_create_without_continuation_mails.rb
@@ -0,0 +1,11 @@
+class CreateWithoutContinuationMails < ActiveRecord::Migration[5.0]
+ def change
+ create_table :without_continuation_mails do |t|
+ t.text :body
+ t.string :object
+ t.belongs_to :procedure, index: true, unique: true, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20170307092820_move_mails_to_new_system.rb b/db/migrate/20170307092820_move_mails_to_new_system.rb
new file mode 100644
index 000000000..02b41ced3
--- /dev/null
+++ b/db/migrate/20170307092820_move_mails_to_new_system.rb
@@ -0,0 +1,11 @@
+class MoveMailsToNewSystem < ActiveRecord::Migration[5.0]
+ def up
+ execute 'INSERT INTO received_mails (object, body, procedure_id, created_at, updated_at)
+ SELECT object, body, procedure_id, mail_templates.created_at, mail_templates.updated_at from mail_templates inner join procedures on mail_templates.procedure_id = procedures.id;'
+
+ execute "UPDATE received_mails set created_at='1980-01-01 00:00', updated_at='1980-01-01 00:00' where created_at is NULL"
+
+ change_column_null :received_mails, :created_at, false
+ change_column_null :received_mails, :updated_at, false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f64bd3888..db86ebfaf 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170302112312) do
+ActiveRecord::Schema.define(version: 20170307092820) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -104,6 +104,15 @@ ActiveRecord::Schema.define(version: 20170302112312) do
t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id", using: :btree
end
+ create_table "closed_mails", force: :cascade do |t|
+ t.text "body"
+ t.string "object"
+ t.integer "procedure_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["procedure_id"], name: "index_closed_mails_on_procedure_id", using: :btree
+ end
+
create_table "commentaires", force: :cascade do |t|
t.string "email"
t.datetime "created_at", null: false
@@ -227,6 +236,15 @@ ActiveRecord::Schema.define(version: 20170302112312) do
t.index ["dossier_id"], name: "index_individuals_on_dossier_id", using: :btree
end
+ create_table "initiated_mails", force: :cascade do |t|
+ t.string "object"
+ t.text "body"
+ t.integer "procedure_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["procedure_id"], name: "index_initiated_mails_on_procedure_id", using: :btree
+ end
+
create_table "invites", force: :cascade do |t|
t.string "email"
t.string "email_sender"
@@ -336,6 +354,24 @@ ActiveRecord::Schema.define(version: 20170302112312) do
t.integer "dossier_id"
end
+ create_table "received_mails", force: :cascade do |t|
+ t.text "body"
+ t.string "object"
+ t.integer "procedure_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["procedure_id"], name: "index_received_mails_on_procedure_id", using: :btree
+ end
+
+ create_table "refused_mails", force: :cascade do |t|
+ t.text "body"
+ t.string "object"
+ t.integer "procedure_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["procedure_id"], name: "index_refused_mails_on_procedure_id", using: :btree
+ end
+
create_table "rna_informations", force: :cascade do |t|
t.string "association_id"
t.string "titre"
@@ -387,11 +423,25 @@ ActiveRecord::Schema.define(version: 20170302112312) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
+ create_table "without_continuation_mails", force: :cascade do |t|
+ t.text "body"
+ t.string "object"
+ t.integer "procedure_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["procedure_id"], name: "index_without_continuation_mails_on_procedure_id", using: :btree
+ end
+
add_foreign_key "cerfas", "dossiers"
+ add_foreign_key "closed_mails", "procedures"
add_foreign_key "commentaires", "dossiers"
add_foreign_key "dossiers", "users"
+ add_foreign_key "initiated_mails", "procedures"
add_foreign_key "procedure_paths", "administrateurs"
add_foreign_key "procedure_paths", "procedures"
+ add_foreign_key "received_mails", "procedures"
+ add_foreign_key "refused_mails", "procedures"
+ add_foreign_key "without_continuation_mails", "procedures"
create_view :searches, sql_definition: <<-SQL
SELECT dossiers.id AS dossier_id,
diff --git a/spec/controllers/admin/mail_templates_controller_spec.rb b/spec/controllers/admin/mail_templates_controller_spec.rb
index e80ba6c5b..31adfd4ee 100644
--- a/spec/controllers/admin/mail_templates_controller_spec.rb
+++ b/spec/controllers/admin/mail_templates_controller_spec.rb
@@ -1,8 +1,8 @@
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]}
+ let(:initiated_mail) { Mails::InitiatedMail.default }
+ let(:procedure) { create :procedure }
before do
sign_in procedure.administrateur
@@ -11,41 +11,32 @@ describe Admin::MailTemplatesController, type: :controller do
describe 'GET index' do
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.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(Mails::InitiatedMail::DISPLAYED_NAME) }
end
describe 'PATCH update' do
let(:object) { 'plop modif' }
let(:body) { 'plip modif' }
- context 'when is mail_template id' do
- subject { patch :update,
- params: {procedure_id: mail_template.procedure.id,
- id: mail_template.id,
- mail_template: {
- object: object,
- body: body
- }} }
+ before :each do
+ patch :update,
+ params: { procedure_id: procedure.id,
+ id: initiated_mail.class.slug,
+ mail_template: { object: object, body: body }
+ }
+ end
- it { expect(subject).to redirect_to admin_procedure_mail_templates_path(mail_template.procedure) }
+ it { expect(response).to redirect_to admin_procedure_mail_templates_path(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)
- }
+ context 'the mail template' do
+ subject { procedure.reload ; procedure.initiated_mail }
- it {
- expect {
- subject
- mail_template.reload
- }.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
diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb
index 72de50eca..7cc7759aa 100644
--- a/spec/controllers/backoffice/dossiers_controller_spec.rb
+++ b/spec/controllers/backoffice/dossiers_controller_spec.rb
@@ -230,7 +230,8 @@ describe Backoffice::DossiersController, type: :controller do
end
it 'Notification email is send' do
- expect(NotificationMailer).to receive(:dossier_received).and_return(NotificationMailer)
+ expect(NotificationMailer).to receive(:send_notification)
+ .with(dossier, kind_of(Mails::ReceivedMail)).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
@@ -255,7 +256,8 @@ describe Backoffice::DossiersController, type: :controller do
end
it 'Notification email is sent' do
- expect(NotificationMailer).to receive(:dossier_refused).and_return(NotificationMailer)
+ expect(NotificationMailer).to receive(:send_notification)
+ .with(dossier, kind_of(Mails::RefusedMail)).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
@@ -280,7 +282,8 @@ describe Backoffice::DossiersController, type: :controller do
end
it 'Notification email is sent' do
- expect(NotificationMailer).to receive(:dossier_without_continuation).and_return(NotificationMailer)
+ expect(NotificationMailer).to receive(:send_notification)
+ .with(dossier, kind_of(Mails::WithoutContinuationMail)).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
@@ -304,7 +307,8 @@ describe Backoffice::DossiersController, type: :controller do
end
it 'Notification email is sent' do
- expect(NotificationMailer).to receive(:dossier_closed).and_return(NotificationMailer)
+ expect(NotificationMailer).to receive(:send_notification)
+ .with(dossier, kind_of(Mails::ClosedMail)).and_return(NotificationMailer)
expect(NotificationMailer).to receive(:deliver_now!)
subject
diff --git a/spec/decorators/mail_template_decorator_spec.rb b/spec/decorators/mail_template_decorator_spec.rb
deleted file mode 100644
index de8a3f167..000000000
--- a/spec/decorators/mail_template_decorator_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require 'spec_helper'
-
-describe MailTemplateDecorator do
- let(:mail_template) {create :mail_template}
- let(:decorator) { mail_template.decorate }
-
- context '#name' do
- subject { decorator.name }
-
- context 'when mail_template is a MailReceived' do
- let(:mail_template) {create :mail_template, :dossier_received}
- it { is_expected.to eq "E-mail d'accusé de réception" }
- end
-
- end
-
-end
diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb
index d3b7cc066..e97e10ee1 100644
--- a/spec/factories/procedure.rb
+++ b/spec/factories/procedure.rb
@@ -9,7 +9,6 @@ FactoryGirl.define do
published false
cerfa_flag false
administrateur { create(:administrateur) }
- mail_templates { [create(:mail_template, :dossier_received)]}
after(:build) do |procedure, _evaluator|
if procedure.module_api_carto.nil?
diff --git a/spec/factories/mail_received.rb b/spec/factories/received_mail.rb
similarity index 72%
rename from spec/factories/mail_received.rb
rename to spec/factories/received_mail.rb
index 2e6ef674c..d97effd96 100644
--- a/spec/factories/mail_received.rb
+++ b/spec/factories/received_mail.rb
@@ -1,7 +1,6 @@
FactoryGirl.define do
- factory :mail_received 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"
- type 'MailReceived'
end
end
diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb
index 10d6b5e24..0f9aeba80 100644
--- a/spec/mailers/notification_mailer_spec.rb
+++ b/spec/mailers/notification_mailer_spec.rb
@@ -1,6 +1,16 @@
require "spec_helper"
RSpec.describe NotificationMailer, type: :mailer do
+ describe '.send_notification' do
+ let(:user) { create(:user) }
+ let(:dossier) { create(:dossier, user: user) }
+ let(:email) { instance_double('email', object_for_dossier: 'object', body_for_dossier: 'body') }
+ subject { described_class.send_notification(dossier, email) }
+
+ it { expect(subject.subject).to eq(email.object_for_dossier) }
+ it { expect(subject.body).to eq(email.body_for_dossier) }
+ end
+
describe ".new_answer" do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user) }
@@ -11,30 +21,4 @@ RSpec.describe NotificationMailer, type: :mailer do
it { expect(subject.body).to include("Pour le consulter, merci de vous rendre sur #{users_dossier_recapitulatif_url(dossier_id: dossier.id)}") }
it { expect(subject.subject).to eq("Nouveau message pour votre dossier TPS N°#{dossier.id}") }
end
-
- describe ".dossier_submitted" do
- let(:user) { create(:user) }
- let(:dossier) { create(:dossier, user: user) }
-
- subject(:subject) { described_class.dossier_submitted(dossier) }
-
- before { dossier.reload }
-
- it { expect(subject.body).to match("Nous vous confirmons que votre dossier N°#{dossier.id} a été déposé") }
- it { expect(subject.body).to match("auprès de #{dossier.procedure.organisation} avec succès") }
- it { expect(subject.body).to match("ce jour à #{dossier.updated_at}.") }
- it { expect(subject.subject).to eq("Votre dossier TPS N°#{dossier.id} a été déposé") }
- end
-
- describe '.dossier_received' do
- let(:user) { create(:user) }
- let(:dossier) { create(:dossier, user: user) }
-
- subject(:subject) { described_class.dossier_received(dossier) }
-
- before { dossier.reload }
-
- it { expect(subject.subject).to eq("[TPS] Accusé de réception pour votre dossier n°#{dossier.id}") }
- it { expect(subject.body).to match("Votre administration vous confirme la bonne réception de votre dossier n°#{dossier.id}") }
- end
end
diff --git a/spec/mailers/previews/notification_mailer_preview.rb b/spec/mailers/previews/notification_mailer_preview.rb
index 5eb4a0bb3..25fa735c2 100644
--- a/spec/mailers/previews/notification_mailer_preview.rb
+++ b/spec/mailers/previews/notification_mailer_preview.rb
@@ -1,7 +1,7 @@
class NotificationMailerPreview < ActionMailer::Preview
- def dossier_received
- NotificationMailer.dossier_received(Dossier.last)
+ def send_notification
+ NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail)
end
end
diff --git a/spec/migrations/remove_duplicate_email_received_spec.rb b/spec/migrations/remove_duplicate_email_received_spec.rb
deleted file mode 100644
index 9fd83c40a..000000000
--- a/spec/migrations/remove_duplicate_email_received_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-load 'spec/spec_helper.rb'
-load 'db/migrate/20170215102943_remove_duplicate_email_received.rb'
-
-describe RemoveDuplicateEmailReceived do
- context 'with one procedure and one associated mail_received' do
- let!(:procedure) { create(:procedure) }
-
- it 'keeps the procedure mails' do
- RemoveDuplicateEmailReceived.new.change
- expect(MailReceived.count).to eq(1)
- end
-
- context 'and another mail_received' do
- before :each do
- MailReceived.create!(procedure: procedure)
- end
-
- it 'destroys the unecessary maiL_received' do
- RemoveDuplicateEmailReceived.new.change
- expect(MailReceived.count).to eq(1)
- expect(procedure.mail_received).not_to be_nil
- end
- end
- end
-end
diff --git a/spec/models/concern/mail_template_concern_spec.rb b/spec/models/concern/mail_template_concern_spec.rb
new file mode 100644
index 000000000..f177a360a
--- /dev/null
+++ b/spec/models/concern/mail_template_concern_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe MailTemplateConcern do
+ describe '.replace_tags' do
+ let(:dossier) { create :dossier }
+ let(:initiated_mail) { Mails::InitiatedMail.default }
+
+ it 'works' do
+ initiated_mail.object = '[TPS] --numero_dossier-- --libelle_procedure-- --lien_dossier--'
+ expected =
+ "[TPS] 1 Demande de subvention " +
+ "http://localhost:3000/users/dossiers/1/recapitulatif"
+
+ expect(initiated_mail.object_for_dossier(dossier)).to eq(expected)
+ end
+ end
+end
diff --git a/spec/models/mail_template_spec.rb b/spec/models/mail_template_spec.rb
deleted file mode 100644
index fb27e5d94..000000000
--- a/spec/models/mail_template_spec.rb
+++ /dev/null
@@ -1,90 +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 '.tags' do
- subject { MailTemplate::TAGS }
-
- it { expect(subject.size).to eq 3 }
-
- describe 'numero_dossier' do
- subject { super()[:numero_dossier] }
-
- describe 'attr and description value' do
-
- it { expect(subject[:description]).to eq "Permet d'afficher le numéro de dossier de l'utilisateur." }
- end
- end
-
- describe 'libelle_procedure' do
- subject { super()[:libelle_procedure] }
-
- describe 'attr and description value' do
-
- it { expect(subject[:description]).to eq "Permet d'afficher le libellé de la procédure." }
- end
- end
-
- describe 'lien_dossier' do
- subject { super()[:lien_dossier] }
-
- describe 'attr and description value' do
-
- it { expect(subject[:description]).to eq "Permet d'afficher un lien vers le dossier de l'utilisateur." }
- end
- end
- end
-
- describe '.replace_tags' do
- let(:dossier) { create :dossier }
- let(:procedure) { dossier.procedure }
- let(:mail_received) { procedure.mail_received }
-
- describe 'for tag --numero_dossier--' do
- before do
- procedure.mail_received.update_column(:object, '[TPS] Dossier n°--numero_dossier--')
- end
-
- subject { procedure.mail_received.object_for_dossier dossier }
-
- it { expect(subject).to eq "[TPS] Dossier n°#{dossier.id}" }
- end
-
- describe 'for tag --libelle_procedure--' do
- before do
- procedure.mail_received.update_column(:object, '[TPS] Dossier pour la procédure --libelle_procedure--')
- end
-
- subject { procedure.mail_received.object_for_dossier dossier }
-
- it { expect(subject).to eq "[TPS] Dossier pour la procédure #{procedure.libelle}" }
- end
-
- describe 'for tag --lien_dossier--' do
- include Rails.application.routes.url_helpers
- include ActionView::Helpers::UrlHelper
-
- before do
- procedure.mail_received.update_column(:body, 'Consultez votre dossier ici --lien_dossier--')
- end
-
- subject { procedure.mail_received.body_for_dossier dossier }
-
- it { is_expected.to eq "Consultez votre dossier ici #{link_to users_dossier_recapitulatif_url(dossier), users_dossier_recapitulatif_url(dossier), target: '_blank'}" }
- end
-
- describe 'multiple tags' do
- before do
- procedure.mail_received.update_column(:object, '[TPS] Dossier n°--numero_dossier-- pour la procédure --libelle_procedure-- et encore le numéro : --numero_dossier--')
- end
-
- subject { procedure.mail_received.object_for_dossier dossier }
-
- it { expect(subject).to eq "[TPS] Dossier n°#{dossier.id} pour la procédure #{procedure.libelle} et encore le numéro : #{dossier.id}" }
- end
- end
-end
diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb
index 331f2373b..5a6074a30 100644
--- a/spec/models/procedure_spec.rb
+++ b/spec/models/procedure_spec.rb
@@ -1,57 +1,40 @@
require 'spec_helper'
describe Procedure do
- describe 'assocations' do
- it { is_expected.to have_many(:types_de_piece_justificative) }
- it { is_expected.to have_many(:types_de_champ) }
- it { is_expected.to have_many(:dossiers) }
- it { is_expected.to have_many(:mail_templates) }
- it { is_expected.to have_one(:module_api_carto) }
- it { is_expected.to belong_to(:administrateur) }
- it { is_expected.to have_many(:preference_list_dossiers) }
+
+ describe 'mails' do
+ it { expect(subject.initiated_mail).to be_a(Mails::InitiatedMail) }
+ it { expect(subject.received_mail).to be_a(Mails::ReceivedMail) }
+ it { expect(subject.closed_mail).to be_a(Mails::ClosedMail) }
+ it { expect(subject.refused_mail).to be_a(Mails::RefusedMail) }
+ it { expect(subject.without_continuation_mail).to be_a(Mails::WithoutContinuationMail) }
end
- describe 'attributes' do
- it { is_expected.to have_db_column(:libelle) }
- it { is_expected.to have_db_column(:description) }
- it { is_expected.to have_db_column(:organisation) }
- it { is_expected.to have_db_column(:direction) }
- it { is_expected.to have_db_column(:euro_flag) }
- it { is_expected.to have_db_column(:logo) }
- it { is_expected.to have_db_column(:logo_secure_token) }
- it { is_expected.to have_db_column(:cerfa_flag) }
- it { is_expected.to have_db_column(:published) }
+ describe 'initiated_mail' do
+ subject { create(:procedure) }
- describe 'mail_received' do
- let(:procedure) { create :procedure }
-
- before do
- create :mail_received, procedure: procedure
- end
-
- it { expect(procedure.mail_received).not_to be_nil }
+ context 'when initiated_mail is not customize' do
+ it { expect(subject.initiated_mail.body).to eq(Mails::InitiatedMail.default.body) }
end
- end
-
- describe '#build_default_mails' do
- subject { build :procedure, mail_templates: [] }
-
- it 'call the fonction build_default_mails' do
- expect(subject).to receive(:build_default_mails)
- subject.save
- end
-
- describe 'accessible values' do
-
- before do
+ context 'when initiated_mail is customize' do
+ before :each do
+ subject.initiated_mail = Mails::InitiatedMail.new(body: 'sisi')
subject.save
subject.reload
end
+ it { expect(subject.initiated_mail.body).to eq('sisi') }
+ end
- it { expect(subject.mail_templates.size).to eq 1 }
+ context 'when initiated_mail is customize ... again' do
+ before :each do
+ subject.initiated_mail = Mails::InitiatedMail.new(body: 'toto')
+ subject.save
+ subject.reload
+ end
+ it { expect(subject.initiated_mail.body).to eq('toto') }
- it { expect(subject.mail_received).not_to be_nil }
+ it { expect(Mails::InitiatedMail.count).to eq(1) }
end
end
@@ -160,17 +143,14 @@ describe Procedure do
describe 'clone' do
let(:archived) { false }
let(:published) { false }
- let(:procedure) { create(:procedure, archived: archived, published: published) }
+ let(:procedure) { create(:procedure, archived: archived, published: published, received_mail: received_mail) }
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
let!(:type_de_champ_private_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
let!(:type_de_champ_private_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
-
- before do
- procedure.mail_received.object = "Je vais être cloné"
- end
+ let(:received_mail){ create(:received_mail) }
subject { procedure.clone }
@@ -182,7 +162,6 @@ describe Procedure do
expect(subject.types_de_piece_justificative.size).to eq procedure.types_de_piece_justificative.size
expect(subject.types_de_champ.size).to eq procedure.types_de_champ.size
expect(subject.types_de_champ_private.size).to eq procedure.types_de_champ_private.size
- expect(subject.mail_templates.size).to eq procedure.mail_templates.size
subject.types_de_champ.zip(procedure.types_de_champ).each do |stc, ptc|
expect(stc).to have_same_attributes_as(ptc)
@@ -196,9 +175,22 @@ describe Procedure do
expect(stc).to have_same_attributes_as(ptc)
end
- subject.mail_templates.zip(procedure.mail_templates).each do |stc, ptc|
- expect(stc).to have_same_attributes_as(ptc)
- end
+ end
+
+ it 'should duplicate existing mail_templates' do
+ expect(subject.received_mail.attributes.except("id", "procedure_id", "created_at", "updated_at")).to eq procedure.received_mail.attributes.except("id", "procedure_id", "created_at", "updated_at")
+ expect(subject.received_mail.id).not_to eq procedure.received_mail.id
+ expect(subject.received_mail.id).not_to be nil
+ expect(subject.received_mail.procedure_id).not_to eq procedure.received_mail.procedure_id
+ expect(subject.received_mail.procedure_id).not_to be nil
+ expect(subject.received_mail.created_at).not_to eq procedure.received_mail.created_at
+ expect(subject.received_mail.created_at).not_to be nil
+ expect(subject.received_mail.updated_at).not_to eq procedure.received_mail.updated_at
+ expect(subject.received_mail.updated_at).not_to be nil
+ end
+
+ it 'should not duplicate default mail_template' do
+ expect(subject.initiated_mail.attributes).to eq Mails::InitiatedMail.default.attributes
end
it 'should not duplicate specific related objects' do