Merge pull request #10872 from tchak/refactor-explicit-default-champs

ETQ dev, je voudrais que les champs par défaut des dossiers soient créés explicitement. Moins de callbacks – moins de magie !
This commit is contained in:
Paul Chavard 2024-10-04 13:11:02 +00:00 committed by GitHub
commit 21b6974def
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 325 additions and 341 deletions

View file

@ -10,7 +10,6 @@ class Dossiers::ErrorsFullMessagesComponent < ApplicationComponent
def dedup_and_partitioned_errors
@dossier.errors.to_enum # ActiveModel::Errors.to_a is an alias to full_messages, we don't want that
.to_a # but enum.to_a gives back an array
.uniq { |error| [error.inner_error.base] } # dedup cumulated errors from dossier.champs, dossier.champs_public, dossier.champs_private which run the validator one time per association
.map { |error| to_error_descriptor(error) }
end

View file

@ -9,7 +9,7 @@ class API::Public::V1::DossiersController < API::Public::V1::BaseController
state: Dossier.states.fetch(:brouillon),
prefilled: true
)
dossier.build_default_individual
dossier.build_default_values
if dossier.save
dossier.prefill!(PrefillChamps.new(dossier, params.to_unsafe_h).to_a, PrefillIdentity.new(dossier, params.to_unsafe_h).to_h)
render json: serialize_dossier(dossier), status: :created

View file

@ -127,7 +127,7 @@ module Users
state: Dossier.states.fetch(:brouillon),
prefilled: true
)
@prefilled_dossier.build_default_individual
@prefilled_dossier.build_default_values
if @prefilled_dossier.save
@prefilled_dossier.prefill!(PrefillChamps.new(@prefilled_dossier, params.to_unsafe_h).to_a, PrefillIdentity.new(@prefilled_dossier, params.to_unsafe_h).to_h)
end

View file

@ -385,7 +385,7 @@ module Users
user: current_user,
state: Dossier.states.fetch(:brouillon)
)
dossier.build_default_individual
dossier.build_default_values
dossier.save!
DossierMailer.with(dossier:).notify_new_draft.deliver_later

View file

@ -23,7 +23,7 @@ class DossierDashboard < Administrate::BaseDashboard
en_construction_at: Field::DateTime,
en_instruction_at: Field::DateTime,
processed_at: Field::DateTime,
champs_public: ChampCollectionField,
project_champs_public: ChampCollectionField,
groupe_instructeur: Field::BelongsTo
}.freeze
@ -47,7 +47,7 @@ class DossierDashboard < Administrate::BaseDashboard
:state,
:procedure,
:groupe_instructeur,
:champs_public,
:project_champs_public,
:created_at,
:updated_at,
:hidden_by_user_at,

View file

@ -49,8 +49,6 @@ class Dossier < ApplicationRecord
# We have to remove champs in a particular order - champs with a reference to a parent have to be
# removed first, otherwise we get a foreign key constraint error.
has_many :champs_to_destroy, -> { order(:parent_id) }, class_name: 'Champ', inverse_of: false, dependent: :destroy
has_many :champs_public, -> { root.public_only }, class_name: 'Champ', inverse_of: false
has_many :champs_private, -> { root.private_only }, class_name: 'Champ', inverse_of: false
has_many :commentaires, inverse_of: :dossier, dependent: :destroy
has_many :preloaded_commentaires, -> { includes(:dossier_correction, piece_jointe_attachments: :blob) }, class_name: 'Commentaire', inverse_of: :dossier
@ -142,8 +140,6 @@ class Dossier < ApplicationRecord
after_destroy_commit :log_destroy
accepts_nested_attributes_for :champs
accepts_nested_attributes_for :champs_public
accepts_nested_attributes_for :champs_private
accepts_nested_attributes_for :individual
include AASM
@ -413,7 +409,6 @@ class Dossier < ApplicationRecord
delegate :siret, :siren, to: :etablissement, allow_nil: true
delegate :france_connected_with_one_identity?, to: :user, allow_nil: true
before_save :build_default_champs_for_new_dossier, if: Proc.new { revision_id_was.nil? && parent_dossier_id.nil? && editing_fork_origin_id.nil? }
after_save :send_web_hook
@ -471,29 +466,9 @@ class Dossier < ApplicationRecord
end
end
def build_default_champs_for_new_dossier
revision.build_champs_public(self).each do |champ|
champs_public << champ
end
revision.build_champs_private(self).each do |champ|
champs_private << champ
end
champs_public.filter { _1.repetition? && _1.mandatory? }.each do |champ|
champ.add_row(updated_by: nil)
end
champs_private.filter(&:repetition?).each do |champ|
champ.add_row(updated_by: nil)
end
end
def build_default_individual
if procedure.for_individual? && individual.blank?
self.individual = if france_connected_with_one_identity?
Individual.from_france_connect(user.france_connect_informations.first)
else
Individual.new
end
end
def build_default_values
build_default_individual
build_default_champs
end
def en_construction_ou_instruction?
@ -1176,6 +1151,33 @@ class Dossier < ApplicationRecord
private
def build_default_champs
build_default_champs_for(revision.types_de_champ_public) if !champs.any?(&:public?)
build_default_champs_for(revision.types_de_champ_private) if !champs.any?(&:private?)
end
def build_default_champs_for(types_de_champ)
self.champs << types_de_champ.flat_map do |type_de_champ|
if type_de_champ.repetition? && (type_de_champ.private? || type_de_champ.mandatory?)
row_id = ULID.generate
parent = type_de_champ.build_champ(dossier: self)
[parent] + revision.children_of(type_de_champ).map { _1.build_champ(dossier: self, parent:, row_id:) }
else
type_de_champ.build_champ(dossier: self)
end
end
end
def build_default_individual
if procedure.for_individual? && individual.blank?
self.individual = if france_connected_with_one_identity?
Individual.from_france_connect(user.france_connect_informations.first)
else
Individual.new
end
end
end
def create_missing_traitemets
if en_construction_at.present? && traitements.en_construction.empty?
self.traitements.passer_en_construction(processed_at: en_construction_at)

View file

@ -39,7 +39,7 @@ class DossierPreloader
def revisions(pj_template: false)
@revisions ||= ProcedureRevision.where(id: @dossiers.pluck(:revision_id).uniq)
.includes(types_de_champ: pj_template ? { piece_justificative_template_attachment: :blob } : [])
.includes(types_de_champ_public: [], types_de_champ_private: [], types_de_champ: pj_template ? { piece_justificative_template_attachment: :blob } : [])
.index_by(&:id)
end
@ -80,8 +80,6 @@ class DossierPreloader
dossier.association(:revision).target = revision
end
dossier.association(:champs).target = champs
dossier.association(:champs_public).target = dossier.project_champs_public
dossier.association(:champs_private).target = dossier.project_champs_private
# remove once parent_id is deprecated
champs_by_parent_id = champs.group_by(&:parent_id)

View file

@ -37,16 +37,6 @@ class ProcedureRevision < ApplicationRecord
serialize :ineligibilite_rules, LogicSerializer
def build_champs_public(dossier)
# reload: it can be out of sync in test if some tdcs are added wihtout using add_tdc
types_de_champ_public.reload.map { _1.build_champ(dossier:) }
end
def build_champs_private(dossier)
# reload: it can be out of sync in test if some tdcs are added wihtout using add_tdc
types_de_champ_private.reload.map { _1.build_champ(dossier:) }
end
def add_type_de_champ(params)
parent_stable_id = params.delete(:parent_stable_id)
parent_coordinate, _ = coordinate_and_tdc(parent_stable_id)
@ -172,7 +162,7 @@ class ProcedureRevision < ApplicationRecord
.find_or_initialize_by(revision: self, user: user, for_procedure_preview: true, state: Dossier.states.fetch(:brouillon))
if dossier.new_record?
dossier.build_default_individual
dossier.build_default_values
dossier.save!
end

View file

@ -7,11 +7,11 @@ module Maintenance
end
def process(cloned_dossier)
cloned_dossier.champs_private
cloned_dossier.project_champs_private
.filter { checkable_pj?(_1, cloned_dossier) }
.map do |cloned_champ|
parent_champ = cloned_dossier.parent_dossier
.champs_private
.project_champs_private
.find { _1.stable_id == cloned_champ.stable_id }
next if !parent_champ

View file

@ -21,7 +21,7 @@ RSpec.describe Dossiers::EnConstructionNotSubmittedComponent, type: :component d
end
context "with changes" do
before { fork.champs_public.first.update(value: "new value") }
before { fork.project_champs_public.first.update(value: "new value") }
it "inform user" do
expect(subject).to include("Des modifications nont pas encore été déposées")

View file

@ -113,7 +113,7 @@ describe EditableChamp::SectionComponent, type: :component do
end
it 'contains as many text champ as repetition.rows' do
expect(page).to have_selector("fieldset fieldset input[type=text]", count: dossier.champs_public.find(&:repetition?).rows.size)
expect(page).to have_selector("fieldset fieldset input[type=text]", count: dossier.project_champs_public.find(&:repetition?).rows.size)
end
end

View file

