refactor(champ): more concistent champ_for_update usage

This commit is contained in:
Paul Chavard 2024-08-22 17:35:40 +02:00
parent f7cd7e615d
commit 1aee7ab1d2
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
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])
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
def params_row_id

View file

@ -57,7 +57,7 @@ module DossierChampsConcern
.types_de_champ
.filter { _1.stable_id.in?(stable_ids) }
.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
def champ_for_update(type_de_champ, row_id, updated_by:)

View file

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