diff --git a/app/models/procedure.rb b/app/models/procedure.rb
index 0bef80a6c..a99204e3a 100644
--- a/app/models/procedure.rb
+++ b/app/models/procedure.rb
@@ -87,7 +87,7 @@ class Procedure < ActiveRecord::Base
end
def clone
- procedure = self.deep_clone(include: [:types_de_piece_justificative, :types_de_champ, :module_api_carto])
+ procedure = self.deep_clone(include: [:types_de_piece_justificative, :types_de_champ, :module_api_carto, :mail_templates])
procedure.archived = false
procedure.published = false
return procedure if procedure.save
diff --git a/db/migrate/20160901082824_initiated_all_received_mail_for_procedure.rb b/db/migrate/20160901082824_initiated_all_received_mail_for_procedure.rb
new file mode 100644
index 000000000..225745646
--- /dev/null
+++ b/db/migrate/20160901082824_initiated_all_received_mail_for_procedure.rb
@@ -0,0 +1,41 @@
+class InitiatedAllReceivedMailForProcedure < ActiveRecord::Migration
+ class Procedure < ActiveRecord::Base
+ has_one :mail_received
+ end
+
+ class MailTemplate < ActiveRecord::Base
+
+ end
+
+ 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élais légal déclaré par votre interlocuteur.
+
+ En vous souhaitant une bonne journée,
+
+
+ ---
+
+ L'équipe TPS"
+ end
+ end
+
+ def up
+ Procedure.all.each do |procedure|
+ procedure.mail_received ||= MailReceived.create(type: 'MailReceived')
+ procedure.save
+ end
+ end
+
+ def down
+ Procedure.all.each do |procedure|
+ procedure.mail_received.delete
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c377a367d..3b12345df 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160830142653) do
+ActiveRecord::Schema.define(version: 20160901082824) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb
index 4c67b4b9f..bd720b25a 100644
--- a/spec/models/procedure_spec.rb
+++ b/spec/models/procedure_spec.rb
@@ -164,6 +164,11 @@ describe Procedure do
let!(:type_de_champ_1) { create(:type_de_champ_public, 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
+
subject { procedure.clone }
it 'should duplicate specific objects with different id' do
@@ -171,6 +176,7 @@ describe Procedure do
expect(subject).to have_same_attributes_as(procedure)
expect(subject.module_api_carto).to have_same_attributes_as(procedure.module_api_carto)
+
subject.types_de_champ.zip(procedure.types_de_champ).each do |stc, ptc|
expect(stc).to have_same_attributes_as(ptc)
end
@@ -178,6 +184,10 @@ describe Procedure do
subject.types_de_piece_justificative.zip(procedure.types_de_piece_justificative).each do |stc, ptc|
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 not duplicate specific related objects' do