@ -515,7 +515,7 @@ describe API::V2::GraphqlController do
avis: []
)
expected_champs = dossier.champs_public.map do |champ|
expected_champs = dossier.project_champs_public.map do |champ|
{
id: champ.to_typed_id,
label: champ.libelle,
@ -546,7 +546,7 @@ describe API::V2::GraphqlController do
end
expect(gql_data[:dossier][:messages]).to match_array(expected_messages)
expect(gql_data[:dossier][:champs][0][:id]).to eq(dossier.champs_public[0].type_de_champ.to_typed_id)
expect(gql_data[:dossier][:champs][0][:id]).to eq(dossier.project_champs_public[0].type_de_champ.to_typed_id)
end
end
@ -687,8 +687,8 @@ describe API::V2::GraphqlController do
context "champs" do
let(:procedure) { create(:procedure, :published, :for_individual, administrateurs: [admin], types_de_champ_public: [{ type: :date }, { type: :datetime }]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:champ_date) { dossier.champs_public.first }
let(:champ_datetime) { dossier.champs_public.second }
let(:champ_date) { dossier.project_champs_public.first }
let(:champ_datetime) { dossier.project_champs_public.second }
before do
champ_date.update(value: '2019-07-10')
@ -1243,7 +1243,7 @@ describe API::V2::GraphqlController do
"mutation {
dossierModifierAnnotationText(input: {
dossierId: \"#{dossier.to_typed_id}\",
annotationId: \"#{dossier.champs_private.find { |c| c.type == 'Champs::TextChamp' }.to_typed_id}\",
annotationId: \"#{dossier.project_champs_private.find { |c| c.type == 'Champs::TextChamp' }.to_typed_id}\",
instructeurId: \"#{instructeur.to_typed_id}\",
value: \"hello\"
}) {
@ -1280,7 +1280,7 @@ describe API::V2::GraphqlController do
"mutation {
dossierModifierAnnotationCheckbox(input: {
dossierId: \"#{dossier.to_typed_id}\",
annotationId: \"#{dossier.champs_private.find { |c| c.type_champ == 'checkbox' }.to_typed_id}\",
annotationId: \"#{dossier.project_champs_private.find { |c| c.type_champ == 'checkbox' }.to_typed_id}\",
instructeurId: \"#{instructeur.to_typed_id}\",
value: #{value}
}) {
@ -1331,7 +1331,7 @@ describe API::V2::GraphqlController do
"mutation {
dossierModifierAnnotationCheckbox(input: {
dossierId: \"#{dossier.to_typed_id}\",
annotationId: \"#{dossier.champs_private.find { |c| c.type_champ == 'yes_no' }.to_typed_id}\",
annotationId: \"#{dossier.project_champs_private.find { |c| c.type_champ == 'yes_no' }.to_typed_id}\",
instructeurId: \"#{instructeur.to_typed_id}\",
value: #{value}
}) {
@ -1381,7 +1381,7 @@ describe API::V2::GraphqlController do
"mutation {
dossierModifierAnnotationDate(input: {
dossierId: \"#{dossier.to_typed_id}\",
annotationId: \"#{dossier.champs_private.find { |c| c.type_champ == 'date' }.to_typed_id}\",
annotationId: \"#{dossier.project_champs_private.find { |c| c.type_champ == 'date' }.to_typed_id}\",
instructeurId: \"#{instructeur.to_typed_id}\",
value: \"#{1.day.from_now.to_date.iso8601}\"
}) {
@ -1401,7 +1401,7 @@ describe API::V2::GraphqlController do
expect(gql_data).to eq(dossierModifierAnnotationDate: {
annotation: {
stringValue: dossier.reload.champs_private.find { |c| c.type_champ == 'date' }.to_s
stringValue: dossier.reload.project_champs_private.find { |c| c.type_champ == 'date' }.to_s
},
errors: nil
})
@ -1416,7 +1416,7 @@ describe API::V2::GraphqlController do
"mutation {
dossierModifierAnnotationDatetime(input: {
dossierId: \"#{dossier.to_typed_id}\",
annotationId: \"#{dossier.champs_private.find { |c| c.type_champ == 'datetime' }.to_typed_id}\",
annotationId: \"#{dossier.project_champs_private.find { |c| c.type_champ == 'datetime' }.to_typed_id}\",
instructeurId: \"#{instructeur.to_typed_id}\",
value: \"#{1.day.from_now.iso8601}\"
}) {
@ -1436,7 +1436,7 @@ describe API::V2::GraphqlController do
expect(gql_data).to eq(dossierModifierAnnotationDatetime: {
annotation: {
stringValue: dossier.reload.champs_private.find { |c| c.type_champ == 'datetime' }.to_s
stringValue: dossier.reload.project_champs_private.find { |c| c.type_champ == 'datetime' }.to_s
},
errors: nil
})
@ -1451,7 +1451,7 @@ describe API::V2::GraphqlController do
"mutation {
dossierModifierAnnotationDropDownList(input: {
dossierId: \"#{dossier.to_typed_id}\",
annotationId: \"#{dossier.champs_private.find { |c| c.type_champ == 'drop_down_list' }.to_typed_id}\",
annotationId: \"#{dossier.project_champs_private.find { |c| c.type_champ == 'drop_down_list' }.to_typed_id}\",
instructeurId: \"#{instructeur.to_typed_id}\",
value: \"#{value}\"
}) {
@ -1472,7 +1472,7 @@ describe API::V2::GraphqlController do
expect(gql_data).to eq(dossierModifierAnnotationDropDownList: {
annotation: {
stringValue: dossier.reload.champs_private.find { |c| c.type_champ == 'drop_down_list' }.to_s
stringValue: dossier.reload.project_champs_private.find { |c| c.type_champ == 'drop_down_list' }.to_s
},
errors: nil
})
@ -1497,7 +1497,7 @@ describe API::V2::GraphqlController do
"mutation {
dossierModifierAnnotationIntegerNumber(input: {
dossierId: \"#{dossier.to_typed_id}\",
annotationId: \"#{dossier.champs_private.find { |c| c.type_champ == 'integer_number' }.to_typed_id}\",
annotationId: \"#{dossier.project_champs_private.find { |c| c.type_champ == 'integer_number' }.to_typed_id}\",
instructeurId: \"#{instructeur.to_typed_id}\",
value: 42
}) {

View file

@ -4,7 +4,7 @@ describe Champs::PieceJustificativeController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }]) }
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
let(:champ) { dossier.champs_public.first }
let(:champ) { dossier.project_champs_public.first }
describe '#update' do
render_views

View file

@ -6,7 +6,7 @@ describe Champs::RNAController, type: :controller do
describe '#show' do
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
let(:champ) { dossier.champs_public.first }
let(:champ) { dossier.project_champs_public.first }
let(:champs_public_attributes) do
champ_attributes = {}

View file

@ -6,7 +6,7 @@ describe Champs::SiretController, type: :controller do
describe '#show' do
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
let(:champ) { dossier.champs_public.first }
let(:champ) { dossier.project_champs_public.first }
let(:champs_public_attributes) do
champ_attributes = {}

View file

@ -483,7 +483,7 @@ describe Experts::AvisController, type: :controller do
context 'when the expert also shares the linked dossiers' do
context 'and the expert can access the linked dossiers' do
let(:created_avis) { create(:avis, dossier: dossier, claimant: claimant, email: "toto3@gmail.com") }
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs_public.filter(&:dossier_link?).filter_map(&:value)) }
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.project_champs_public.filter(&:dossier_link?).filter_map(&:value)) }
let(:linked_avis) { create(:avis, dossier: linked_dossier, claimant: claimant) }
let(:invite_linked_dossiers) { true }

View file

@ -978,11 +978,11 @@ describe Instructeurs::DossiersController, type: :controller do
let(:another_instructeur) { create(:instructeur) }
let(:now) { Time.zone.parse('01/01/2100') }
let(:champ_multiple_drop_down_list) { dossier.champs_private.first }
let(:champ_linked_drop_down_list) { dossier.champs_private.second }
let(:champ_datetime) { dossier.champs_private.third }
let(:champ_repetition) { dossier.champs_private.fourth }
let(:champ_drop_down_list) { dossier.champs_private.fifth }
let(:champ_multiple_drop_down_list) { dossier.project_champs_private.first }
let(:champ_linked_drop_down_list) { dossier.project_champs_private.second }
let(:champ_datetime) { dossier.project_champs_private.third }
let(:champ_repetition) { dossier.project_champs_private.fourth }
let(:champ_drop_down_list) { dossier.project_champs_private.fifth }
context 'when no invalid champs_public' do
context "with new values for champs_private" do
@ -1106,7 +1106,7 @@ describe Instructeurs::DossiersController, type: :controller do
]
end
let(:champ_decimal_number) { dossier.champs_public.first }
let(:champ_decimal_number) { dossier.project_champs_public.first }
let(:params) do
{

View file

@ -18,16 +18,16 @@ describe RechercheController, type: :controller do
before do
instructeur.assign_to_procedure(dossier.procedure)
dossier.champs_public[0].value = "Name of district A"
dossier.champs_public[1].value = "Name of city A"
dossier.champs_private[0].value = "Dossier A is complete"
dossier.champs_private[1].value = "Dossier A is valid"
dossier.project_champs_public[0].value = "Name of district A"
dossier.project_champs_public[1].value = "Name of city A"
dossier.project_champs_private[0].value = "Dossier A is complete"
dossier.project_champs_private[1].value = "Dossier A is valid"
dossier.save!
dossier_with_expert.champs_public[0].value = "Name of district B"
dossier_with_expert.champs_public[1].value = "name of city B"
dossier_with_expert.champs_private[0].value = "Dossier B is incomplete"
dossier_with_expert.champs_private[1].value = "Dossier B is invalid"
dossier_with_expert.project_champs_public[0].value = "Name of district B"
dossier_with_expert.project_champs_public[1].value = "name of city B"
dossier_with_expert.project_champs_private[0].value = "Dossier B is incomplete"
dossier_with_expert.project_champs_private[1].value = "Dossier B is invalid"
dossier_with_expert.save!
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)

View file

