diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 78f5f6bac..fbc1d9361 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -687,7 +687,7 @@ class TypeDeChamp < ApplicationRecord def champ_value(type_champ, champ) dynamic_type_class = type_champ_to_class_name(type_champ).constantize # special case for linked drop down champ – it's blank implementation is not what you think - if champ.blank? && (type_champ != TypeDeChamp.type_champs.fetch(:linked_drop_down_list) || champ.nil? || champ.value.blank?) + if (type_champ != TypeDeChamp.type_champs.fetch(:linked_drop_down_list) || champ.nil? || champ.value.blank?) && champ.blank? dynamic_type_class.champ_default_value else dynamic_type_class.champ_value(champ) @@ -697,7 +697,7 @@ class TypeDeChamp < ApplicationRecord def champ_value_for_api(type_champ, champ, version = 2) dynamic_type_class = type_champ_to_class_name(type_champ).constantize # special case for linked drop down champ – it's blank implementation is not what you think - if champ.blank? && (type_champ != TypeDeChamp.type_champs.fetch(:linked_drop_down_list) || champ.nil? || champ.value.blank?) + if (type_champ != TypeDeChamp.type_champs.fetch(:linked_drop_down_list) || champ.nil? || champ.value.blank?) && champ.blank? dynamic_type_class.champ_default_api_value(version) else dynamic_type_class.champ_value_for_api(champ, version) @@ -707,7 +707,7 @@ class TypeDeChamp < ApplicationRecord def champ_value_for_export(type_champ, champ, path = :value) dynamic_type_class = type_champ_to_class_name(type_champ).constantize # special case for linked drop down champ – it's blank implementation is not what you think - if champ.blank? && (type_champ != TypeDeChamp.type_champs.fetch(:linked_drop_down_list) || champ.nil? || champ.value.blank?) + if (type_champ != TypeDeChamp.type_champs.fetch(:linked_drop_down_list) || champ.nil? || champ.value.blank?) && champ.blank? dynamic_type_class.champ_default_export_value(path) else dynamic_type_class.champ_value_for_export(champ, path) @@ -717,7 +717,7 @@ class TypeDeChamp < ApplicationRecord def champ_value_for_tag(type_champ, champ, path = :value) dynamic_type_class = type_champ_to_class_name(type_champ).constantize # special case for linked drop down champ – it's blank implementation is not what you think - if champ.blank? && (type_champ != TypeDeChamp.type_champs.fetch(:linked_drop_down_list) || champ.nil? || champ.value.blank?) + if (type_champ != TypeDeChamp.type_champs.fetch(:linked_drop_down_list) || champ.nil? || champ.value.blank?) && champ.blank? '' else dynamic_type_class.champ_value_for_tag(champ, path) diff --git a/spec/services/dossier_projection_service_spec.rb b/spec/services/dossier_projection_service_spec.rb index 14865a971..278916762 100644 --- a/spec/services/dossier_projection_service_spec.rb +++ b/spec/services/dossier_projection_service_spec.rb @@ -3,23 +3,24 @@ describe DossierProjectionService do subject { described_class.project(dossiers_ids, fields) } context 'with multiple dossier' do - let!(:procedure) { create(:procedure, :with_type_de_champ) } + let!(:procedure) { create(:procedure, types_de_champ_public: [{}, { type: :linked_drop_down_list }]) } let!(:dossier_1) { create(:dossier, procedure: procedure) } let!(:dossier_2) { create(:dossier, :en_construction, :archived, procedure: procedure) } let!(:dossier_3) { create(:dossier, :en_instruction, procedure: procedure) } let(:dossiers_ids) { [dossier_3.id, dossier_1.id, dossier_2.id] } let(:fields) do - [ + procedure.active_revision.types_de_champ_public.map do |type_de_champ| { "table" => "type_de_champ", - "column" => procedure.active_revision.types_de_champ_public[0].stable_id.to_s + "column" => type_de_champ.stable_id.to_s } - ] + end end before do dossier_1.champs_public.first.update(value: 'champ_1') + dossier_1.champs_public.second.update(value: '["test"]') dossier_2.champs_public.first.update(value: 'champ_2') dossier_3.champs_public.first.destroy end