Merge pull request #6215 from betagouv/main

2021-05-19-02
This commit is contained in:
LeSim 2021-05-19 16:21:18 +02:00 committed by GitHub
commit 9e39c561b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -33,7 +33,7 @@ class DossierProjectionService
types_de_champ: { stable_id: fields.map { |f| f[COLUMN] } }, types_de_champ: { stable_id: fields.map { |f| f[COLUMN] } },
dossier_id: dossiers_ids dossier_id: dossiers_ids
) )
.select(:dossier_id, :value, :type_de_champ_id, :stable_id, :type) # we cannot pluck :value, as we need the champ.to_s method .select(:dossier_id, :value, :type_de_champ_id, :stable_id, :type, :data) # we cannot pluck :value, as we need the champ.to_s method
.group_by(&:stable_id) # the champs are redispatched to their respective fields .group_by(&:stable_id) # the champs are redispatched to their respective fields
.map do |stable_id, champs| .map do |stable_id, champs|
field = fields.find { |f| f[COLUMN] == stable_id.to_s } field = fields.find { |f| f[COLUMN] == stable_id.to_s }

View file

@ -193,6 +193,12 @@ FactoryBot.define do
end end
end end
trait :with_address do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_address, procedure: procedure)
end
end
trait :with_explication do trait :with_explication do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
build(:type_de_champ_explication, procedure: procedure) build(:type_de_champ_explication, procedure: procedure)

View file

@ -173,6 +173,17 @@ describe DossierProjectionService do
it { is_expected.to eq('Oui') } it { is_expected.to eq('Oui') }
end end
context 'for type_de_champ table and value to.s which needs data field' do
let(:table) { 'type_de_champ' }
let(:procedure) { create(:procedure, :with_address) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:column) { dossier.procedure.types_de_champ.first.stable_id.to_s }
before { dossier.champs.first.update(data: { 'label' => '18 a la bonne rue', 'departement' => 'd' }) }
it { is_expected.to eq('18 a la bonne rue') }
end
end end
end end
end end