Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-09-01 10:43:57 +02:00
commit 69c45cfb99
4 changed files with 53 additions and 2 deletions

View file

@ -87,7 +87,7 @@ class Procedure < ActiveRecord::Base
end end
def clone 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.archived = false
procedure.published = false procedure.published = false
return procedure if procedure.save return procedure if procedure.save

View file

@ -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,
<br>
<br>
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.<br>
<br>
En vous souhaitant une bonne journée,
<br>
<br>
---
<br>
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

View file

@ -11,7 +11,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: 20160830142653) do ActiveRecord::Schema.define(version: 20160901082824) 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"

View file

@ -164,6 +164,11 @@ describe Procedure do
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!(: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) }
before do
procedure.mail_received.object = "Je vais être cloné"
end
subject { procedure.clone } subject { procedure.clone }
it 'should duplicate specific objects with different id' do 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).to have_same_attributes_as(procedure)
expect(subject.module_api_carto).to have_same_attributes_as(procedure.module_api_carto) 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| 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)
end end
@ -178,6 +184,10 @@ describe Procedure do
subject.types_de_piece_justificative.zip(procedure.types_de_piece_justificative).each do |stc, ptc| subject.types_de_piece_justificative.zip(procedure.types_de_piece_justificative).each do |stc, ptc|
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 end
it 'should not duplicate specific related objects' do it 'should not duplicate specific related objects' do