@ -412,7 +412,7 @@ describe Users::DossiersController, type: :controller do
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
let(:types_de_champ_public) { [{ type: :text, mandatory: false }] }
let!(:dossier) { create(:dossier, user:, procedure:) }
let(:first_champ) { dossier.champs_public.first }
let(:first_champ) { dossier.project_champs_public.first }
let(:anchor_to_first_champ) { controller.helpers.link_to first_champ.libelle, brouillon_dossier_path(anchor: first_champ.labelledby_id), class: 'error-anchor' }
let(:value) { 'beautiful value' }
let(:now) { Time.zone.parse('01/01/2100') }
@ -529,7 +529,7 @@ describe Users::DossiersController, type: :controller do
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
let(:types_de_champ_public) { [{ type: :text, mandatory: false }] }
let(:dossier) { create(:dossier, :en_construction, procedure:, user:) }
let(:first_champ) { dossier.owner_editing_fork.champs_public.first }
let(:first_champ) { dossier.owner_editing_fork.project_champs_public.first }
let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), modifier_dossier_path(anchor: first_champ.labelledby_id), class: 'error-anchor' }
let(:value) { 'beautiful value' }
let(:now) { Time.zone.parse('01/01/2100') }
@ -677,8 +677,8 @@ describe Users::DossiersController, type: :controller do
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
let(:types_de_champ_public) { [{}, { type: :piece_justificative, mandatory: false }] }
let(:dossier) { create(:dossier, user:, procedure:) }
let(:first_champ) { dossier.champs_public.first }
let(:piece_justificative_champ) { dossier.champs_public.last }
let(:first_champ) { dossier.project_champs_public.first }
let(:piece_justificative_champ) { dossier.project_champs_public.last }
let(:value) { 'beautiful value' }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
let(:now) { Time.zone.parse('01/01/2100') }
@ -773,8 +773,8 @@ describe Users::DossiersController, type: :controller do
render_views
let(:types_de_champ_public) { [{ type: :text }, { type: :integer_number }] }
let(:text_champ) { dossier.champs_public.first }
let(:number_champ) { dossier.champs_public.last }
let(:text_champ) { dossier.project_champs_public.first }
let(:number_champ) { dossier.project_champs_public.last }
let(:submit_payload) do
{
id: dossier.id,
@ -837,9 +837,9 @@ describe Users::DossiersController, type: :controller do
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{}, { type: :piece_justificative }]) }
let!(:dossier) { create(:dossier, :en_construction, user:, procedure:) }
let(:first_champ) { dossier.champs_public.first }
let(:first_champ) { dossier.project_champs_public.first }
let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), brouillon_dossier_path(anchor: first_champ.labelledby_id), class: 'error-anchor' }
let(:piece_justificative_champ) { dossier.champs_public.last }
let(:piece_justificative_champ) { dossier.project_champs_public.last }
let(:value) { 'beautiful value' }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
let(:now) { Time.zone.parse('01/01/2100') }
@ -962,7 +962,7 @@ describe Users::DossiersController, type: :controller do
before do
first_champ.type_de_champ.update!(type_champ: :iban, mandatory: true, libelle: 'l')
dossier.champs_public.first.becomes!(Champs::IbanChamp).save!
dossier.project_champs_public.first.becomes!(Champs::IbanChamp).save!
subject
end
@ -1000,7 +1000,7 @@ describe Users::DossiersController, type: :controller do
context 'when the champ is a phone number' do
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :phone }]) }
let!(:dossier) { create(:dossier, :en_construction, user:, procedure:) }
let(:first_champ) { dossier.champs_public.first }
let(:first_champ) { dossier.project_champs_public.first }
let(:now) { Time.zone.parse('01/01/2100') }
let(:submit_payload) do

View file

@ -11,6 +11,8 @@ FactoryBot.define do
individual { association(:individual, :empty, dossier: instance, strategy: :build) if procedure.for_individual? }
transient do
populate_champs { false }
populate_annotations { false }
for_individual? { false }
# For now a dossier must use a `create`d procedure, even if the dossier is only built (and not created).
# This is because saving the dossier fails when the procedure has not been saved beforehand
@ -19,6 +21,34 @@ FactoryBot.define do
procedure { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, for_individual: for_individual?) }
end
after(:create) do |dossier, evaluator|
if evaluator.populate_champs
dossier.revision.types_de_champ_public.each do |type_de_champ|
value = if type_de_champ.simple_drop_down_list?
type_de_champ.drop_down_options.first
elsif type_de_champ.multiple_drop_down_list?
type_de_champ.drop_down_options.first(2).to_json
end
attrs = { stable_id: type_de_champ.stable_id, dossier:, value: }.compact
create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs)
end
end
if evaluator.populate_annotations
dossier.revision.types_de_champ_private.each do |type_de_champ|
value = if type_de_champ.simple_drop_down_list?
type_de_champ.drop_down_options.first
elsif type_de_champ.multiple_drop_down_list?
type_de_champ.drop_down_options.first(2).to_json
end
attrs = { stable_id: type_de_champ.stable_id, dossier:, private: true, value: }.compact
create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs)
end
end
dossier.build_default_values
end
trait :with_entreprise do
transient do
as_degraded_mode { false }
@ -259,35 +289,11 @@ FactoryBot.define do
end
trait :with_populated_champs do
after(:create) do |dossier, _evaluator|
dossier.champs_to_destroy.where(private: false).destroy_all
dossier.types_de_champ.each do |type_de_champ|
value = if type_de_champ.simple_drop_down_list?
type_de_champ.drop_down_options.first
elsif type_de_champ.multiple_drop_down_list?
type_de_champ.drop_down_options.first(2).to_json
end
attrs = { stable_id: type_de_champ.stable_id, dossier:, value: }.compact
create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs)
end
dossier.reload
end
populate_champs { true }
end
trait :with_populated_annotations do
after(:create) do |dossier, _evaluator|
dossier.champs_to_destroy.where(private: true).destroy_all
dossier.types_de_champ_private.each do |type_de_champ|
value = if type_de_champ.simple_drop_down_list?
type_de_champ.drop_down_options.first
elsif type_de_champ.multiple_drop_down_list?
type_de_champ.drop_down_options.first(2).to_json
end
attrs = { stable_id: type_de_champ.stable_id, dossier:, private: true, value: }.compact
create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs)
end
dossier.reload
end
populate_annotations { true }
end
trait :prefilled do

View file

