Merge branch 'develop' into staging

This commit is contained in:
Simon Lehericey 2017-03-07 18:33:20 +01:00
commit a29a5a3513
50 changed files with 526 additions and 432 deletions

View file

@ -110,7 +110,7 @@ group :test do
gem 'poltergeist' gem 'poltergeist'
gem 'timecop' gem 'timecop'
gem 'guard' gem 'guard'
# gem 'guard-rspec', require: false gem 'guard-rspec', require: false
gem 'guard-livereload', '~> 2.4', require: false gem 'guard-livereload', '~> 2.4', require: false
gem 'vcr' gem 'vcr'
gem 'rails-controller-testing' gem 'rails-controller-testing'
@ -134,8 +134,8 @@ group :development, :test do
gem 'pry-byebug' gem 'pry-byebug'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
# gem 'spring' gem 'spring'
# gem 'spring-commands-rspec' gem 'spring-commands-rspec'
gem 'rspec-rails', '~> 3.0' gem 'rspec-rails', '~> 3.0'
gem 'railroady' gem 'railroady'

View file

@ -295,6 +295,10 @@ GEM
guard (~> 2.8) guard (~> 2.8)
guard-compat (~> 1.0) guard-compat (~> 1.0)
multi_json (~> 1.8) 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) haml (4.0.7)
tilt tilt
haml-rails (0.9.0) haml-rails (0.9.0)
@ -483,6 +487,10 @@ GEM
activesupport (>= 3.0, < 6.0) activesupport (>= 3.0, < 6.0)
builder (~> 3.0) builder (~> 3.0)
rubyzip (~> 1.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-core (3.5.4)
rspec-support (~> 3.5.0) rspec-support (~> 3.5.0)
rspec-expectations (3.5.0) rspec-expectations (3.5.0)
@ -557,6 +565,10 @@ GEM
spreadsheet_architect (1.4.8) spreadsheet_architect (1.4.8)
axlsx (>= 2.0) axlsx (>= 2.0)
rodf (= 0.3.7) 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) sprockets (3.7.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
@ -657,6 +669,7 @@ DEPENDENCIES
font-awesome-rails font-awesome-rails
guard guard
guard-livereload (~> 2.4) guard-livereload (~> 2.4)
guard-rspec
haml-rails haml-rails
hashie hashie
jbuilder (~> 2.0) jbuilder (~> 2.0)
@ -696,6 +709,8 @@ DEPENDENCIES
simplecov simplecov
smart_listing smart_listing
spreadsheet_architect spreadsheet_architect
spring
spring-commands-rspec
sqlite3 sqlite3
therubyracer therubyracer
timecop timecop

View file

@ -64,24 +64,24 @@ guard 'livereload' do
watch(%r{config/locales/.+\.yml}) watch(%r{config/locales/.+\.yml})
end end
# guard :rspec, cmd: 'bin/rspec' do guard :rspec, cmd: 'spring rspec' do
# watch(%r{^spec/.+_spec\.rb$}) watch(%r{^spec/.+_spec\.rb$})
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
# watch('spec/spec_helper.rb') { "spec" } watch('spec/spec_helper.rb') { "spec" }
#
# # Rails example # Rails example
# watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 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/(.*)(\.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{^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(%r{^spec/support/(.+)\.rb$}) { "spec" }
# watch('config/routes.rb') { "spec/routing" } watch('config/routes.rb') { "spec/routing" }
# watch('app/controllers/application_controller.rb') { "spec/controllers" } watch('app/controllers/application_controller.rb') { "spec/controllers" }
# watch('spec/rails_helper.rb') { "spec" } watch('spec/rails_helper.rb') { "spec" }
#
# # Capybara features specs # Capybara features specs
# watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" } watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
#
# # Turnip features and steps # Turnip features and steps
# watch(%r{^spec/acceptance/(.+)\.feature$}) watch(%r{^spec/acceptance/(.+)\.feature$})
# watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
# end end

View file

@ -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;
}
}

View file

@ -2,23 +2,35 @@ 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
%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 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

View file

