refactor(revision): rename find_or_clone_type_de_champ
This commit is contained in:
parent
6f98def288
commit
a36672239d
7 changed files with 25 additions and 25 deletions
|
@ -15,7 +15,7 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def update
|
||||
type_de_champ = @procedure.draft_revision.find_or_clone_type_de_champ(params[:id])
|
||||
type_de_champ = @procedure.draft_revision.find_and_ensure_exclusive_use(params[:id])
|
||||
|
||||
if type_de_champ.update(type_de_champ_update_params)
|
||||
reset_procedure
|
||||
|
|
|
@ -65,7 +65,7 @@ class ProcedureRevision < ApplicationRecord
|
|||
TypeDeChamp.new.tap { |tdc| tdc.errors.add(:base, e.message) }
|
||||
end
|
||||
|
||||
def find_or_clone_type_de_champ(stable_id)
|
||||
def find_and_ensure_exclusive_use(stable_id)
|
||||
coordinate, tdc = coordinate_and_tdc(stable_id)
|
||||
|
||||
if tdc.only_present_on_draft?
|
||||
|
|
|
@ -397,7 +397,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
|
||||
context 'when procedure has revisions' do
|
||||
let(:types_de_champ) { [build(:type_de_champ, libelle: 'mon ancien libellé')] }
|
||||
let(:draft_type_de_champ) { procedure.draft_revision.find_or_clone_type_de_champ(types_de_champ[0].stable_id) }
|
||||
let(:draft_type_de_champ) { procedure.draft_revision.find_and_ensure_exclusive_use(types_de_champ[0].stable_id) }
|
||||
|
||||
before do
|
||||
draft_type_de_champ.update(libelle: 'mon nouveau libellé')
|
||||
|
|
|
@ -34,7 +34,7 @@ describe Dossier do
|
|||
|
||||
context 'with type de champ made optional' do
|
||||
before do
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(mandatory_type_de_champ.stable_id).update(mandatory: false)
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(mandatory_type_de_champ.stable_id).update(mandatory: false)
|
||||
procedure.publish_revision!
|
||||
dossier.reload
|
||||
end
|
||||
|
@ -47,7 +47,7 @@ describe Dossier do
|
|||
|
||||
context 'with type de champ made mandatory' do
|
||||
before do
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(type_de_champ.stable_id).update(mandatory: true)
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(mandatory: true)
|
||||
procedure.publish_revision!
|
||||
dossier.reload
|
||||
end
|
||||
|
@ -138,7 +138,7 @@ describe Dossier do
|
|||
|
||||
context 'with type de champ made optional' do
|
||||
before do
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(mandatory_type_de_champ.stable_id).update(mandatory: false)
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(mandatory_type_de_champ.stable_id).update(mandatory: false)
|
||||
procedure.publish_revision!
|
||||
dossier.reload
|
||||
end
|
||||
|
@ -176,9 +176,9 @@ describe Dossier do
|
|||
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
||||
libelle: "Un champ text"
|
||||
})
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(text_type_de_champ).update(mandatory: false, libelle: "nouveau libelle")
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(datetime_type_de_champ).update(type_champ: TypeDeChamp.type_champs.fetch(:date))
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(repetition_text_type_de_champ).update(libelle: "nouveau libelle dans une repetition")
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(text_type_de_champ).update(mandatory: false, libelle: "nouveau libelle")
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(datetime_type_de_champ).update(type_champ: TypeDeChamp.type_champs.fetch(:date))
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(repetition_text_type_de_champ).update(libelle: "nouveau libelle dans une repetition")
|
||||
procedure.draft_revision.add_type_de_champ({
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:checkbox),
|
||||
libelle: "oui ou non",
|
||||
|
@ -247,7 +247,7 @@ describe Dossier do
|
|||
dossier.champs.first.update(value: 'v1')
|
||||
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
||||
tdc_to_update = procedure.draft_revision.find_or_clone_type_de_champ(stable_id)
|
||||
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
tdc_to_update.update(drop_down_list_value: 'option updated')
|
||||
end
|
||||
|
||||
|
@ -269,7 +269,7 @@ describe Dossier do
|
|||
dossier.champs.first.update(value: 'v1', geo_areas: [create(:geo_area, :cadastre)])
|
||||
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
||||
tdc_to_update = procedure.draft_revision.find_or_clone_type_de_champ(stable_id)
|
||||
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
tdc_to_update.update(cadastres: false)
|
||||
end
|
||||
|
||||
|
@ -301,7 +301,7 @@ describe Dossier do
|
|||
context 'when the first tdc is removed' do
|
||||
before do
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
||||
tdc_to_remove = procedure.draft_revision.find_or_clone_type_de_champ(stable_id)
|
||||
tdc_to_remove = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
procedure.draft_revision.remove_type_de_champ(tdc_to_remove.stable_id)
|
||||
end
|
||||
|
||||
|
@ -320,7 +320,7 @@ describe Dossier do
|
|||
context 'when the first tdc libelle is updated' do
|
||||
before do
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
||||
tdc_to_update = procedure.draft_revision.find_or_clone_type_de_champ(stable_id)
|
||||
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
tdc_to_update.update(libelle: 'l1 updated')
|
||||
end
|
||||
|
||||
|
@ -345,7 +345,7 @@ describe Dossier do
|
|||
first_champ.update_column('updated_at', Time.zone.parse('01/01/1901'))
|
||||
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
||||
tdc_to_update = procedure.draft_revision.find_or_clone_type_de_champ(stable_id)
|
||||
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
tdc_to_update.update(type_champ: :integer_number)
|
||||
end
|
||||
|
||||
|
@ -396,7 +396,7 @@ describe Dossier do
|
|||
context 'when the first child libelle tdc is updated' do
|
||||
before do
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'c1')
|
||||
tdc_to_update = procedure.draft_revision.find_or_clone_type_de_champ(stable_id)
|
||||
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
tdc_to_update.update(libelle: 'c1 updated')
|
||||
end
|
||||
|
||||
|
@ -406,7 +406,7 @@ describe Dossier do
|
|||
context 'when the first child tdc type is updated' do
|
||||
before do
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'c1')
|
||||
tdc_to_update = procedure.draft_revision.find_or_clone_type_de_champ(stable_id)
|
||||
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
tdc_to_update.update(type_champ: :integer_number)
|
||||
end
|
||||
|
||||
|
@ -416,7 +416,7 @@ describe Dossier do
|
|||
context 'when the parents type is changed' do
|
||||
before do
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'p1')
|
||||
parent = procedure.draft_revision.find_or_clone_type_de_champ(stable_id)
|
||||
parent = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
parent.update(type_champ: :integer_number)
|
||||
end
|
||||
|
||||
|
|
|
@ -1453,9 +1453,9 @@ describe Dossier do
|
|||
dossier
|
||||
procedure.draft_revision.remove_type_de_champ(text_type_de_champ.stable_id)
|
||||
procedure.draft_revision.add_type_de_champ(type_champ: TypeDeChamp.type_champs.fetch(:text), libelle: 'New text field')
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(yes_no_type_de_champ.stable_id).update(libelle: 'Updated yes/no')
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(commune_type_de_champ.stable_id).update(libelle: 'Commune de naissance')
|
||||
procedure.draft_revision.find_or_clone_type_de_champ(repetition_type_de_champ.stable_id).update(libelle: 'Repetition')
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(yes_no_type_de_champ.stable_id).update(libelle: 'Updated yes/no')
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(commune_type_de_champ.stable_id).update(libelle: 'Commune de naissance')
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(repetition_type_de_champ.stable_id).update(libelle: 'Repetition')
|
||||
procedure.update(published_revision: procedure.draft_revision, draft_revision: procedure.create_new_revision)
|
||||
dossier.reload
|
||||
procedure.reload
|
||||
|
|
|
@ -65,7 +65,7 @@ describe ProcedurePresentation do
|
|||
let!(:changed_tdc) { { type_champ: :number, libelle: 'changed libelle 1' } }
|
||||
|
||||
before do
|
||||
type_de_champ = procedure.draft_revision.find_or_clone_type_de_champ(previous_tdc.id)
|
||||
type_de_champ = procedure.draft_revision.find_and_ensure_exclusive_use(previous_tdc.id)
|
||||
type_de_champ.update(changed_tdc)
|
||||
|
||||
procedure.publish_revision!
|
||||
|
|
|
@ -284,7 +284,7 @@ describe ProcedureRevision do
|
|||
before do
|
||||
procedure.publish!
|
||||
procedure.reload
|
||||
draft.find_or_clone_type_de_champ(last_type_de_champ.stable_id).update(libelle: 'new libelle')
|
||||
draft.find_and_ensure_exclusive_use(last_type_de_champ.stable_id).update(libelle: 'new libelle')
|
||||
procedure.reload
|
||||
draft.reload
|
||||
end
|
||||
|
@ -330,7 +330,7 @@ describe ProcedureRevision do
|
|||
let(:procedure) { create(:procedure, :with_type_de_champ) }
|
||||
|
||||
before do
|
||||
updated_tdc = new_draft.find_or_clone_type_de_champ(first_tdc.stable_id)
|
||||
updated_tdc = new_draft.find_and_ensure_exclusive_use(first_tdc.stable_id)
|
||||
|
||||
updated_tdc.update(libelle: 'modifier le libelle', description: 'une description', mandatory: !updated_tdc.mandatory)
|
||||
end
|
||||
|
@ -431,7 +431,7 @@ describe ProcedureRevision do
|
|||
|
||||
before do
|
||||
child = new_draft.children_of(new_draft.types_de_champ_public.last).first
|
||||
new_draft.find_or_clone_type_de_champ(child.stable_id).update(type_champ: :drop_down_list, drop_down_options: ['one', 'two'])
|
||||
new_draft.find_and_ensure_exclusive_use(child.stable_id).update(type_champ: :drop_down_list, drop_down_options: ['one', 'two'])
|
||||
end
|
||||
|
||||
it do
|
||||
|
@ -465,7 +465,7 @@ describe ProcedureRevision do
|
|||
|
||||
before do
|
||||
child = new_draft.types_de_champ_public.last.types_de_champ.first
|
||||
new_draft.find_or_clone_type_de_champ(child.stable_id).update(type_champ: :carte, options: { cadastres: true, znieff: true })
|
||||
new_draft.find_and_ensure_exclusive_use(child.stable_id).update(type_champ: :carte, options: { cadastres: true, znieff: true })
|
||||
end
|
||||
|
||||
it do
|
||||
|
|
Loading…
Reference in a new issue