@ -71,8 +71,8 @@ RSpec.describe Types::DossierType, type: :graphql do
end
before do
dossier.champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:address) }.update(data: address)
dossier.champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:rna) }.update(data: rna)
dossier.project_champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:address) }.update(data: address)
dossier.project_champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:rna) }.update(data: rna)
end
it do
@ -82,7 +82,7 @@ RSpec.describe Types::DossierType, type: :graphql do
expect(data[:dossier][:champs][1][:commune][:code]).to eq('75119')
expect(data[:dossier][:champs][1][:commune][:postalCode]).to eq('75019')
expect(data[:dossier][:champs][1][:departement][:code]).to eq('75')
expect(data[:dossier][:champs][2][:etablissement][:siret]).to eq dossier.champs_public[2].etablissement.siret
expect(data[:dossier][:champs][2][:etablissement][:siret]).to eq dossier.project_champs_public[2].etablissement.siret
expect(data[:dossier][:champs][0][:id]).to eq(data[:dossier][:revision][:champDescriptors][0][:id])
expect(data[:dossier][:champs][1][:address][:cityName]).to eq('Paris 19e Arrondissement')
@ -99,7 +99,7 @@ RSpec.describe Types::DossierType, type: :graphql do
end
context 'when etablissement is in degraded mode' do
let(:etablissement) { dossier.champs_public.third.etablissement }
let(:etablissement) { dossier.project_champs_public.third.etablissement }
before do
etablissement.update(adresse: nil)
end
@ -128,7 +128,7 @@ RSpec.describe Types::DossierType, type: :graphql do
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:) }
let(:query) { DOSSIER_WITH_SELECTED_CHAMP_QUERY }
let(:variables) { { number: dossier.id, id: champ.to_typed_id } }
let(:champ) { dossier.champs_public.last }
let(:champ) { dossier.project_champs_public.last }
context 'when champ exists' do
it {
@ -155,7 +155,7 @@ RSpec.describe Types::DossierType, type: :graphql do
let(:checkbox_value) { 'true' }
before do
dossier.champs_public.first.update(value: checkbox_value)
dossier.project_champs_public.first.update(value: checkbox_value)
end
context 'when checkbox is true' do
@ -204,7 +204,7 @@ RSpec.describe Types::DossierType, type: :graphql do
let(:variables) { { number: dossier.id } }
before do
dossier.champs_public.first.update(value: linked_dossier.id)
dossier.project_champs_public.first.update(value: linked_dossier.id)
end
context 'en_construction' do
@ -233,7 +233,7 @@ RSpec.describe Types::DossierType, type: :graphql do
let(:variables) { { number: dossier.id } }
let(:rows) do
dossier.champs_public.first.rows.map do |champs|
dossier.project_champs_public.first.rows.map do |champs|
{ champs: champs.map { { id: _1.to_typed_id } } }
end
end

View file

@ -10,8 +10,8 @@ RSpec.describe DossierIndexSearchTermsJob, type: :job do
subject(:perform_job) { described_class.perform_now(dossier.reload) }
before do
dossier.champs_public.first.update_column(:value, "un nouveau champ")
dossier.champs_private.first.update_column(:value, "private champ")
dossier.project_champs_public.first.update_column(:value, "un nouveau champ")
dossier.project_champs_private.first.update_column(:value, "private champ")
end
it "update search terms columns" do

View file

@ -29,11 +29,11 @@ describe 'Recovery::Revision::LifeCycle' do
it do
expect { DossierPreloader.load_one(dossier) }.not_to raise_error(ArgumentError)
expect(dossier.champs_public.size).to eq(1)
expect(dossier.project_champs_public.size).to eq(1)
expect(dossier.champs.size).to eq(2)
importer.load
expect { DossierPreloader.load_one(dossier) }.not_to raise_error(ArgumentError)
expect(dossier.champs_public.size).to eq(2)
expect(dossier.project_champs_public.size).to eq(2)
end
end

View file

@ -75,11 +75,11 @@ describe AttestationTemplate, type: :model do
end
before do
dossier.champs_public
dossier.project_champs_public
.find { |champ| champ.libelle == 'libelleA' }
.update(value: 'libelle1')
dossier.champs_public
dossier.project_champs_public
.find { |champ| champ.libelle == 'libelleB' }
.update(value: 'libelle2')
end

View file

@ -86,8 +86,8 @@ describe Champ do
let(:dossier) { create(:dossier) }
it 'partition public and private' do
expect(dossier.champs_public.count).to eq(1)
expect(dossier.champs_private.count).to eq(1)
expect(dossier.project_champs_public.count).to eq(1)
expect(dossier.project_champs_private.count).to eq(1)
end
end
@ -97,7 +97,7 @@ describe Champ do
context 'when a procedure has 2 revisions' do
it 'does not duplicate the champs' do
expect(dossier.champs_public.count).to eq(1)
expect(dossier.project_champs_public.count).to eq(1)
expect(procedure.revisions.count).to eq(2)
end
end
@ -111,7 +111,7 @@ describe Champ do
before { procedure.publish }
it 'does not duplicate the champs private' do
expect(dossier.champs_private.count).to eq(1)
expect(dossier.project_champs_private.count).to eq(1)
expect(procedure.revisions.count).to eq(2)
end
end
@ -122,12 +122,12 @@ describe Champ do
create(:procedure, types_de_champ_public: [{}, { type: :header_section }, { type: :repetition, mandatory: true, children: [{ type: :header_section }] }], types_de_champ_private: [{}, { type: :header_section }])
end
let(:dossier) { create(:dossier, procedure: procedure) }
let(:public_champ) { dossier.champs_public.first }
let(:private_champ) { dossier.champs_private.first }
let(:champ_in_repetition) { dossier.champs_public.find(&:repetition?).champs.first }
let(:public_champ) { dossier.project_champs_public.first }
let(:private_champ) { dossier.project_champs_private.first }
let(:champ_in_repetition) { dossier.project_champs_public.find(&:repetition?).champs.first }
let(:standalone_champ) { build(:champ, type_de_champ: build(:type_de_champ), dossier: build(:dossier)) }
let(:public_sections) { dossier.champs_public.filter(&:header_section?) }
let(:private_sections) { dossier.champs_private.filter(&:header_section?) }
let(:public_sections) { dossier.project_champs_public.filter(&:header_section?) }
let(:private_sections) { dossier.project_champs_private.filter(&:header_section?) }
let(:sections_in_repetition) { dossier.champs.filter(&:child?).filter(&:header_section?) }
it 'returns the sibling sections of a champ' do

View file

@ -61,7 +61,7 @@ RSpec.describe DossierChampsConcern do
end
context "missing champ" do
before { dossier; Champs::TextChamp.destroy_all }
before { dossier.champs.where(type: 'Champs::TextChamp').destroy_all; dossier.reload }
it {
expect(subject.new_record?).to be_truthy
@ -94,7 +94,7 @@ RSpec.describe DossierChampsConcern do
it { expect(subject.persisted?).to be_truthy }
context "missing champ" do
before { dossier; Champs::TextChamp.destroy_all }
before { dossier.champs.where(type: 'Champs::TextChamp').destroy_all; dossier.reload }
it {
expect(subject.new_record?).to be_truthy

View file

@ -120,15 +120,15 @@ RSpec.describe DossierCloneConcern do
context 'public are duplicated' do
it do
expect(new_dossier.champs_public.count).to eq(dossier.champs_public.count)
expect(new_dossier.champs_public.ids).not_to eq(dossier.champs_public.ids)
expect(new_dossier.project_champs_public.count).to eq(dossier.project_champs_public.count)
expect(new_dossier.project_champs_public.map(&:id)).not_to eq(dossier.project_champs_public.map(&:id))
end
it 'keeps champs.values' do
original_first_champ = dossier.champs_public.first
original_first_champ = dossier.project_champs_public.first
original_first_champ.update!(value: 'kthxbye')
expect(new_dossier.champs_public.first.value).to eq(original_first_champ.value)
expect(new_dossier.project_champs_public.first.value).to eq(original_first_champ.value)
end
context 'for Champs::Repetition with rows, original_champ.repetition and rows are duped' do
@ -192,26 +192,26 @@ RSpec.describe DossierCloneConcern do
let(:types_de_champ_private) { [{}] }
it 'reset champs private values' do
expect(new_dossier.champs_private.count).to eq(dossier.champs_private.count)
expect(new_dossier.champs_private.ids).not_to eq(dossier.champs_private.ids)
original_first_champs_private = dossier.champs_private.first
expect(new_dossier.project_champs_private.count).to eq(dossier.project_champs_private.count)
expect(new_dossier.project_champs_private.map(&:id)).not_to eq(dossier.project_champs_private.map(&:id))
original_first_champs_private = dossier.project_champs_private.first
original_first_champs_private.update!(value: 'kthxbye')
expect(new_dossier.champs_private.first.value).not_to eq(original_first_champs_private.value)
expect(new_dossier.champs_private.first.value).to eq(nil)
expect(new_dossier.project_champs_private.first.value).not_to eq(original_first_champs_private.value)
expect(new_dossier.project_champs_private.first.value).to eq(nil)
end
end
end
context "as a fork" do
let(:new_dossier) { dossier.clone(fork: true) }
before { dossier.champs_public.reload } # we compare timestamps so we have to get the precision limit from the db }
before { dossier.project_champs_public } # we compare timestamps so we have to get the precision limit from the db }
it do
expect(new_dossier.editing_fork_origin).to eq(dossier)
expect(new_dossier.champs_public[0].id).not_to eq(dossier.champs_public[0].id)
expect(new_dossier.champs_public[0].created_at).to eq(dossier.champs_public[0].created_at)
expect(new_dossier.champs_public[0].updated_at).to eq(dossier.champs_public[0].updated_at)
expect(new_dossier.project_champs_public[0].id).not_to eq(dossier.project_champs_public[0].id)
expect(new_dossier.project_champs_public[0].created_at).to eq(dossier.project_champs_public[0].created_at)
expect(new_dossier.project_champs_public[0].updated_at).to eq(dossier.project_champs_public[0].updated_at)
end
context "piece justificative champ" do
@ -343,11 +343,11 @@ RSpec.describe DossierCloneConcern do
dossier.debounce_index_search_terms_flag.remove
end
it { expect { subject }.to change { dossier.reload.champs.size }.by(0) }
it { expect { subject }.not_to change { dossier.reload.champs.order(:created_at).reject { _1.stable_id.in?([99, 994]) }.map(&:value) } }
it { expect { subject }.to change { dossier.champs.size }.by(0) }
it { expect { subject }.not_to change { dossier.champs.order(:created_at).reject { _1.stable_id.in?([99, 994]) }.map(&:value) } }
it { expect { subject }.to have_enqueued_job(DossierIndexSearchTermsJob).with(dossier) }
it { expect { subject }.to change { dossier.reload.champs.find { _1.stable_id == 99 }.value }.from('old value').to('new value') }
it { expect { subject }.to change { dossier.reload.champs.find { _1.stable_id == 994 }.value }.from('old value').to('new value in repetition') }
it { expect { subject }.to change { dossier.champs.find { _1.stable_id == 99 }.value }.from('old value').to('new value') }
it { expect { subject }.to change { dossier.champs.find { _1.stable_id == 994 }.value }.from('old value').to('new value in repetition') }
it 'fork is hidden after merge' do
subject
@ -386,11 +386,10 @@ RSpec.describe DossierCloneConcern do
added_repetition_champ.update(value: "new value in repetition champ")
dossier.reload
super()
dossier.reload
}
it { expect { subject }.to change { dossier.reload.champs.size }.by(1) }
it { expect { subject }.to change { dossier.reload.champs.order(:created_at).map(&:to_s) }.from(['old value', 'old value', 'Non', 'old value', 'old value']).to(['new value for updated champ', 'Non', 'old value', 'old value', 'new value for added champ', 'new value in repetition champ']) }
it { expect { subject }.to change { dossier.champs.size }.by(1) }
it { expect { subject }.to change { dossier.champs.order(:created_at).map(&:to_s) }.from(['old value', 'old value', 'Non', 'old value', 'old value']).to(['new value for updated champ', 'Non', 'old value', 'old value', 'new value for added champ', 'new value in repetition champ']) }
it "dossier after merge should be on last published revision" do
expect(dossier.revision_id).to eq(procedure.revisions.first.id)

View file

@ -43,7 +43,7 @@ RSpec.describe DossierPrefillableConcern do
end
it "doesn't change champs_public" do
expect { fill }.not_to change { dossier.champs_public.to_a }
expect { fill }.not_to change { dossier.project_champs_public.to_a }
end
end
@ -71,12 +71,12 @@ RSpec.describe DossierPrefillableConcern do
it "updates the champs with the new values and mark them as prefilled" do
fill
expect(dossier.champs_public.first.value).to eq(value_1)
expect(dossier.champs_public.first.prefilled).to eq(true)
expect(dossier.champs_public.last.value).to eq(value_2)
expect(dossier.champs_public.last.prefilled).to eq(true)
expect(dossier.champs_private.first.value).to eq(value_3)
expect(dossier.champs_private.first.prefilled).to eq(true)
expect(dossier.project_champs_public.first.value).to eq(value_1)
expect(dossier.project_champs_public.first.prefilled).to eq(true)
expect(dossier.project_champs_public.last.value).to eq(value_2)
expect(dossier.project_champs_public.last.prefilled).to eq(true)
expect(dossier.project_champs_private.first.value).to eq(value_3)
expect(dossier.project_champs_private.first.prefilled).to eq(true)
end
end
@ -91,11 +91,11 @@ RSpec.describe DossierPrefillableConcern do
it_behaves_like 'a dossier marked as prefilled'
it "still updates the champ" do
expect { fill }.to change { dossier.champs_public.first.value }.from(nil).to(value)
expect { fill }.to change { dossier.project_champs_public.first.value }.from(nil).to(value)
end
it "still marks it as prefilled" do
expect { fill }.to change { dossier.champs_public.first.prefilled }.from(nil).to(true)
expect { fill }.to change { dossier.project_champs_public.first.prefilled }.from(nil).to(true)
end
end
end
@ -115,7 +115,7 @@ RSpec.describe DossierPrefillableConcern do
it "updates the champs with the new values and mark them as prefilled" do
fill
expect(dossier.champs_public.first.value).to eq(value_1)
expect(dossier.project_champs_public.first.value).to eq(value_1)
expect(dossier.individual).to be_nil # Fix #9486
end

View file

@ -293,19 +293,19 @@ describe DossierRebaseConcern do
let(:datetime_type_de_champ) { types_de_champ.find { _1.stable_id == 103 } }
let(:yes_no_type_de_champ) { types_de_champ.find { _1.stable_id == 104 } }
let(:text_champ) { dossier.champs_public.find { _1.stable_id == 1 } }
let(:repetition_champ) { dossier.champs_public.find { _1.stable_id == 101 } }
let(:datetime_champ) { dossier.champs_public.find { _1.stable_id == 103 } }
let(:text_champ) { dossier.project_champs_public.find { _1.stable_id == 1 } }
let(:repetition_champ) { dossier.project_champs_public.find { _1.stable_id == 101 } }
let(:datetime_champ) { dossier.project_champs_public.find { _1.stable_id == 103 } }
let(:rebased_text_champ) { dossier.champs_public.find { _1.stable_id == 1 } }
let(:rebased_repetition_champ) { dossier.champs_public.find { _1.stable_id == 101 } }
let(:rebased_datetime_champ) { dossier.champs_public.find { _1.stable_id == 103 } }
let(:rebased_number_champ) { dossier.champs_public.find { _1.stable_id == 105 } }
let(:rebased_text_champ) { dossier.project_champs_public.find { _1.stable_id == 1 } }
let(:rebased_repetition_champ) { dossier.project_champs_public.find { _1.stable_id == 101 } }
let(:rebased_datetime_champ) { dossier.project_champs_public.find { _1.stable_id == 103 } }
let(:rebased_number_champ) { dossier.project_champs_public.find { _1.stable_id == 105 } }
let(:rebased_new_repetition_champ) { dossier.champs_public.find { _1.libelle == "une autre repetition" } }
let(:rebased_new_repetition_champ) { dossier.project_champs_public.find { _1.libelle == "une autre repetition" } }
let(:private_text_type_de_champ) { types_de_champ.find { _1.stable_id == 11 } }
let(:rebased_private_text_champ) { dossier.champs_private.find { _1.stable_id == 11 } }
let(:rebased_private_text_champ) { dossier.project_champs_private.find { _1.stable_id == 11 } }
context "when revision is published" do
before do
@ -345,16 +345,17 @@ describe DossierRebaseConcern do
datetime_champ.update(value: Time.zone.now.to_s)
text_champ.update(value: 'bonjour')
text_champ.type_de_champ
# Add two rows then remove previous to last row in order to create a "hole" in the sequence
repetition_champ.add_row(updated_by: 'test')
repetition_champ.add_row(updated_by: 'test')
repetition_champ.champs.where(row_id: repetition_champ.rows[-2].first.row_id).destroy_all
repetition_champ.reload
repetition_champ.champs.where(row_id: repetition_champ.row_ids[-2]).destroy_all
dossier.reload
end
it "updates the brouillon champs with the latest revision changes" do
expect(dossier.revision).to eq(procedure.published_revision)
expect(dossier.champs_public.size).to eq(5)
expect(dossier.project_champs_public.size).to eq(5)
expect(dossier.champs.count(&:public?)).to eq(7)
expect(repetition_champ.rows.size).to eq(2)
expect(repetition_champ.rows[0].size).to eq(1)
@ -367,7 +368,7 @@ describe DossierRebaseConcern do
expect(procedure.revisions.size).to eq(3)
expect(dossier.revision).to eq(procedure.published_revision)
expect(dossier.champs_public.size).to eq(7)
expect(dossier.project_champs_public.size).to eq(7)
expect(dossier.champs.count(&:public?)).to eq(13)
expect(rebased_text_champ.value).to eq(text_champ.value)
expect(rebased_text_champ.type_de_champ).not_to eq(text_champ.type_de_champ)
@ -404,7 +405,7 @@ describe DossierRebaseConcern do
let(:dossier) { create(:dossier, :en_construction, procedure:) }
it 'is noop' do
expect { subject }.not_to change { dossier.reload.champs_public[0].rebased_at }
expect { subject }.not_to change { dossier.reload.project_champs_public[0].rebased_at }
expect { subject }.not_to change { dossier.updated_at }
end
end
@ -430,38 +431,38 @@ describe DossierRebaseConcern do
context 'when a dropdown option is added' do
before do
dossier.champs_public.first.update(value: 'v1')
dossier.project_champs_public.first.update(value: 'v1')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["option", "updated", "v1"])
end
it { expect { subject }.not_to change { dossier.champs_public.first.value } }
it { expect { subject }.not_to change { dossier.project_champs_public.first.value } }
end
context 'when a dropdown option is removed' do
before do
dossier.champs_public.first.update(value: 'v1')
dossier.project_champs_public.first.update(value: 'v1')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["option", "updated"])
end
it { expect { subject }.to change { dossier.champs_public.first.value }.from('v1').to(nil) }
it { expect { subject }.to change { dossier.project_champs_public.first.value }.from('v1').to(nil) }
end
context 'when a dropdown unused option is removed' do
before do
dossier.champs_public.first.update(value: 'v1')
dossier.project_champs_public.first.update(value: 'v1')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["v1", "updated"])
end
it { expect { subject }.not_to change { dossier.champs_public.first.value } }
it { expect { subject }.not_to change { dossier.project_champs_public.first.value } }
end
end
@ -476,38 +477,38 @@ describe DossierRebaseConcern do
context 'when a dropdown option is added' do
before do
dossier.champs_public.first.update(value: '["v1"]')
dossier.project_champs_public.first.update(value: '["v1"]')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["option", "updated", "v1"])
end
it { expect { subject }.not_to change { dossier.champs_public.first.value } }
it { expect { subject }.not_to change { dossier.project_champs_public.first.value } }
end
context 'when a dropdown option is removed' do
before do
dossier.champs_public.first.update(value: '["v1", "option"]')
dossier.project_champs_public.first.update(value: '["v1", "option"]')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["option", "updated"])
end
it { expect { subject }.to change { dossier.champs_public.first.value }.from('["v1","option"]').to('["option"]') }
it { expect { subject }.to change { dossier.project_champs_public.first.value }.from('["v1","option"]').to('["option"]') }
end
context 'when a dropdown unused option is removed' do
before do
dossier.champs_public.first.update(value: '["v1"]')
dossier.project_champs_public.first.update(value: '["v1"]')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["v1", "updated"])
end
it { expect { subject }.not_to change { dossier.champs_public.first.value } }
it { expect { subject }.not_to change { dossier.project_champs_public.first.value } }
end
end
@ -522,38 +523,38 @@ describe DossierRebaseConcern do
context 'when a dropdown option is added' do
before do
dossier.champs_public.first.update(value: '["v1",""]')
dossier.project_champs_public.first.update(value: '["v1",""]')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["--titre1--", "option", "v1", "updated", "--titre2--", "option2", "v2"])
end
it { expect { subject }.not_to change { dossier.champs_public.first.value } }
it { expect { subject }.not_to change { dossier.project_champs_public.first.value } }
end
context 'when a dropdown option is removed' do
before do
dossier.champs_public.first.update(value: '["v1","option2"]')
dossier.project_champs_public.first.update(value: '["v1","option2"]')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["--titre1--", "option", "updated", "--titre2--", "option2", "v2"])
end
it { expect { subject }.to change { dossier.champs_public.first.value }.from('["v1","option2"]').to(nil) }
it { expect { subject }.to change { dossier.project_champs_public.first.value }.from('["v1","option2"]').to(nil) }
end
context 'when a dropdown unused option is removed' do
before do
dossier.champs_public.first.update(value: '["v1",""]')
dossier.project_champs_public.first.update(value: '["v1",""]')
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(drop_down_options: ["--titre1--", "v1", "updated", "--titre2--", "option2", "v2"])
end
it { expect { subject }.not_to change { dossier.champs_public.first.value } }
it { expect { subject }.not_to change { dossier.project_champs_public.first.value } }
end
end
@ -568,14 +569,14 @@ describe DossierRebaseConcern do
context 'and the cadastre are removed' do
before do
dossier.champs_public.first.update(value: 'v1', geo_areas: [build(:geo_area, :cadastre)])
dossier.project_champs_public.first.update(value: 'v1', geo_areas: [build(:geo_area, :cadastre)])
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
tdc_to_update.update(cadastres: false)
end
it { expect { subject }.to change { dossier.champs_public.first.cadastres.count }.from(1).to(0) }
it { expect { subject }.to change { dossier.project_champs_public.first.cadastres.count }.from(1).to(0) }
end
end
@ -626,7 +627,7 @@ describe DossierRebaseConcern do
end
context 'when the first tdc type is updated' do
def first_champ = dossier.champs_public.first
def first_champ = dossier.project_champs_public.first
before do
first_champ.update(value: 'v1', external_id: '123', geo_areas: [build(:geo_area)])
@ -727,7 +728,7 @@ describe DossierRebaseConcern do
parent.update(type_champ: :integer_number)
end
it { expect { subject }.to change { dossier.champs_public.first.champs.count }.from(2).to(0) }
it { expect { subject }.to change { dossier.project_champs_public.first.champs.count }.from(2).to(0) }
it { expect { subject }.to change { Champ.count }.from(3).to(1) }
end
end

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true
describe DossierSearchableConcern do
let(:champ_public) { dossier.champs_public.first }
let(:champ_private) { dossier.champs_private.first }
let(:champ_public) { dossier.project_champs_public.first }
let(:champ_private) { dossier.project_champs_private.first }
describe '#index_search_terms' do
let(:etablissement) { dossier.etablissement }