@ -88,45 +88,53 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
def receive def receive
create_dossier_facade params[:dossier_id] create_dossier_facade params[:dossier_id]
@facade.dossier.received! dossier = @facade.dossier
dossier.received!
flash.notice = 'Dossier considéré comme reçu.' 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 end
def refuse def refuse
create_dossier_facade params[:dossier_id] 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é.' 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 end
def without_continuation def without_continuation
create_dossier_facade params[:dossier_id] 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.' 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 end
def close def close
create_dossier_facade params[:dossier_id] 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.' 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 end
def follow def follow

View file

@ -72,6 +72,7 @@ class Users::DescriptionController < UsersController
if mandatory if mandatory
if @dossier.draft? if @dossier.draft?
@dossier.initiated! @dossier.initiated!
NotificationMailer.send_notification(@dossier, @dossier.procedure.initiated_mail).deliver_now!
end end
flash.notice = 'Félicitations, votre demande a bien été enregistrée.' flash.notice = 'Félicitations, votre demande a bien été enregistrée.'

View file

@ -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

View file

@ -1,28 +1,20 @@
class NotificationMailer < ApplicationMailer 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 def new_answer dossier
send_mail dossier, "Nouveau message pour votre dossier TPS N°#{dossier.id}" send_mail dossier, "Nouveau message pour votre dossier TPS N°#{dossier.id}"
end 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 private
def vars_mailer dossier def vars_mailer dossier
@ -33,7 +25,6 @@ class NotificationMailer < ApplicationMailer
def send_mail dossier, subject def send_mail dossier, subject
vars_mailer dossier vars_mailer dossier
mail(from: "tps@apientreprise.fr", to: @user.email, mail(subject: subject)
subject: subject)
end end
end end

View file

