refactor(champ): more concistent champ_for_update usage

This commit is contained in:
Paul Chavard 2024-08-22 17:35:40 +02:00
parent 988025ba69
commit 54926db89b
No known key found for this signature in database
3 changed files with 8 additions and 6 deletions

View file

@ -9,7 +9,11 @@ class Champs::ChampController < ApplicationController
def find_champ def find_champ
dossier = policy_scope(Dossier).includes(:champs, revision: [:types_de_champ]).find(params[:dossier_id]) dossier = policy_scope(Dossier).includes(:champs, revision: [:types_de_champ]).find(params[:dossier_id])
type_de_champ = dossier.find_type_de_champ_by_stable_id(params[:stable_id]) type_de_champ = dossier.find_type_de_champ_by_stable_id(params[:stable_id])
dossier.champ_for_update(type_de_champ, params_row_id, updated_by: current_user.email) if type_de_champ.repetition?
dossier.project_champ(type_de_champ, nil)
else
dossier.champ_for_update(type_de_champ, params_row_id, updated_by: current_user.email)
end
end end
def params_row_id def params_row_id

View file

@ -57,7 +57,7 @@ module DossierChampsConcern
.types_de_champ .types_de_champ
.filter { _1.stable_id.in?(stable_ids) } .filter { _1.stable_id.in?(stable_ids) }
.filter { !revision.child?(_1) } .filter { !revision.child?(_1) }
.map { champ_for_update(_1, nil, updated_by: nil) } .map { _1.repetition? ? project_champ(_1, nil) : champ_for_update(_1, nil, updated_by: nil) }
end end
def champ_for_update(type_de_champ, row_id, updated_by:) def champ_for_update(type_de_champ, row_id, updated_by:)

View file

@ -38,10 +38,8 @@ describe DossierSearchableConcern do
end end
it "update columns en construction" do it "update columns en construction" do
dossier.update( dossier.update_champs_attributes({ champ_public.public_id => { value: 'nouvelle valeur publique' } }, :public, updated_by: 'test')
champs_public_attributes: [{ id: champ_public.id, value: 'nouvelle valeur publique' }], dossier.update_champs_attributes({ champ_private.public_id => { value: 'nouvelle valeur privee' } }, :private, updated_by: 'test')
champs_private_attributes: [{ id: champ_private.id, value: 'nouvelle valeur privee' }]
)
assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob) do assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob) do
dossier.passer_en_construction dossier.passer_en_construction