View file

@ -169,11 +169,11 @@ describe TagsSubstitutionConcern, type: :model do
context 'and their value in the dossier are not nil' do
before do
dossier.champs_public
dossier.project_champs_public
.find { |champ| champ.libelle == 'libelleA' }
.update(value: 'libelle1')
dossier.champs_public
dossier.project_champs_public
.find { |champ| champ.libelle == "libelle\xc2\xA0B".encode('utf-8') }
.update(value: 'libelle2')
end
@ -195,7 +195,7 @@ describe TagsSubstitutionConcern, type: :model do
context 'and their value in the dossier are not nil' do
before do
dossier.champs_public
dossier.project_champs_public
.find { |champ| champ.libelle == "Intitulé de l'‘«\"évènement\"»’" }
.update(value: 'ceci est mon évènement')
end
@ -217,7 +217,7 @@ describe TagsSubstitutionConcern, type: :model do
context 'and their value in the dossier are not nil' do
before do
dossier.champs_public
dossier.project_champs_public
.find { |champ| champ.libelle == "bon pote -- c'est top" }
.update(value: 'ceci est mon évènement')
end
@ -316,7 +316,7 @@ describe TagsSubstitutionConcern, type: :model do
let(:template) { '--libelleA--' }
context 'and its value in the dossier is not nil' do
before { dossier.champs_private.first.update(value: 'libelle1') }
before { dossier.project_champs_private.first.update(value: 'libelle1') }
it { is_expected.to eq('libelle1') }
end
@ -339,7 +339,7 @@ describe TagsSubstitutionConcern, type: :model do
context 'champs publics are valid tags' do
let(:types_de_champ_public) { [{ libelle: 'libelleA' }] }
before { dossier.champs_public.first.update(value: 'libelle1') }
before { dossier.project_champs_public.first.update(value: 'libelle1') }
it { is_expected.to eq('libelle1') }
end
@ -358,11 +358,11 @@ describe TagsSubstitutionConcern, type: :model do
context 'and its value in the dossier are not nil' do
before do
dossier.champs_public
dossier.project_champs_public
.find { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:date) }
.update(value: '2017-04-15')
dossier.champs_public
dossier.project_champs_public
.find { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) }
.update(value: '2017-09-13 09:00')
end
@ -433,7 +433,7 @@ describe TagsSubstitutionConcern, type: :model do
end
context "match breaking and non breaking spaces" do
before { dossier.champs_public.first.update(value: 'valeur') }
before { dossier.project_champs_public.first.update(value: 'valeur') }
shared_examples "treat all kinds of space as equivalent" do
context 'and the champ has a non breaking space' do
@ -480,7 +480,7 @@ describe TagsSubstitutionConcern, type: :model do
before do
draft_type_de_champ.update(libelle: 'mon nouveau libellé')
dossier.champs_public.first.update(value: 'valeur')
dossier.project_champs_public.first.update(value: 'valeur')
procedure.update!(draft_revision: procedure.create_new_revision, published_revision: procedure.draft_revision)
end
@ -513,7 +513,7 @@ describe TagsSubstitutionConcern, type: :model do
context 'in a champ' do
let(:types_de_champ_public) { [{ libelle: 'libelleA' }] }
before { dossier.champs_public.first.update(value: 'hey <a href="https://oops.com">anchor</a>') }
before { dossier.project_champs_public.first.update(value: 'hey <a href="https://oops.com">anchor</a>') }
it { is_expected.to eq('hey &lt;a href=&quot;https://oops.com&quot;&gt;anchor&lt;/a&gt; --nom--') }
end