@ -1,9 +1,9 @@
class MailTemplate < ActiveRecord::Base module MailTemplateConcern
extend ActiveSupport::Concern
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper include ActionView::Helpers::UrlHelper
belongs_to :procedure
TAGS = { TAGS = {
numero_dossier: { numero_dossier: {
description: "Permet d'afficher le numéro de dossier de l'utilisateur." description: "Permet d'afficher le numéro de dossier de l'utilisateur."
@ -30,6 +30,17 @@ class MailTemplate < ActiveRecord::Base
end end
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 private
def replace_tag tag, dossier def replace_tag tag, dossier
@ -37,7 +48,6 @@ class MailTemplate < ActiveRecord::Base
when :numero_dossier when :numero_dossier
dossier.id.to_s dossier.id.to_s
when :lien_dossier when :lien_dossier
# TPS::Application::URL # quickfix
link_to users_dossier_recapitulatif_url(dossier), users_dossier_recapitulatif_url(dossier), target: '_blank' link_to users_dossier_recapitulatif_url(dossier), users_dossier_recapitulatif_url(dossier), target: '_blank'
when :libelle_procedure when :libelle_procedure
dossier.procedure.libelle dossier.procedure.libelle

View file

@ -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,
<br>
<br>
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.<br>
<br>
En vous souhaitant une bonne journée,
<br>
<br>
---
<br>
L'équipe TPS"
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -3,8 +3,6 @@ class Procedure < ActiveRecord::Base
has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy
has_many :types_de_champ_private, dependent: :destroy has_many :types_de_champ_private, dependent: :destroy
has_many :dossiers has_many :dossiers
has_many :mail_templates
has_one :mail_received
has_one :procedure_path, dependent: :destroy 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 :libelle, presence: true, allow_blank: false, allow_nil: false
validates :description, 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 MAIL_TEMPLATE_TYPES = %w(InitiatedMail ReceivedMail ClosedMail RefusedMail WithoutContinuationMail)
MailReceived.create(procedure: self) unless mail_received
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 end
def path def path
@ -89,11 +100,22 @@ class Procedure < ActiveRecord::Base
end end
def clone 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.archived = false
procedure.published = false procedure.published = false
procedure.logo_secure_token = nil procedure.logo_secure_token = nil
procedure.remote_logo_url = self.logo_url 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 return procedure if procedure.save
end end

View file

@ -1,8 +1,11 @@
.white-back .white-back
%h3 %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 .row
.col-md-6 .col-md-6
= f.input :object, label: "Objet de l'email" = f.input :object, label: "Objet de l'email"
@ -19,7 +22,7 @@
Balise Balise
%th %th
Description Description
- MailTemplate::TAGS.each do |balise| - MailTemplateConcern::TAGS.each do |balise|
%tr %tr
%td.center %td.center
= "--#{balise.first}--" = "--#{balise.first}--"

View file

@ -1,15 +1,13 @@
.row.white-back #custom-mails
.wrapper
%h1 E-mails personnalisables %h1 E-mails personnalisables
.row
.col-md-6
%table.table %table.table
%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.decorate.name = mail.class.const_get(:DISPLAYED_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)

View file

@ -1,6 +1,6 @@
%div#main-container{class: "col-xs-#{main_container_size}"} #main-container{ class: "col-xs-#{main_container_size}" }
%div.row .row
= render partial: 'layouts/flash_messages' = render partial: 'layouts/flash_messages'
%div.row .row
= yield = yield
%div.row .row

View file

@ -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
\---

View file

@ -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
\---

View file

@ -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
\---

View file

@ -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
\---

View file

@ -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
\---

View file

@ -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

View file

@ -1 +0,0 @@
<%= @dossier.procedure.mail_received.body_for_dossier(@dossier).html_safe %>

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,6 @@
class DeleteAllMailValidatedInDb < ActiveRecord::Migration[5.0] class DeleteAllMailValidatedInDb < ActiveRecord::Migration[5.0]
def change 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
end end

View file

@ -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

View file

@ -1,8 +1,17 @@
class RemoveDepositDatetimeFromDossiers < ActiveRecord::Migration[5.0] class RemoveDepositDatetimeFromDossiers < ActiveRecord::Migration[5.0]
def change def change
remove_column :dossiers, :deposit_datetime, :datetime
end
def up
Dossier.where.not(deposit_datetime: nil).each do |dossier| Dossier.where.not(deposit_datetime: nil).each do |dossier|
dossier.update(initiated_at: dossier.deposit_datetime) dossier.update(initiated_at: dossier.deposit_datetime)
end 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
end end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

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: 20170302112312) do ActiveRecord::Schema.define(version: 20170307092820) 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"
@ -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 t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id", using: :btree
end 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| create_table "commentaires", force: :cascade do |t|
t.string "email" t.string "email"
t.datetime "created_at", null: false 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 t.index ["dossier_id"], name: "index_individuals_on_dossier_id", using: :btree
end 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| create_table "invites", force: :cascade do |t|
t.string "email" t.string "email"
t.string "email_sender" t.string "email_sender"
@ -336,6 +354,24 @@ ActiveRecord::Schema.define(version: 20170302112312) do
t.integer "dossier_id" t.integer "dossier_id"
end 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| create_table "rna_informations", force: :cascade do |t|
t.string "association_id" t.string "association_id"
t.string "titre" 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 t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end 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 "cerfas", "dossiers"
add_foreign_key "closed_mails", "procedures"
add_foreign_key "commentaires", "dossiers" add_foreign_key "commentaires", "dossiers"
add_foreign_key "dossiers", "users" add_foreign_key "dossiers", "users"
add_foreign_key "initiated_mails", "procedures"
add_foreign_key "procedure_paths", "administrateurs" add_foreign_key "procedure_paths", "administrateurs"
add_foreign_key "procedure_paths", "procedures" 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 create_view :searches, sql_definition: <<-SQL
SELECT dossiers.id AS dossier_id, SELECT dossiers.id AS dossier_id,

View file

@ -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) { Mails::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(Mails::InitiatedMail::DISPLAYED_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

View file

@ -230,7 +230,8 @@ describe Backoffice::DossiersController, type: :controller do
end end
it 'Notification email is send' do 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!) expect(NotificationMailer).to receive(:deliver_now!)
subject subject
@ -255,7 +256,8 @@ describe Backoffice::DossiersController, type: :controller do
end end
it 'Notification email is sent' do 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!) expect(NotificationMailer).to receive(:deliver_now!)
subject subject
@ -280,7 +282,8 @@ describe Backoffice::DossiersController, type: :controller do
end end
it 'Notification email is sent' do 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!) expect(NotificationMailer).to receive(:deliver_now!)
subject subject
@ -304,7 +307,8 @@ describe Backoffice::DossiersController, type: :controller do
end end
it 'Notification email is sent' do 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!) expect(NotificationMailer).to receive(:deliver_now!)
subject subject

