From aeeb0dd22f4f25006f9d286fbfacda1c9878236f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 26 Jun 2017 17:18:47 +0200 Subject: [PATCH] =?UTF-8?q?[Fix=20#170]=20Keep=20drop=20down=20menu=20valu?= =?UTF-8?q?es=20for=20annot.=20priv=C3=A9es=20when=20cloning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/procedure.rb | 15 +++++++-------- spec/factories/drop_down_list.rb | 2 +- spec/factories/type_de_champ_private.rb | 6 ++++++ spec/factories/type_de_champ_public.rb | 6 ++++++ spec/models/procedure_spec.rb | 4 ++++ 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index c5a0ce236..8db90cdef 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -89,14 +89,13 @@ class Procedure < ActiveRecord::Base def clone procedure = self.deep_clone(include: - [ - :types_de_piece_justificative, - :types_de_champ, - :types_de_champ_private, - :module_api_carto, - :attestation_template, - types_de_champ: [:drop_down_list] - ]) + { + types_de_piece_justificative: nil, + module_api_carto: nil, + attestation_template: nil, + types_de_champ: :drop_down_list, + types_de_champ_private: :drop_down_list + }) procedure.archived = false procedure.published = false procedure.logo_secure_token = nil diff --git a/spec/factories/drop_down_list.rb b/spec/factories/drop_down_list.rb index 6b81511cf..0aeabf30d 100644 --- a/spec/factories/drop_down_list.rb +++ b/spec/factories/drop_down_list.rb @@ -1,5 +1,5 @@ FactoryGirl.define do factory :drop_down_list do - value '' + value "val1\r\nval2\r\n--separateur--\r\nval3" end end diff --git a/spec/factories/type_de_champ_private.rb b/spec/factories/type_de_champ_private.rb index 408279d05..356028d91 100644 --- a/spec/factories/type_de_champ_private.rb +++ b/spec/factories/type_de_champ_private.rb @@ -5,5 +5,11 @@ FactoryGirl.define do type_champ 'text' order_place 1 mandatory false + + trait :type_drop_down_list do + libelle 'Menu déroulant' + type_champ 'drop_down_list' + drop_down_list { create(:drop_down_list) } + end end end diff --git a/spec/factories/type_de_champ_public.rb b/spec/factories/type_de_champ_public.rb index e11b90e33..307ec2077 100644 --- a/spec/factories/type_de_champ_public.rb +++ b/spec/factories/type_de_champ_public.rb @@ -19,5 +19,11 @@ FactoryGirl.define do libelle 'Yes/no' type_champ 'yes_no' end + + trait :type_drop_down_list do + libelle 'Menu déroulant' + type_champ 'drop_down_list' + drop_down_list { create(:drop_down_list) } + end end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 88e3fbd16..69f15588a 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -147,8 +147,10 @@ describe Procedure do 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_2) { create(:type_de_champ_public, :type_drop_down_list, procedure: procedure, order_place: 2) } 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_2) { create(:type_de_champ_private, :type_drop_down_list, procedure: procedure, order_place: 2) } 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(:received_mail){ create(:received_mail) } @@ -174,6 +176,8 @@ 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.types_de_champ.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ.map(&:drop_down_list).compact.size + expect(subject.types_de_champ_private.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ_private.map(&:drop_down_list).compact.size subject.types_de_champ.zip(procedure.types_de_champ).each do |stc, ptc| expect(stc).to have_same_attributes_as(ptc)