View file

@ -10,9 +10,9 @@ describe DossierPreloader do
end
let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:repetition) { subject.champs_public.second }
let(:repetition_optional) { subject.champs_public.third }
let(:first_child) { subject.champs_public.second.champs.first }
let(:repetition) { subject.project_champs_public.second }
let(:repetition_optional) { subject.project_champs_public.third }
let(:first_child) { subject.project_champs_public.second.champs.first }
describe 'all' do
subject { DossierPreloader.load_one(dossier, pj_template: true) }
@ -25,20 +25,20 @@ describe DossierPreloader do
callback = lambda { |*_args| count += 1 }
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
expect(subject.id).to eq(dossier.id)
expect(subject.champs_public.size).to eq(types_de_champ.size)
expect(subject.project_champs_public.size).to eq(types_de_champ.size)
expect(subject.changed?).to be false
expect(first_child.type).to eq('Champs::TextChamp')
expect(repetition.id).not_to eq(first_child.id)
expect(subject.champs.first.dossier).to eq(subject)
expect(subject.champs.find(&:public?).dossier).to eq(subject)
expect(subject.champs_public.first.dossier).to eq(subject)
expect(subject.project_champs_public.first.dossier).to eq(subject)
expect(subject.champs_public.first.type_de_champ.piece_justificative_template.attached?).to eq(false)
expect(subject.project_champs_public.first.type_de_champ.piece_justificative_template.attached?).to eq(false)
expect(subject.champs.first.conditional?).to eq(false)
expect(subject.champs.find(&:public?).conditional?).to eq(false)
expect(subject.champs_public.first.conditional?).to eq(false)
expect(subject.project_champs_public.first.conditional?).to eq(false)
expect(first_child.parent).to eq(repetition)
expect(repetition.champs.first).to eq(first_child)

View file

@ -304,22 +304,12 @@ describe Dossier, type: :model do
subject { dossier }
describe '#create' do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
it 'builds public and private champs' do
expect(dossier.champs_public.count).to eq(1)
expect(dossier.champs_private.count).to eq(1)
end
end
describe '#build_default_individual' do
describe '#build_default_values' do
let(:dossier) { build(:dossier, procedure: procedure, user: user) }
subject do
dossier.individual = nil
dossier.build_default_individual
dossier.build_default_values
end
context 'when the dossier belongs to a procedure for individuals' do
@ -867,7 +857,7 @@ describe Dossier, type: :model do
it { is_expected.not_to eq(modif_date) }
context 'when a champ is modified' do
before { dossier.champs_public.first.update_attribute('value', 'yop') }
before { dossier.project_champs_public.first.update_attribute('value', 'yop') }
it { is_expected.to eq(modif_date) }
end
@ -1709,14 +1699,14 @@ describe Dossier, type: :model do
let(:expression_reguliere_error_message) { "Le champ doit être composé de lettres majuscules" }
before do
champ = dossier.champs_public.first
champ = dossier.project_champs_public.first
champ.value = expression_reguliere_exemple_text
dossier.save(context: :champs_public_value)
end
it 'should have errors' do
expect(dossier.errors).not_to be_empty
expect(dossier.errors.full_messages.join(',')).to include(dossier.champs_public.first.expression_reguliere_error_message)
expect(dossier.errors.full_messages.join(',')).to include(dossier.project_champs_public.first.expression_reguliere_error_message)
end
end
@ -1726,7 +1716,7 @@ describe Dossier, type: :model do
let(:expression_reguliere_error_message) { "Le champ doit être composé de lettres majuscules" }
before do
champ = dossier.champs_public.first
champ = dossier.project_champs_public.first
champ.value = expression_reguliere_exemple_text
dossier.save
end
@ -2026,8 +2016,8 @@ describe Dossier, type: :model do
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(:repetition_champ) { dossier.project_champs_public.find(&:repetition?) }
let(:repetition_second_revision_champ) { dossier_second_revision.project_champs_public.find(&:repetition?) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:dossier_second_revision) { create(:dossier, procedure: procedure) }
let(:dossier_champs_for_export) { dossier.champs_for_export(procedure.types_de_champ_for_procedure_export) }
@ -2087,14 +2077,14 @@ describe Dossier, type: :model do
let(:dossier) { create(:dossier, procedure:) }
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) }
let(:tdcs) { dossier.project_champs_public.map(&:type_de_champ) }
subject { dossier.champs_for_export(tdcs) }
before do
text_tdc.update(condition: ds_eq(champ_value(yes_no_tdc.stable_id), constant(true)))
yes_no, text = dossier.champs_public
yes_no, text = dossier.project_champs_public
yes_no.update(value: yes_no_value)
text.update(value: 'text')
end
@ -2113,7 +2103,7 @@ describe Dossier, type: :model do
context 'with another revision' do
let(:tdc_from_another_revision) { create(:type_de_champ_communes, libelle: 'commune', condition: ds_eq(constant(true), constant(true))) }
let(:tdcs) { dossier.champs_public.map(&:type_de_champ) << tdc_from_another_revision }
let(:tdcs) { dossier.project_champs_public.map(&:type_de_champ) << tdc_from_another_revision }
let(:yes_no_value) { 'true' }
let(:expected) do

View file

@ -50,7 +50,7 @@ describe ExportTemplate do
end
context 'for pj' do
let(:champ_pj) { dossier.champs_public.first }
let(:champ_pj) { dossier.project_champs_public.first }
let(:export_template) { create(:export_template, groupe_instructeur:, pjs: [ExportItem.default(stable_id: 3, prefix: "justif", enabled: true)]) }
let(:attachment) { ActiveStorage::Attachment.new(name: 'pj', record: champ_pj, blob: ActiveStorage::Blob.new(filename: "superpj.png")) }

View file

@ -201,7 +201,7 @@ describe Instructeur, type: :model do
context 'when there is a modification on public champs' do
before {
dossier.champs_public.first.update(value: 'toto')
dossier.project_champs_public.first.update(value: 'toto')
dossier.update(last_champ_updated_at: Time.zone.now)
}
@ -223,7 +223,7 @@ describe Instructeur, type: :model do
context 'when there is a modification on private champs' do
before {
dossier.champs_private.first.update(value: 'toto')
dossier.project_champs_private.first.update(value: 'toto')
dossier.update(last_champ_private_updated_at: Time.zone.now)
}
@ -302,7 +302,7 @@ describe Instructeur, type: :model do
it { expect(instructeur_on_procedure_2.notifications_for_groupe_instructeurs(gi_p2)[:en_cours]).to match([]) }
context 'and there is a modification on private champs' do
before { dossier.champs_private.first.update_attribute('value', 'toto') }
before { dossier.project_champs_private.first.update_attribute('value', 'toto') }
it { is_expected.to match([dossier.id]) }
end
@ -317,7 +317,7 @@ describe Instructeur, type: :model do
end
context 'when there is a modification on public champs on a followed dossier from another procedure' do
before { dossier_on_procedure_2.champs_public.first.update_attribute('value', 'toto') }
before { dossier_on_procedure_2.project_champs_public.first.update_attribute('value', 'toto') }
it { is_expected.to match([]) }
end

View file

@ -146,8 +146,8 @@ describe ProcedurePresentation do
let(:tartine_dossier) { create(:dossier, procedure: procedure) }
before do
beurre_dossier.champs_public.first.update(value: 'beurre')
tartine_dossier.champs_public.first.update(value: 'tartine')
beurre_dossier.project_champs_public.first.update(value: 'beurre')
tartine_dossier.project_champs_public.first.update(value: 'tartine')
end
context 'asc' do
@ -176,8 +176,8 @@ describe ProcedurePresentation do
nothing_dossier
procedure.draft_revision.add_type_de_champ(tdc)
procedure.publish_revision!
beurre_dossier.champs_public.last.update(value: 'beurre')
tartine_dossier.champs_public.last.update(value: 'tartine')
beurre_dossier.project_champs_public.last.update(value: 'beurre')
tartine_dossier.project_champs_public.last.update(value: 'tartine')
end
context 'asc' do
@ -201,8 +201,8 @@ describe ProcedurePresentation do
let(:vin_dossier) { create(:dossier, procedure: procedure) }
before do
biere_dossier.champs_private.first.update(value: 'biere')
vin_dossier.champs_private.first.update(value: 'vin')
biere_dossier.project_champs_private.first.update(value: 'biere')
vin_dossier.project_champs_private.first.update(value: 'vin')
end
context 'asc' do
@ -231,8 +231,8 @@ describe ProcedurePresentation do
nothing_dossier
procedure.draft_revision.add_type_de_champ(tdc)
procedure.publish_revision!
biere_dossier.champs_private.last.update(value: 'biere')
vin_dossier.champs_private.last.update(value: 'vin')
biere_dossier.project_champs_private.last.update(value: 'biere')
vin_dossier.project_champs_private.last.update(value: 'vin')
end
context 'asc' do
@ -592,8 +592,8 @@ describe ProcedurePresentation do
let(:value_column_searched) { ['postal_code'] }
before do
kept_dossier.champs_public.find_by(stable_id: 1).update(value_json: { "postal_code" => value })
create(:dossier, procedure: procedure).champs_public.find_by(stable_id: 1).update(value_json: { "postal_code" => "unknown" })
kept_dossier.project_champs_public.find { _1.stable_id == 1 }.update(value_json: { "postal_code" => value })
create(:dossier, procedure: procedure).project_champs_public.find { _1.stable_id == 1 }.update(value_json: { "postal_code" => "unknown" })
end
it { is_expected.to contain_exactly(kept_dossier.id) }
it 'describes column' do
@ -607,8 +607,8 @@ describe ProcedurePresentation do
let(:value_column_searched) { ['departement_code'] }
before do
kept_dossier.champs_public.find_by(stable_id: 1).update(value_json: { "departement_code" => value })
create(:dossier, procedure: procedure).champs_public.find_by(stable_id: 1).update(value_json: { "departement_code" => "unknown" })
kept_dossier.project_champs_public.find { _1.stable_id == 1 }.update(value_json: { "departement_code" => value })
create(:dossier, procedure: procedure).project_champs_public.find { _1.stable_id == 1 }.update(value_json: { "departement_code" => "unknown" })
end
it { is_expected.to contain_exactly(kept_dossier.id) }
it 'describes column' do
@ -622,8 +622,8 @@ describe ProcedurePresentation do
let(:value_column_searched) { ['region_name'] }
before do
kept_dossier.champs_public.find_by(stable_id: 1).update(value_json: { "region_name" => value })
create(:dossier, procedure: procedure).champs_public.find_by(stable_id: 1).update(value_json: { "region_name" => "unknown" })
kept_dossier.project_champs_public.find { _1.stable_id == 1 }.update(value_json: { "region_name" => value })
create(:dossier, procedure: procedure).project_champs_public.find { _1.stable_id == 1 }.update(value_json: { "region_name" => "unknown" })
end
it { is_expected.to contain_exactly(kept_dossier.id) }
it 'describes column' do

