From 29bdd82b597838208533e5c7daef09e763ef2ed5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 16 Nov 2022 12:46:33 +0100 Subject: [PATCH] refactor(procedure): types_de_champ -> active_revision.types_de_champ_public --- .../procedure/card/champs_component.rb | 2 +- app/dashboards/procedure_dashboard.rb | 4 +- app/models/procedure.rb | 21 ++++------ app/serializers/procedure_serializer.rb | 6 ++- .../procedures/publication.html.haml | 4 +- config/locales/models/procedure/en.yml | 2 +- config/locales/models/procedure/fr.yml | 2 +- .../explication_component_spec.rb | 2 +- .../api/v1/procedures_controller_spec.rb | 2 +- .../api/v2/graphql_controller_spec.rb | 4 +- ...1_migrate_filters_to_use_stable_id_spec.rb | 2 +- spec/models/champ_spec.rb | 4 +- spec/models/dossier_rebase_concern_spec.rb | 12 +++--- spec/models/dossier_spec.rb | 16 ++++---- spec/models/procedure_presentation_spec.rb | 30 +++++++-------- spec/models/procedure_spec.rb | 38 +++++++++---------- spec/models/type_de_champ_spec.rb | 4 +- ...demarches_publiques_export_service_spec.rb | 4 +- .../dossier_projection_service_spec.rb | 12 +++--- .../services/procedure_export_service_spec.rb | 2 +- spec/system/accessibilite/wcag_usager_spec.rb | 2 +- .../administrateurs/types_de_champ_spec.rb | 8 ++-- .../instructeurs/procedure_filters_spec.rb | 2 +- 23 files changed, 91 insertions(+), 94 deletions(-) diff --git a/app/components/procedure/card/champs_component.rb b/app/components/procedure/card/champs_component.rb index 21acff9de..595d19464 100644 --- a/app/components/procedure/card/champs_component.rb +++ b/app/components/procedure/card/champs_component.rb @@ -12,7 +12,7 @@ class Procedure::Card::ChampsComponent < ApplicationComponent def error_messages [ - @procedure.errors.messages_for(:draft_types_de_champ), + @procedure.errors.messages_for(:draft_types_de_champ_public), @procedure.errors.messages_for(:draft_revision) ].flatten.to_sentence end diff --git a/app/dashboards/procedure_dashboard.rb b/app/dashboards/procedure_dashboard.rb index 1ba286f85..6a42f30fc 100644 --- a/app/dashboards/procedure_dashboard.rb +++ b/app/dashboards/procedure_dashboard.rb @@ -8,7 +8,7 @@ class ProcedureDashboard < Administrate::BaseDashboard # which determines how the attribute is displayed # on pages throughout the dashboard. ATTRIBUTE_TYPES = { - published_types_de_champ: TypesDeChampCollectionField, + published_types_de_champ_public: TypesDeChampCollectionField, published_types_de_champ_private: TypesDeChampCollectionField, path: ProcedureLinkField, dossiers: Field::HasMany, @@ -76,7 +76,7 @@ class ProcedureDashboard < Administrate::BaseDashboard :whitelisted_at, :hidden_at, :closed_at, - :published_types_de_champ, + :published_types_de_champ_public, :published_types_de_champ_private, :for_individual, :auto_archive_on, diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 353f8f7ec..7702df819 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -75,10 +75,11 @@ class Procedure < ApplicationRecord belongs_to :published_revision, class_name: 'ProcedureRevision', optional: true has_many :deleted_dossiers, dependent: :destroy - has_many :published_types_de_champ, through: :published_revision, source: :types_de_champ_public - has_many :published_types_de_champ_private, through: :published_revision, source: :types_de_champ_private - has_many :draft_types_de_champ, through: :draft_revision, source: :types_de_champ_public + has_many :draft_types_de_champ_public, through: :draft_revision, source: :types_de_champ_public has_many :draft_types_de_champ_private, through: :draft_revision, source: :types_de_champ_private + has_many :published_types_de_champ_public, through: :published_revision, source: :types_de_champ_public + has_many :published_types_de_champ_private, through: :published_revision, source: :types_de_champ_private + has_one :draft_attestation_template, through: :draft_revision, source: :attestation_template has_one :published_attestation_template, through: :published_revision, source: :attestation_template @@ -110,14 +111,6 @@ class Procedure < ApplicationRecord brouillon? ? draft_revision : published_revision end - def types_de_champ - brouillon? ? draft_types_de_champ : published_types_de_champ - end - - def types_de_champ_private - brouillon? ? draft_types_de_champ_private : published_types_de_champ_private - end - def types_de_champ_for_procedure_presentation(parent = nil) if brouillon? if parent.nil? @@ -269,7 +262,7 @@ class Procedure < ApplicationRecord validates :description, presence: true, allow_blank: false, allow_nil: false validates :administrateurs, presence: true validates :lien_site_web, presence: true, if: :publiee? - validates :draft_types_de_champ, + validates :draft_types_de_champ_public, 'types_de_champ/no_empty_block': true, 'types_de_champ/no_empty_drop_down': true, on: :publication @@ -535,7 +528,7 @@ class Procedure < ApplicationRecord end if is_different_admin || from_library - procedure.draft_types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) } + procedure.draft_revision.types_de_champ_public.each { |tdc| tdc.options&.delete(:old_pj) } end procedure @@ -860,7 +853,7 @@ class Procedure < ApplicationRecord children.each do |child| child.update!(parent: coordinates_by_stable_id.fetch(child.parent.stable_id)) end - new_draft.revision_types_de_champ.reload + new_draft.reload end def before_publish diff --git a/app/serializers/procedure_serializer.rb b/app/serializers/procedure_serializer.rb index 3ec46cb0d..755ec6b5c 100644 --- a/app/serializers/procedure_serializer.rb +++ b/app/serializers/procedure_serializer.rb @@ -48,7 +48,11 @@ class ProcedureSerializer < ActiveModel::Serializer end def types_de_champ - object.types_de_champ.reject { |c| c.old_pj.present? } + object.active_revision.types_de_champ_public.reject { |c| c.old_pj.present? } + end + + def types_de_champ_private + object.active_revision.types_de_champ_private end def types_de_piece_justificative diff --git a/app/views/administrateurs/procedures/publication.html.haml b/app/views/administrateurs/procedures/publication.html.haml index 4e9435c79..334e92c24 100644 --- a/app/views/administrateurs/procedures/publication.html.haml +++ b/app/views/administrateurs/procedures/publication.html.haml @@ -4,11 +4,11 @@ [@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)], ['Publication']] } .container - - if @procedure.draft_types_de_champ.dubious.present? + - if @procedure.draft_revision.types_de_champ_public.dubious.present? .card.warning.mb-3 .card-title Attention, certains champs ne peuvent être demandé par l'administration. Voici les champs qui nous semblent suspect : %ul - - @procedure.draft_types_de_champ.dubious.each do |dubious_champs| + - @procedure.draft_revision.types_de_champ_public.dubious.each do |dubious_champs| %li.dubious-champs= "#{dubious_champs.libelle} (#{dubious_champs.description})" .lien-demarche %h1 diff --git a/config/locales/models/procedure/en.yml b/config/locales/models/procedure/en.yml index 537fb3fdd..3bac7a8ad 100644 --- a/config/locales/models/procedure/en.yml +++ b/config/locales/models/procedure/en.yml @@ -31,7 +31,7 @@ en: attributes: api_particulier_token: invalid: 'invalid format' - draft_types_de_champ: + draft_types_de_champ_public: format: 'Public field %{message}' draft_types_de_champ_private: format: 'Private field %{message}' diff --git a/config/locales/models/procedure/fr.yml b/config/locales/models/procedure/fr.yml index a5293881c..c8e31b9ba 100644 --- a/config/locales/models/procedure/fr.yml +++ b/config/locales/models/procedure/fr.yml @@ -31,7 +31,7 @@ fr: attributes: api_particulier_token: invalid: 'n’a pas le bon format' - draft_types_de_champ: + draft_types_de_champ_public: format: 'Le champ %{message}' draft_types_de_champ_private: format: 'L’annotation privée %{message}' diff --git a/spec/components/types_de_champ_editor/explication_component_spec.rb b/spec/components/types_de_champ_editor/explication_component_spec.rb index 4a37ad881..ff0e28f67 100644 --- a/spec/components/types_de_champ_editor/explication_component_spec.rb +++ b/spec/components/types_de_champ_editor/explication_component_spec.rb @@ -2,7 +2,7 @@ describe TypesDeChampEditor::ChampComponent, type: :component do describe 'render by type' do context 'explication' do let(:procedure) { create(:procedure, :with_explication) } - let(:tdc) { procedure.types_de_champ.first } + let(:tdc) { procedure.active_revision.types_de_champ_public.first } let(:coordinate) { procedure.draft_revision.coordinate_for(tdc) } let(:component) { described_class.new(coordinate: coordinate, upper_coordinates: []) } diff --git a/spec/controllers/api/v1/procedures_controller_spec.rb b/spec/controllers/api/v1/procedures_controller_spec.rb index ab48cf54c..2f7e238da 100644 --- a/spec/controllers/api/v1/procedures_controller_spec.rb +++ b/spec/controllers/api/v1/procedures_controller_spec.rb @@ -43,7 +43,7 @@ describe API::V1::ProceduresController, type: :controller do describe 'type_de_champ' do subject { super()[:types_de_champ][0] } - let(:champ) { procedure.types_de_champ.first } + let(:champ) { procedure.active_revision.types_de_champ_public.first } it { expect(subject[:id]).to eq(champ.id) } it { expect(subject[:libelle]).to eq(champ.libelle) } diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index a947cc88d..5631679f5 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -148,7 +148,7 @@ describe API::V2::GraphqlController do draftRevision: { id: procedure.draft_revision.to_typed_id }, publishedRevision: { id: procedure.published_revision.to_typed_id, - champDescriptors: procedure.published_types_de_champ.map do |tdc| + champDescriptors: procedure.published_revision.types_de_champ_public.map do |tdc| { type: tdc.type_champ } @@ -159,7 +159,7 @@ describe API::V2::GraphqlController do typeOrganisme: procedure.service.type_organisme, organisme: procedure.service.organisme }, - champDescriptors: procedure.types_de_champ.map do |tdc| + champDescriptors: procedure.active_revision.types_de_champ_public.map do |tdc| { id: tdc.to_typed_id, label: tdc.libelle, diff --git a/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb b/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb index 02c51be49..0d6ecc683 100644 --- a/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb +++ b/spec/lib/tasks/deployment/20201001161931_migrate_filters_to_use_stable_id_spec.rb @@ -2,7 +2,7 @@ describe '20201001161931_migrate_filters_to_use_stable_id' do let(:rake_task) { Rake::Task['after_party:migrate_filters_to_use_stable_id'] } let(:procedure) { create(:procedure, :with_instructeur, :with_type_de_champ) } - let(:type_de_champ) { procedure.types_de_champ.first } + let(:type_de_champ) { procedure.active_revision.types_de_champ_public.first } let(:sort) do { "table" => "type_de_champ", diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index 13582c404..a5f3641d8 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -75,7 +75,7 @@ describe Champ do procedure.active_revision.add_type_de_champ( libelle: 'header', type_champ: 'header_section', - parent_stable_id: procedure.types_de_champ.find(&:repetition?).stable_id + parent_stable_id: procedure.active_revision.types_de_champ_public.find(&:repetition?).stable_id ) end end @@ -494,7 +494,7 @@ describe Champ do describe 'repetition' do let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, :with_repetition) } - let(:tdc_repetition) { procedure.types_de_champ.find(&:repetition?) } + let(:tdc_repetition) { procedure.active_revision.types_de_champ_public.find(&:repetition?) } let(:tdc_text) { procedure.active_revision.children_of(tdc_repetition).first } let(:dossier) { create(:dossier, procedure: procedure) } diff --git a/spec/models/dossier_rebase_concern_spec.rb b/spec/models/dossier_rebase_concern_spec.rb index 8487cce70..098cd8950 100644 --- a/spec/models/dossier_rebase_concern_spec.rb +++ b/spec/models/dossier_rebase_concern_spec.rb @@ -2,8 +2,8 @@ describe Dossier do describe '#can_rebase?' do let(:procedure) { create(:procedure, :with_type_de_champ_mandatory, :with_yes_no, attestation_template: build(:attestation_template)) } let(:attestation_template) { procedure.draft_revision.attestation_template.find_or_revise! } - let(:type_de_champ) { procedure.types_de_champ.find { |tdc| !tdc.mandatory? } } - let(:mandatory_type_de_champ) { procedure.types_de_champ.find(&:mandatory?) } + let(:type_de_champ) { procedure.active_revision.types_de_champ_public.find { |tdc| !tdc.mandatory? } } + let(:mandatory_type_de_champ) { procedure.active_revision.types_de_champ_public.find(&:mandatory?) } before { Flipper.enable(:procedure_revisions, procedure) } @@ -155,17 +155,17 @@ describe Dossier do let(:procedure) { create(:procedure, :with_type_de_champ_mandatory, :with_yes_no, :with_repetition, :with_datetime) } let(:dossier) { create(:dossier, procedure: procedure) } - let(:yes_no_type_de_champ) { procedure.types_de_champ.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } } + let(:yes_no_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } } - let(:text_type_de_champ) { procedure.types_de_champ.find(&:mandatory?) } + let(:text_type_de_champ) { procedure.active_revision.types_de_champ_public.find(&:mandatory?) } let(:text_champ) { dossier.champs_public.find(&:mandatory?) } let(:rebased_text_champ) { dossier.champs_public.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:text) } } - let(:datetime_type_de_champ) { procedure.types_de_champ.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } } + let(:datetime_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } } let(:datetime_champ) { dossier.champs_public.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } } let(:rebased_datetime_champ) { dossier.champs_public.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:date) } } - let(:repetition_type_de_champ) { procedure.types_de_champ.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } + let(:repetition_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } let(:repetition_text_type_de_champ) { procedure.active_revision.children_of(repetition_type_de_champ).find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:text) } } let(:repetition_champ) { dossier.champs_public.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } let(:rebased_repetition_champ) { dossier.champs_public.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 72c57f467..68f5739d8 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1485,12 +1485,12 @@ describe Dossier do describe "champs_for_export" do context 'with a unconditionnal procedure' do let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no, :with_explication, :with_commune, :with_repetition, zones: [create(:zone)]) } - let(:text_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } } - let(:yes_no_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } } - let(:datetime_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } } - let(:explication_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:explication) } } - let(:commune_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:communes) } } - let(:repetition_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } + let(:text_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } } + let(:yes_no_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } } + let(:datetime_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } } + let(:explication_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:explication) } } + let(:commune_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:communes) } } + let(:repetition_type_de_champ) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } } let(:repetition_champ) { dossier.champs_public.find(&:repetition?) } let(:repetition_second_revision_champ) { dossier_second_revision.champs_public.find(&:repetition?) } let(:dossier) { create(:dossier, procedure: procedure) } @@ -1554,8 +1554,8 @@ describe Dossier do let(:types_de_champ) { [{ type: :yes_no }, { type: :text }] } let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ) } let(:dossier) { create(:dossier, procedure:) } - let(:yes_no_tdc) { procedure.types_de_champ.first } - let(:text_tdc) { procedure.types_de_champ.second } + let(:yes_no_tdc) { procedure.active_revision.types_de_champ_public.first } + let(:text_tdc) { procedure.active_revision.types_de_champ_public.second } let(:tdcs) { dossier.champs_public.map(&:type_de_champ) } subject { Dossier.champs_for_export(dossier.champs_public, tdcs) } diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 41a81bd0a..4c75d1f62 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -2,7 +2,7 @@ describe ProcedurePresentation do let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) } let(:instructeur) { create(:instructeur) } let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) } - let(:first_type_de_champ) { assign_to.procedure.types_de_champ.first } + let(:first_type_de_champ) { assign_to.procedure.active_revision.types_de_champ_public.first } let(:first_type_de_champ_id) { first_type_de_champ.stable_id.to_s } let(:procedure_presentation) { create(:procedure_presentation, @@ -52,10 +52,10 @@ describe ProcedurePresentation do describe "#fields" do context 'when the procedure can have a SIRET number' do let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, types_de_champ_count: 4, types_de_champ_private_count: 4) } - let(:tdc_1) { procedure.types_de_champ[0] } - let(:tdc_2) { procedure.types_de_champ[1] } - let(:tdc_private_1) { procedure.types_de_champ_private[0] } - let(:tdc_private_2) { procedure.types_de_champ_private[1] } + let(:tdc_1) { procedure.active_revision.types_de_champ_public[0] } + let(:tdc_2) { procedure.active_revision.types_de_champ_public[1] } + let(:tdc_private_1) { procedure.active_revision.types_de_champ_private[0] } + let(:tdc_private_2) { procedure.active_revision.types_de_champ_private[1] } let(:expected) { [ { "label" => 'Créé le', "table" => 'self', "column" => 'created_at', 'classname' => '', 'virtual' => false, 'type' => :date, "scope" => '' }, @@ -90,10 +90,10 @@ describe ProcedurePresentation do } before do - procedure.types_de_champ[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section)) - procedure.types_de_champ[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication)) - procedure.types_de_champ_private[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section)) - procedure.types_de_champ_private[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication)) + procedure.active_revision.types_de_champ_public[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section)) + procedure.active_revision.types_de_champ_public[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication)) + procedure.active_revision.types_de_champ_private[2].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:header_section)) + procedure.active_revision.types_de_champ_private[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication)) end subject { create(:procedure_presentation, assign_to: assign_to) } @@ -225,7 +225,7 @@ describe ProcedurePresentation do context 'for type_de_champ table' do context 'with no revisions' do let(:table) { 'type_de_champ' } - let(:column) { procedure.types_de_champ.first.stable_id.to_s } + let(:column) { procedure.active_revision.types_de_champ_public.first.stable_id.to_s } let(:beurre_dossier) { create(:dossier, procedure: procedure) } let(:tartine_dossier) { create(:dossier, procedure: procedure) } @@ -251,7 +251,7 @@ describe ProcedurePresentation do context 'with a revision adding a new type_de_champ' do let!(:tdc) { { type_champ: :text, libelle: 'nouveau champ' } } let(:table) { 'type_de_champ' } - let(:column) { procedure.types_de_champ.last.stable_id.to_s } + let(:column) { procedure.active_revision.types_de_champ_public.last.stable_id.to_s } let(:nothing_dossier) { create(:dossier, procedure: procedure) } let(:beurre_dossier) { create(:dossier, procedure: procedure) } @@ -280,7 +280,7 @@ describe ProcedurePresentation do context 'for type_de_champ_private table' do context 'with no revisions' do let(:table) { 'type_de_champ_private' } - let(:column) { procedure.types_de_champ_private.first.stable_id.to_s } + let(:column) { procedure.active_revision.types_de_champ_private.first.stable_id.to_s } let(:biere_dossier) { create(:dossier, procedure: procedure) } let(:vin_dossier) { create(:dossier, procedure: procedure) } @@ -306,7 +306,7 @@ describe ProcedurePresentation do context 'with a revision adding a new type_de_champ' do let!(:tdc) { { type_champ: :text, private: true, libelle: 'nouveau champ' } } let(:table) { 'type_de_champ_private' } - let(:column) { procedure.types_de_champ_private.last.stable_id.to_s } + let(:column) { procedure.active_revision.types_de_champ_private.last.stable_id.to_s } let(:nothing_dossier) { create(:dossier, procedure: procedure) } let(:biere_dossier) { create(:dossier, procedure: procedure) } @@ -511,7 +511,7 @@ describe ProcedurePresentation do let(:kept_dossier) { create(:dossier, procedure: procedure) } let(:discarded_dossier) { create(:dossier, procedure: procedure) } - let(:type_de_champ) { procedure.types_de_champ.first } + let(:type_de_champ) { procedure.active_revision.types_de_champ_public.first } context 'with single value' do before do @@ -561,7 +561,7 @@ describe ProcedurePresentation do let(:kept_dossier) { create(:dossier, procedure: procedure) } let(:discarded_dossier) { create(:dossier, procedure: procedure) } - let(:type_de_champ_private) { procedure.types_de_champ_private.first } + let(:type_de_champ_private) { procedure.active_revision.types_de_champ_private.first } before do kept_dossier.champs_private.find_by(type_de_champ: type_de_champ_private).update(value: 'keep me') diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index f50d96a5b..b1d03a8e5 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -303,7 +303,7 @@ describe Procedure do end describe 'draft_types_de_champ validations' do - let(:repetition) { repetition = procedure.types_de_champ.find(&:repetition?) } + let(:repetition) { repetition = procedure.draft_revision.types_de_champ_public.find(&:repetition?) } let(:text_field) { build(:type_de_champ_text) } let(:invalid_repetition_error_message) { 'Le champ « Enfants » doit comporter au moins un champ répétable' } @@ -323,14 +323,14 @@ describe Procedure do context 'on a draft procedure' do it 'doesn’t validate the types de champs' do procedure.validate - expect(procedure.errors[:draft_types_de_champ]).not_to be_present + expect(procedure.errors[:draft_types_de_champ_public]).not_to be_present end end context 'when validating for publication' do it 'validates that no repetition type de champ is empty' do procedure.validate(:publication) - expect(procedure.errors.full_messages_for(:draft_types_de_champ)).to include(invalid_repetition_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).to include(invalid_repetition_error_message) new_draft = procedure.draft_revision @@ -338,16 +338,16 @@ describe Procedure do new_draft.revision_types_de_champ.create(type_de_champ: create(:type_de_champ), position: 0, parent: parent_coordinate) procedure.validate(:publication) - expect(procedure.errors.full_messages_for(:draft_types_de_champ)).not_to include(invalid_repetition_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).not_to include(invalid_repetition_error_message) end it 'validates that no drop-down type de champ is empty' do procedure.validate(:publication) - expect(procedure.errors.full_messages_for(:draft_types_de_champ)).to include(invalid_drop_down_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).to include(invalid_drop_down_error_message) drop_down.update!(drop_down_list_value: "--title--\r\nsome value") procedure.reload.validate(:publication) - expect(procedure.errors.full_messages_for(:draft_types_de_champ)).not_to include(invalid_drop_down_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ_public)).not_to include(invalid_drop_down_error_message) end end @@ -441,8 +441,8 @@ describe Procedure do api_particulier_token: '123456789012345', api_particulier_scopes: ['cnaf_famille']) end - let(:type_de_champ_repetition) { procedure.types_de_champ.last } - let(:type_de_champ_private_repetition) { procedure.types_de_champ_private.last } + let(:type_de_champ_repetition) { procedure.draft_revision.types_de_champ_public.last } + let(:type_de_champ_private_repetition) { procedure.draft_revision.types_de_champ_private.last } let(:received_mail) { build(:received_mail) } let(:from_library) { false } let(:opendata) { true } @@ -485,28 +485,28 @@ describe Procedure do it 'should duplicate specific objects with different id' do expect(subject.id).not_to eq(procedure.id) - expect(subject.draft_types_de_champ.size).to eq(procedure.draft_types_de_champ.size) - expect(subject.draft_types_de_champ_private.size).to eq(procedure.draft_types_de_champ_private.size) + expect(subject.draft_revision.types_de_champ_public.size).to eq(procedure.draft_revision.types_de_champ_public.size) + expect(subject.draft_revision.types_de_champ_private.size).to eq(procedure.draft_revision.types_de_champ_private.size) - procedure.draft_types_de_champ.zip(subject.draft_types_de_champ).each do |ptc, stc| + procedure.draft_revision.types_de_champ_public.zip(subject.draft_revision.types_de_champ_public).each do |ptc, stc| expect(stc).to have_same_attributes_as(ptc) expect(stc.revision).to eq(subject.draft_revision) end public_repetition = type_de_champ_repetition - cloned_public_repetition = subject.draft_types_de_champ.repetition.first + cloned_public_repetition = subject.draft_revision.types_de_champ_public.repetition.first procedure.draft_revision.children_of(public_repetition).zip(subject.draft_revision.children_of(cloned_public_repetition)).each do |ptc, stc| expect(stc).to have_same_attributes_as(ptc) expect(stc.revision).to eq(subject.draft_revision) end - procedure.draft_types_de_champ_private.zip(subject.draft_types_de_champ_private).each do |ptc, stc| + procedure.draft_revision.types_de_champ_private.zip(subject.draft_revision.types_de_champ_private).each do |ptc, stc| expect(stc).to have_same_attributes_as(ptc) expect(stc.revision).to eq(subject.draft_revision) end private_repetition = type_de_champ_private_repetition - cloned_private_repetition = subject.draft_types_de_champ_private.repetition.first + cloned_private_repetition = subject.draft_revision.types_de_champ_private.repetition.first procedure.draft_revision.children_of(private_repetition).zip(subject.draft_revision.children_of(cloned_private_repetition)).each do |ptc, stc| expect(stc).to have_same_attributes_as(ptc) expect(stc.revision).to eq(subject.draft_revision) @@ -540,7 +540,7 @@ describe Procedure do end it 'should discard old pj information' do - subject.draft_types_de_champ.each do |stc| + subject.draft_revision.types_de_champ_public.each do |stc| expect(stc.old_pj).to be_nil end end @@ -575,7 +575,7 @@ describe Procedure do end it 'should discard old pj information' do - subject.draft_types_de_champ.each do |stc| + subject.draft_revision.types_de_champ_public.each do |stc| expect(stc.old_pj).to be_nil end end @@ -645,12 +645,12 @@ describe Procedure do end it 'should keep types_de_champ ids stable' do - expect(subject.draft_types_de_champ.first.id).not_to eq(procedure.draft_types_de_champ.first.id) - expect(subject.draft_types_de_champ.first.stable_id).to eq(procedure.draft_types_de_champ.first.id) + expect(subject.draft_revision.types_de_champ_public.first.id).not_to eq(procedure.draft_revision.types_de_champ_public.first.id) + expect(subject.draft_revision.types_de_champ_public.first.stable_id).to eq(procedure.draft_revision.types_de_champ_public.first.id) end it 'should duplicate piece_justificative_template on a type_de_champ' do - expect(subject.draft_types_de_champ.where(type_champ: "piece_justificative").first.piece_justificative_template.attached?).to be true + expect(subject.draft_revision.types_de_champ_public.where(type_champ: "piece_justificative").first.piece_justificative_template.attached?).to be_truthy end context 'with a notice attached' do diff --git a/spec/models/type_de_champ_spec.rb b/spec/models/type_de_champ_spec.rb index 944add316..2b96be0cb 100644 --- a/spec/models/type_de_champ_spec.rb +++ b/spec/models/type_de_champ_spec.rb @@ -210,8 +210,8 @@ describe TypeDeChamp do let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) } it 'partition public and private' do - expect(procedure.types_de_champ.count).to eq(1) - expect(procedure.types_de_champ_private.count).to eq(1) + expect(procedure.active_revision.types_de_champ_public.count).to eq(1) + expect(procedure.active_revision.types_de_champ_private.count).to eq(1) end end diff --git a/spec/services/demarches_publiques_export_service_spec.rb b/spec/services/demarches_publiques_export_service_spec.rb index c83d7e060..3ad918ba3 100644 --- a/spec/services/demarches_publiques_export_service_spec.rb +++ b/spec/services/demarches_publiques_export_service_spec.rb @@ -23,8 +23,8 @@ describe DemarchesPubliquesExportService do revision: { champDescriptors: [ { - description: procedure.types_de_champ.first.description, - label: procedure.types_de_champ.first.libelle, + description: procedure.active_revision.types_de_champ_public.first.description, + label: procedure.active_revision.types_de_champ_public.first.libelle, options: nil, required: false, type: "text", diff --git a/spec/services/dossier_projection_service_spec.rb b/spec/services/dossier_projection_service_spec.rb index 7aeeae13b..fbf7efd24 100644 --- a/spec/services/dossier_projection_service_spec.rb +++ b/spec/services/dossier_projection_service_spec.rb @@ -13,7 +13,7 @@ describe DossierProjectionService do [ { "table" => "type_de_champ", - "column" => procedure.types_de_champ[0].stable_id.to_s + "column" => procedure.active_revision.types_de_champ_public[0].stable_id.to_s } ] end @@ -153,7 +153,7 @@ describe DossierProjectionService do context 'for type_de_champ table' do let(:table) { 'type_de_champ' } let(:dossier) { create(:dossier) } - let(:column) { dossier.procedure.types_de_champ.first.stable_id.to_s } + let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s } before { dossier.champs_public.first.update(value: 'kale') } @@ -163,7 +163,7 @@ describe DossierProjectionService do context 'for type_de_champ_private table' do let(:table) { 'type_de_champ_private' } let(:dossier) { create(:dossier) } - let(:column) { dossier.procedure.types_de_champ_private.first.stable_id.to_s } + let(:column) { dossier.procedure.active_revision.types_de_champ_private.first.stable_id.to_s } before { dossier.champs_private.first.update(value: 'quinoa') } @@ -174,7 +174,7 @@ describe DossierProjectionService do let(:table) { 'type_de_champ' } let(:procedure) { create(:procedure, :with_yes_no) } let(:dossier) { create(:dossier, procedure: procedure) } - let(:column) { dossier.procedure.types_de_champ.first.stable_id.to_s } + let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s } before { dossier.champs_public.first.update(value: 'true') } @@ -185,7 +185,7 @@ describe DossierProjectionService 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 } + let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s } before { dossier.champs_public.first.update(data: { 'label' => '18 a la bonne rue', 'departement' => 'd' }) } @@ -196,7 +196,7 @@ describe DossierProjectionService do let(:table) { 'type_de_champ' } let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :pays }]) } let(:dossier) { create(:dossier, procedure: procedure) } - let(:column) { dossier.procedure.types_de_champ.first.stable_id.to_s } + let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s } let!(:previous_locale) { I18n.locale } before { I18n.locale = :fr } diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index 8bcd085f5..040a7f84e 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -387,7 +387,7 @@ describe ProcedureExportService do context 'with long libelle composed of utf8 characteres' do before do - procedure.types_de_champ.each do |c| + procedure.active_revision.types_de_champ_public.each do |c| c.update!(libelle: "#{c.id} - ?/[] ééé ééé ééééééé ééééééé éééééééé. ééé éé éééééééé éé ééé. ééééé éééééééé ééé ééé.") end champ_repetition.champs.each do |c| diff --git a/spec/system/accessibilite/wcag_usager_spec.rb b/spec/system/accessibilite/wcag_usager_spec.rb index 4c355162c..f370a9986 100644 --- a/spec/system/accessibilite/wcag_usager_spec.rb +++ b/spec/system/accessibilite/wcag_usager_spec.rb @@ -4,7 +4,7 @@ describe 'wcag rules for usager', js: true do let(:litteraire_user) { create(:user, password: password) } before do - procedure.types_de_champ.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:carte) }.destroy + procedure.active_revision.types_de_champ_public.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:carte) }.destroy end context 'pages without the need to be logged in' do diff --git a/spec/system/administrateurs/types_de_champ_spec.rb b/spec/system/administrateurs/types_de_champ_spec.rb index 955785184..4adfc0c29 100644 --- a/spec/system/administrateurs/types_de_champ_spec.rb +++ b/spec/system/administrateurs/types_de_champ_spec.rb @@ -126,8 +126,8 @@ describe 'As an administrateur I can edit types de champ', js: true do fill_in 'Libellé du champ', with: 'Libellé de champ carte', fill_options: { clear: :backspace } check 'Cadastres' - wait_until { procedure.draft_types_de_champ.first.layer_enabled?(:cadastres) } - wait_until { procedure.draft_types_de_champ.first.libelle == 'Libellé de champ carte' } + wait_until { procedure.active_revision.types_de_champ_public.first.layer_enabled?(:cadastres) } + wait_until { procedure.active_revision.types_de_champ_public.first.libelle == 'Libellé de champ carte' } expect(page).to have_content('Formulaire enregistré') preview_window = window_opened_by { click_on 'Prévisualiser le formulaire' } @@ -147,8 +147,8 @@ describe 'As an administrateur I can edit types de champ', js: true do fill_in 'Options de la liste', with: 'Un menu', fill_options: { clear: :backspace } check "Proposer une option « autre » avec un texte libre" - wait_until { procedure.draft_types_de_champ.first.drop_down_list_options == ['', 'Un menu'] } - wait_until { procedure.draft_types_de_champ.first.drop_down_other == "1" } + wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_list_options == ['', 'Un menu'] } + wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_other == "1" } expect(page).to have_content('Formulaire enregistré') page.refresh diff --git a/spec/system/instructeurs/procedure_filters_spec.rb b/spec/system/instructeurs/procedure_filters_spec.rb index 7195cbb50..35bfd8c30 100644 --- a/spec/system/instructeurs/procedure_filters_spec.rb +++ b/spec/system/instructeurs/procedure_filters_spec.rb @@ -1,7 +1,7 @@ describe "procedure filters" do let(:instructeur) { create(:instructeur) } let(:procedure) { create(:procedure, :published, :with_type_de_champ, instructeurs: [instructeur]) } - let!(:type_de_champ) { procedure.types_de_champ.first } + let!(:type_de_champ) { procedure.active_revision.types_de_champ_public.first } let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) } let!(:champ) { Champ.find_by(type_de_champ_id: type_de_champ.id, dossier_id: new_unfollow_dossier.id) } let!(:new_unfollow_dossier_2) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }