Merge pull request #8066 from tchak/refactor-procedure-types-de-champ

refactor(procedure): types_de_champ -> active_revision.types_de_champ_public
This commit is contained in:
Paul Chavard 2022-11-17 14:01:25 +01:00 committed by GitHub
commit d52bdd598c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 91 additions and 94 deletions

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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}'

View file

@ -31,7 +31,7 @@ fr:
attributes:
api_particulier_token:
invalid: 'na pas le bon format'
draft_types_de_champ:
draft_types_de_champ_public:
format: 'Le champ %{message}'
draft_types_de_champ_private:
format: 'Lannotation privée %{message}'

View file

@ -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: []) }

View file

@ -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) }

View file

@ -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,

View file

@ -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",

View file

@ -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) }

View file

@ -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) } }

View file

@ -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) }

View file

@ -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')

View file

@ -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 'doesnt 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

View file

@ -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

View file

@ -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",

View file

@ -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 }

View file

@ -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|

View file

@ -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

View file

@ -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

View file

@ -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)) }