View file

@ -10,8 +10,8 @@ describe ChampPolicy do
subject { Pundit.policy_scope(account, Champ) }
let(:champ) { dossier.champs_public.first }
let(:champ_private) { dossier.champs_private.first }
let(:champ) { dossier.project_champs_public.first }
let(:champ_private) { dossier.project_champs_private.first }
shared_examples_for 'they can access a public champ' do
it { expect(subject.find_by(id: champ.id)).to eq(champ) }

View file

@ -21,10 +21,10 @@ describe DossierProjectionService do
end
before do
dossier_1.champs_public.first.update(value: 'champ_1')
dossier_1.champs_public.second.update(value: '["test"]')
dossier_2.champs_public.first.update(value: 'champ_2')
dossier_3.champs_public.first.destroy
dossier_1.project_champs_public.first.update(value: 'champ_1')
dossier_1.project_champs_public.second.update(value: '["test"]')
dossier_2.project_champs_public.first.update(value: 'champ_2')
dossier_3.project_champs_public.first.destroy
end
let(:result) { subject }
@ -65,7 +65,7 @@ describe DossierProjectionService do
end
before do
dossier.champs_public.first.update(code_postal: '63290', external_id: '63102')
dossier.project_champs_public.first.update(code_postal: '63290', external_id: '63102')
end
let(:result) { subject }
@ -185,7 +185,7 @@ describe DossierProjectionService do
let(:dossier) { create(:dossier) }
let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s }
before { dossier.champs_public.first.update(value: 'kale') }
before { dossier.project_champs_public.first.update(value: 'kale') }
it { is_expected.to eq('kale') }
end
@ -195,7 +195,7 @@ describe DossierProjectionService do
let(:dossier) { create(:dossier) }
let(:column) { dossier.procedure.active_revision.types_de_champ_private.first.stable_id.to_s }
before { dossier.champs_private.first.update(value: 'quinoa') }
before { dossier.project_champs_private.first.update(value: 'quinoa') }
it { is_expected.to eq('quinoa') }
end
@ -206,7 +206,7 @@ describe DossierProjectionService do
let(:dossier) { create(:dossier, procedure: procedure) }
let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s }
before { dossier.champs_public.first.update(value: 'true') }
before { dossier.project_champs_public.first.update(value: 'true') }
it { is_expected.to eq('Oui') }
end
@ -217,7 +217,7 @@ describe DossierProjectionService do
let(:dossier) { create(:dossier, procedure: procedure) }
let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s }
before { dossier.champs_public.first.update(value: '18 a la bonne rue', data: { 'label' => '18 a la bonne rue', 'departement' => 'd' }) }
before { dossier.project_champs_public.first.update(value: '18 a la bonne rue', data: { 'label' => '18 a la bonne rue', 'departement' => 'd' }) }
it { is_expected.to eq('18 a la bonne rue') }
end
@ -236,7 +236,7 @@ describe DossierProjectionService do
context 'when external id is set' do
before do
dossier.champs_public.first.update(external_id: 'GB')
dossier.project_champs_public.first.update(external_id: 'GB')
end
it { is_expected.to eq('Royaume-Uni') }
@ -244,7 +244,7 @@ describe DossierProjectionService do
context 'when no external id is set' do
before do
dossier.champs_public.first.update(value: "qu'il est beau mon pays")
dossier.project_champs_public.first.update(value: "qu'il est beau mon pays")
end
it { is_expected.to eq("") }

View file

@ -10,7 +10,7 @@ describe PiecesJustificativesService do
let(:pj_service) { PiecesJustificativesService.new(user_profile:, export_template:) }
let(:user_profile) { build(:administrateur) }
def pj_champ(d) = d.champs_public.find_by(type: 'Champs::PieceJustificativeChamp')
def pj_champ(d) = d.project_champs_public.find { _1.type == 'Champs::PieceJustificativeChamp' }
def repetition(d) = d.champs.find_by(type: "Champs::RepetitionChamp")
def attachments(champ) = champ.piece_justificative_file.attachments
@ -102,7 +102,7 @@ describe PiecesJustificativesService do
let(:user_profile) { build(:administrateur) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :piece_justificative }]) }
let(:witness) { create(:dossier, procedure: procedure) }
def pj_champ(d) = d.champs_public.find { |c| c.type == 'Champs::PieceJustificativeChamp' }
def pj_champ(d) = d.project_champs_public.find { |c| c.type == 'Champs::PieceJustificativeChamp' }
context 'with a single attachment' do
before do
@ -143,7 +143,7 @@ describe PiecesJustificativesService do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :titre_identite }]) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:champ_identite) { dossier.champs_public.find { |c| c.type == 'Champs::TitreIdentiteChamp' } }
let(:champ_identite) { dossier.project_champs_public.find { |c| c.type == 'Champs::TitreIdentiteChamp' } }
before { attach_file_to_champ(champ_identite) }
@ -260,7 +260,7 @@ describe PiecesJustificativesService do
let(:witness) { create(:dossier, procedure: procedure) }
let!(:private_pj) { create(:type_de_champ_piece_justificative, procedure: procedure, private: true) }
def private_pj_champ(d) = d.champs_private.find { |c| c.type == 'Champs::PieceJustificativeChamp' }
def private_pj_champ(d) = d.project_champs_private.find { |c| c.type == 'Champs::PieceJustificativeChamp' }
before do
attach_file_to_champ(private_pj_champ(dossier))
@ -503,8 +503,8 @@ describe PiecesJustificativesService do
let(:dossier_1) { create(:dossier, procedure:) }
let(:champs) { dossier_1.champs }
def pj_champ(d) = d.champs_public.find_by(type: 'Champs::PieceJustificativeChamp')
def repetition(d, index:) = d.champs_public.filter(&:repetition?)[index]
def pj_champ(d) = d.project_champs_public.find { _1.type == 'Champs::PieceJustificativeChamp' }
def repetition(d, index:) = d.project_champs_public.filter(&:repetition?)[index]
subject { PiecesJustificativesService.new(user_profile:, export_template: nil).send(:compute_champ_id_row_index, champs) }
@ -535,7 +535,7 @@ describe PiecesJustificativesService do
end
it do
champs = dossier_1.champs_public
champs = dossier_1.project_champs_public
repet_0 = champs[0]
pj_0 = repet_0.rows.first.first
pj_1 = repet_0.rows.second.first

View file

@ -155,7 +155,7 @@ describe ProcedureExportService do
let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure:) }
let!(:dossier_2) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure:) }
before do
dossier_2.champs_public
dossier_2.project_champs_public
.find { _1.is_a? Champs::PieceJustificativeChamp }
.piece_justificative_file
.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
@ -351,7 +351,7 @@ describe ProcedureExportService do
create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure)
]
end
let(:champ_repetition) { dossiers.first.champs_public.find { |champ| champ.type_champ == 'repetition' } }
let(:champ_repetition) { dossiers.first.project_champs_public.find { |champ| champ.type_champ == 'repetition' } }
it 'should have sheets' do
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.type_de_champ.libelle_for_export])
@ -416,7 +416,7 @@ describe ProcedureExportService do
context 'with empty repetition' do
before do
dossiers.flat_map { |dossier| dossier.champs_public.filter(&:repetition?) }.each do |champ|
dossiers.flat_map { |dossier| dossier.project_champs_public.filter(&:repetition?) }.each do |champ|
Champ.where(row_id: champ.row_ids).destroy_all
end
end
@ -520,7 +520,7 @@ describe ProcedureExportService do
end
let(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
let(:champ_carte) { dossier.champs_public.find(&:carte?) }
let(:champ_carte) { dossier.project_champs_public.find(&:carte?) }
let(:properties) { subject['features'].first['properties'] }
before do

View file

@ -7,7 +7,7 @@ describe ProcedureExportService do
let(:export_template) { create(:export_template, :enabled_pjs, groupe_instructeur: procedure.defaut_groupe_instructeur) }
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template) }
def pj_champ(d) = d.champs_public.find_by(type: 'Champs::PieceJustificativeChamp')
def pj_champ(d) = d.project_champs_public.find { _1.type == 'Champs::PieceJustificativeChamp' }
def repetition(d) = d.champs.find_by(type: "Champs::RepetitionChamp")
def attachments(champ) = champ.piece_justificative_file.attachments

View file

