[Fix #170] Keep drop down menu values for annot. privées when cloning

This commit is contained in:
gregoirenovel 2017-06-26 17:18:47 +02:00
parent e3cf1d373b
commit aeeb0dd22f
5 changed files with 24 additions and 9 deletions

View file

@ -89,14 +89,13 @@ class Procedure < ActiveRecord::Base
def clone def clone
procedure = self.deep_clone(include: procedure = self.deep_clone(include:
[ {
:types_de_piece_justificative, types_de_piece_justificative: nil,
:types_de_champ, module_api_carto: nil,
:types_de_champ_private, attestation_template: nil,
:module_api_carto, types_de_champ: :drop_down_list,
:attestation_template, types_de_champ_private: :drop_down_list
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

View file

@ -1,5 +1,5 @@
FactoryGirl.define do FactoryGirl.define do
factory :drop_down_list do factory :drop_down_list do
value '' value "val1\r\nval2\r\n--separateur--\r\nval3"
end end
end end

View file

@ -5,5 +5,11 @@ FactoryGirl.define do
type_champ 'text' type_champ 'text'
order_place 1 order_place 1
mandatory false 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
end end

View file

@ -19,5 +19,11 @@ FactoryGirl.define do
libelle 'Yes/no' libelle 'Yes/no'
type_champ 'yes_no' type_champ 'yes_no'
end 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
end end

View file

@ -147,8 +147,10 @@ describe Procedure do
let(:procedure) { create(:procedure, archived: archived, published: published, received_mail: received_mail) } 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_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_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!(: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_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) } 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_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.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| 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)