View file

@ -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

View file

@ -9,7 +9,6 @@ FactoryGirl.define do
published false published false
cerfa_flag false cerfa_flag false
administrateur { create(:administrateur) } administrateur { create(:administrateur) }
mail_templates { [create(:mail_template, :dossier_received)]}
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
if procedure.module_api_carto.nil? if procedure.module_api_carto.nil?

View file

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

View file

@ -1,6 +1,16 @@
require "spec_helper" require "spec_helper"
RSpec.describe NotificationMailer, type: :mailer do 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 describe ".new_answer" do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: 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.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}") } it { expect(subject.subject).to eq("Nouveau message pour votre dossier TPS N°#{dossier.id}") }
end 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 end

View file

@ -1,7 +1,7 @@
class NotificationMailerPreview < ActionMailer::Preview class NotificationMailerPreview < ActionMailer::Preview
def dossier_received def send_notification
NotificationMailer.dossier_received(Dossier.last) NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail)
end end
end end

View file

@ -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

View file

@ -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 " +
"<a target=\"_blank\" href=\"http://localhost:3000/users/dossiers/1/recapitulatif\">http://localhost:3000/users/dossiers/1/recapitulatif</a>"
expect(initiated_mail.object_for_dossier(dossier)).to eq(expected)
end
end
end

View file

@ -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

View file

@ -1,57 +1,40 @@
require 'spec_helper' require 'spec_helper'
describe Procedure do describe Procedure do
describe 'assocations' do
it { is_expected.to have_many(:types_de_piece_justificative) } describe 'mails' do
it { is_expected.to have_many(:types_de_champ) } it { expect(subject.initiated_mail).to be_a(Mails::InitiatedMail) }
it { is_expected.to have_many(:dossiers) } it { expect(subject.received_mail).to be_a(Mails::ReceivedMail) }
it { is_expected.to have_many(:mail_templates) } it { expect(subject.closed_mail).to be_a(Mails::ClosedMail) }
it { is_expected.to have_one(:module_api_carto) } it { expect(subject.refused_mail).to be_a(Mails::RefusedMail) }
it { is_expected.to belong_to(:administrateur) } it { expect(subject.without_continuation_mail).to be_a(Mails::WithoutContinuationMail) }
it { is_expected.to have_many(:preference_list_dossiers) }
end end
describe 'attributes' do describe 'initiated_mail' do
it { is_expected.to have_db_column(:libelle) } subject { create(:procedure) }
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 'mail_received' do context 'when initiated_mail is not customize' do
let(:procedure) { create :procedure } it { expect(subject.initiated_mail.body).to eq(Mails::InitiatedMail.default.body) }
before do
create :mail_received, procedure: procedure
end end
it { expect(procedure.mail_received).not_to be_nil } context 'when initiated_mail is customize' do
end before :each do
subject.initiated_mail = Mails::InitiatedMail.new(body: 'sisi')
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
subject.save subject.save
subject.reload subject.reload
end 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
end end
@ -160,17 +143,14 @@ describe Procedure do
describe 'clone' do describe 'clone' do
let(:archived) { false } let(:archived) { false }
let(:published) { 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_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_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_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!(: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_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) } let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
let(:received_mail){ create(:received_mail) }
before do
procedure.mail_received.object = "Je vais être cloné"
end
subject { procedure.clone } 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_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.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.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| subject.types_de_champ.zip(procedure.types_de_champ).each do |stc, ptc|
expect(stc).to have_same_attributes_as(ptc) expect(stc).to have_same_attributes_as(ptc)
@ -196,9 +175,22 @@ describe Procedure do
expect(stc).to have_same_attributes_as(ptc) expect(stc).to have_same_attributes_as(ptc)
end 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 end
it 'should not duplicate specific related objects' do it 'should not duplicate specific related objects' do