@ -282,7 +282,7 @@ describe 'fetch API Particulier Data', js: true do
fill_in 'Le code postal', with: 'wrong_code'
dossier = Dossier.last
cnaf_champ = dossier.champs_public.find(&:cnaf?)
cnaf_champ = dossier.project_champs_public.find(&:cnaf?)
wait_until { cnaf_champ.reload.code_postal == 'wrong_code' }
@ -342,7 +342,7 @@ describe 'fetch API Particulier Data', js: true do
fill_in "Identifiant", with: 'wrong code'
dossier = Dossier.last
pole_emploi_champ = dossier.champs_public.find(&:pole_emploi?)
pole_emploi_champ = dossier.project_champs_public.find(&:pole_emploi?)
wait_until { pole_emploi_champ.reload.identifiant == 'wrong code' }
@ -418,7 +418,7 @@ describe 'fetch API Particulier Data', js: true do
fill_in "INE", with: 'wrong code'
dossier = Dossier.last
mesri_champ = dossier.champs_public.find(&:mesri?)
mesri_champ = dossier.project_champs_public.find(&:mesri?)
wait_until { mesri_champ.reload.ine == 'wrong code' }
clear_enqueued_jobs
@ -485,7 +485,7 @@ describe 'fetch API Particulier Data', js: true do
fill_in "La référence davis dimposition", with: 'wrong_code'
dossier = Dossier.last
dgfip_champ = dossier.champs_public.find(&:dgfip?)
dgfip_champ = dossier.project_champs_public.find(&:dgfip?)
wait_until { dgfip_champ.reload.reference_avis == 'wrong_code' }

View file

@ -214,7 +214,7 @@ describe 'Instructing a dossier:', js: true do
context 'with dossiers having attached files' do
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }], instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:champ) { dossier.champs_public.first }
let(:champ) { dossier.project_champs_public.first }
let(:path) { 'spec/fixtures/files/piece_justificative_0.pdf' }
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }

View file

@ -10,7 +10,7 @@ describe "procedure sort", js: true do
before do
instructeur.follow(followed_dossier)
instructeur.follow(followed_dossier_2)
followed_dossier.champs_public.first.update(value: '123') # touch the dossier
followed_dossier.project_champs_public.first.update(value: '123') # touch the dossier
login_as(instructeur.user, scope: :user)
visit instructeur_procedure_path(procedure, statut: "suivis")

View file

@ -186,7 +186,7 @@ describe 'The routing with rules', js: true do
click_on litteraire_user.dossiers.first.procedure.libelle
click_on 'Modifier mon dossier'
fill_in litteraire_user.dossiers.first.champs_public.first.libelle, with: 'some value'
fill_in litteraire_user.dossiers.first.project_champs_public.first.libelle, with: 'some value'
wait_for_autosave
click_on 'Déposer les modifications'

View file

@ -674,7 +674,7 @@ describe 'The user', js: true do
end
def champ_for(libelle)
champs = user_dossier.reload.champs_public
champs = user_dossier.reload.project_champs_public
champ = champs.find { |c| c.libelle == libelle }
champ.reload
end

View file

@ -35,13 +35,13 @@ describe 'dropdown list with other option activated', js: true do
choose I18n.t('shared.champs.drop_down_list.other')
fill_in(I18n.t('shared.champs.drop_down_list.other_label'), with: "My choice")
wait_until { user_dossier.champs_public.first.value == "My choice" }
expect(user_dossier.champs_public.first.value).to eq("My choice")
wait_until { user_dossier.reload.project_champs_public.first.value == "My choice" }
expect(user_dossier.project_champs_public.first.value).to eq("My choice")
choose "Secondary 1.1"
wait_until { user_dossier.champs_public.first.value == "Secondary 1.1" }
expect(user_dossier.champs_public.first.value).to eq("Secondary 1.1")
wait_until { user_dossier.reload.project_champs_public.first.value == "Secondary 1.1" }
expect(user_dossier.project_champs_public.first.value).to eq("Secondary 1.1")
end
end
@ -68,8 +68,8 @@ describe 'dropdown list with other option activated', js: true do
select("Secondary 1.2")
expect(page).to have_selector(".autosave-status.succeeded", visible: true)
wait_until { user_dossier.champs_public.first.value == "Secondary 1.2" }
expect(user_dossier.champs_public.first.value).to eq("Secondary 1.2")
wait_until { user_dossier.reload.project_champs_public.first.value == "Secondary 1.2" }
expect(user_dossier.project_champs_public.first.value).to eq("Secondary 1.2")
end
end

View file

@ -10,7 +10,7 @@ describe "Dossier en_construction", js: true do
}
let(:champ) {
dossier.find_editing_fork(dossier.user).champs_public.find { _1.stable_id == tdc.stable_id }
dossier.find_editing_fork(dossier.user).project_champs_public.find { _1.stable_id == tdc.stable_id }
}
scenario 'delete a non mandatory piece justificative' do

View file

@ -175,7 +175,7 @@ describe 'Invitations' do
end
it "can search something inside the dossier and it displays the dossier" do
page.find_by_id('q').set(dossier_2.champs_public.first.value)
page.find_by_id('q').set(dossier_2.project_champs_public.first.value)
find('.fr-search-bar .fr-btn').click
expect(current_path).to eq(dossiers_path)
expect(page).to have_link(dossier.procedure.libelle)

View file

@ -306,7 +306,7 @@ describe 'user access to the list of their dossiers', js: true do
context "when user search for something inside the dossier" do
before do
page.find_by_id('q').set(dossier_en_construction.champs_public.first.value)
page.find_by_id('q').set(dossier_en_construction.project_champs_public.first.value)
end
context 'when it matches multiple dossiers' do
@ -336,7 +336,7 @@ describe 'user access to the list of their dossiers', js: true do
click_on 'Afficher'
expect(page).not_to have_link(String(dossier_en_construction.id))
expect(page).not_to have_link(String(dossier_with_champs.id))
expect(page).to have_content("Résultat de la recherche pour « #{dossier_en_construction.champs_public.first.value} » et pour la procédure « #{dossier_brouillon.procedure.libelle} » ")
expect(page).to have_content("Résultat de la recherche pour « #{dossier_en_construction.project_champs_public.first.value} » et pour la procédure « #{dossier_brouillon.procedure.libelle} » ")
expect(page).to have_text("Aucun dossier")
end
end

View file

@ -11,8 +11,8 @@ module Maintenance
let(:parent_dossier) { create(:dossier, procedure:) }
let(:cloned_dossier) { create(:dossier, procedure:) }
let(:parent_champ_pj) { parent_dossier.champs_private.find(&:piece_justificative?) }
let(:cloned_champ_pj) { cloned_dossier.champs_private.find(&:piece_justificative?) }
let(:parent_champ_pj) { parent_dossier.project_champs_private.find(&:piece_justificative?) }
let(:cloned_champ_pj) { cloned_dossier.project_champs_private.find(&:piece_justificative?) }
before do
cloned_dossier.update(parent_dossier:) # used on factorie, does not seed private_champs..

View file

@ -21,12 +21,12 @@ describe 'shared/dossiers/champs', type: :view do
context "there are some champs" do
let(:types_de_champ_public) { [{ type: :checkbox }, { type: :header_section }, { type: :explication }, { type: :dossier_link }, { type: :textarea }, { type: :rna }] }
let(:champ1) { dossier.champs[0] }
let(:champ2) { dossier.champs[1] }
let(:champ3) { dossier.champs[2] }
let(:champ4) { dossier.champs[3] }
let(:champ5) { dossier.champs[4] }
let(:champ6) { dossier.champs[5] }
let(:champ1) { dossier.project_champs_public[0] }
let(:champ2) { dossier.project_champs_public[1] }
let(:champ3) { dossier.project_champs_public[2] }
let(:champ4) { dossier.project_champs_public[3] }
let(:champ5) { dossier.project_champs_public[4] }
let(:champ6) { dossier.project_champs_public[5] }
before do
champ1.update(value: 'true')
@ -57,8 +57,8 @@ describe 'shared/dossiers/champs', type: :view do
context "with auto-link" do
let(:types_de_champ_public) { [{ type: :text }, { type: :textarea }] }
let(:champ1) { dossier.champs[0] }
let(:champ2) { dossier.champs[1] }
let(:champ1) { dossier.project_champs_public.first }
let(:champ2) { dossier.project_champs_public.second }
before do
champ1.update(value: 'https://github.com/tchak')
@ -118,8 +118,8 @@ describe 'shared/dossiers/champs', type: :view do
context "with seen_at" do
let(:types_de_champ_public) { [{ type: :checkbox }] }
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:, depose_at: 1.day.ago) }
let(:champ1) { dossier.champs[0] }
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:, depose_at: 1.day.ago.change(usec: 0)) }
let(:champ1) { dossier.champs.first }
context "with a demande_seen_at after champ updated_at" do
let(:demande_seen_at) { champ1.updated_at + 1.hour }
@ -127,21 +127,20 @@ describe 'shared/dossiers/champs', type: :view do
it { is_expected.not_to have_css(".fr-badge--new") }
end
context "with champ updated_at at depose_at" do
let(:champ1) { dossier.champs[0] }
let(:demande_seen_at) { champ1.updated_at - 1.hour }
before do
champ1.update(value: 'false', updated_at: dossier.depose_at)
end
it { is_expected.not_to have_css(".fr-badge--new") }
end
context "with a demande_seen_at after champ updated_at" do
context "with a demande_seen_at before champ updated_at" do
let(:demande_seen_at) { champ1.updated_at - 1.hour }
it { is_expected.to have_css(".fr-badge--new") }
end
context "with champ updated_at at depose_at" do
let(:demande_seen_at) { champ1.updated_at - 1.hour }
before do
champ1.update_columns(value: 'false', updated_at: dossier.depose_at)
end
it { is_expected.not_to have_css(".fr-badge--new") }
end
end
end

View file

@ -48,7 +48,7 @@ describe 'shared/dossiers/demande', type: :view do
let(:procedure) { create(:procedure, :published, :with_type_de_champ) }
it 'renders the champs' do
dossier.champs_public.each do |champ|
dossier.project_champs_public.each do |champ|
expect(subject).to include(champ.libelle)
end
end
@ -57,7 +57,7 @@ describe 'shared/dossiers/demande', type: :view do
context 'when a champ is freshly build' do
let(:procedure) { create(:procedure, :published, :with_type_de_champ) }
before do
dossier.champs_public.first.destroy
dossier.project_champs_public.first.destroy
end
it 'renders without error' do

View file

@ -44,7 +44,7 @@ describe 'shared/dossiers/edit', type: :view do
context 'with a single-value list' do
let(:types_de_champ_public) { [{ type: :drop_down_list, options:, mandatory: }] }
let(:champ) { dossier.champs_public.first }
let(:champ) { dossier.project_champs_public.first }
let(:type_de_champ) { champ.type_de_champ }
let(:enabled_options) { type_de_champ.drop_down_options }
let(:mandatory) { true }