types_de_champ_for_revision

This commit is contained in:
simon lehericey 2022-05-18 10:50:33 +02:00
parent 79fd90da75
commit 4d97f6aa8c
3 changed files with 9 additions and 9 deletions

View file

@ -307,7 +307,7 @@ class TypeDeChamp < ApplicationRecord
def types_de_champ_for_revision(revision) def types_de_champ_for_revision(revision)
if revision.draft? if revision.draft?
# if we are asking for children on a draft revision, just use current child types_de_champ # if we are asking for children on a draft revision, just use current child types_de_champ
types_de_champ.fillable revision.children_of(self).fillable
else else
# otherwise return all types_de_champ in their latest state # otherwise return all types_de_champ in their latest state
types_de_champ = TypeDeChamp types_de_champ = TypeDeChamp

View file

@ -190,12 +190,6 @@ FactoryBot.define do
end end
end end
trait :with_repetition_commune do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_repetition, types_de_champ: [build(:type_de_champ_communes)], procedure: procedure)
end
end
trait :with_number do trait :with_number do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
build(:type_de_champ_number, procedure: procedure) build(:type_de_champ_number, procedure: procedure)

View file

@ -1470,7 +1470,13 @@ describe Dossier do
context 'within a repetition having a type de champs commune (multiple values for export)' do context 'within a repetition having a type de champs commune (multiple values for export)' do
it 'works' do it 'works' do
proc_test = create(:procedure, :with_repetition_commune) proc_test = create(:procedure)
draft = proc_test.draft_revision
tdc_repetition = draft.add_type_de_champ(type_champ: :repetition, libelle: "repetition")
draft.add_type_de_champ(type_champ: :communes, libelle: "communes", parent_id: tdc_repetition.stable_id)
dossier_test = create(:dossier, procedure: proc_test) dossier_test = create(:dossier, procedure: proc_test)
repetition = proc_test.types_de_champ_for_procedure_presentation.repetition.first repetition = proc_test.types_de_champ_for_procedure_presentation.repetition.first
type_champs = repetition.types_de_champ_for_revision(proc_test.active_revision).to_a type_champs = repetition.types_de_champ_for_revision(proc_test.active_revision).to_a
@ -1734,7 +1740,7 @@ describe Dossier do
let(:rebased_datetime_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:date) } } let(:rebased_datetime_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:date) } }
let(:repetition_type_de_champ) { procedure.types_de_champ.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } let(:repetition_type_de_champ) { procedure.types_de_champ.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } }
let(:repetition_text_type_de_champ) { repetition_type_de_champ.types_de_champ.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:text) } } let(:repetition_text_type_de_champ) { procedure.active_revision.children_of(repetition_type_de_champ).find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:text) } }
let(:repetition_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } let(:repetition_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } }
let(:rebased_repetition_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } let(:rebased_repetition_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } }