refactor(dossier): champs -> champs_public
This commit is contained in:
parent
68e0abc15f
commit
e6288c39f2
62 changed files with 227 additions and 223 deletions
|
@ -362,9 +362,9 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
# Extract a value from params based on the "path"
|
||||
#
|
||||
# params: { dossiers: { champs_attributes: { 1234 => { value: "hello" } } } }
|
||||
# params: { dossiers: { champs_public_attributes: { 1234 => { value: "hello" } } } }
|
||||
#
|
||||
# Usage: read_param_value("dossiers[champs_attributes][1234]", "value")
|
||||
# Usage: read_param_value("dossiers[champs_public_attributes][1234]", "value")
|
||||
def read_param_value(path, name)
|
||||
parts = path.split(/\[|\]\[|\]/) + [name]
|
||||
parts.reduce(params) do |value, part|
|
||||
|
|
|
@ -74,7 +74,7 @@ class RootController < ApplicationController
|
|||
.each { |champ| champ.value = value }
|
||||
end
|
||||
|
||||
@dossier = Dossier.new(champs: all_champs)
|
||||
@dossier = Dossier.new(champs_public: all_champs)
|
||||
all_champs.each do |champ|
|
||||
champ.association(:dossier).target = @dossier
|
||||
champ.champs.each do |champ|
|
||||
|
|
|
@ -198,7 +198,7 @@ module Users
|
|||
respond_to do |format|
|
||||
format.html { render :brouillon }
|
||||
format.turbo_stream do
|
||||
@to_shows, @to_hides = @dossier.champs
|
||||
@to_shows, @to_hides = @dossier.champs_public
|
||||
.filter(&:conditional?)
|
||||
.partition(&:visible?)
|
||||
.map { |champs| champs_to_one_selector(champs) }
|
||||
|
@ -219,7 +219,7 @@ module Users
|
|||
respond_to do |format|
|
||||
format.html { render :modifier }
|
||||
format.turbo_stream do
|
||||
@to_shows, @to_hides = @dossier.champs
|
||||
@to_shows, @to_hides = @dossier.champs_public
|
||||
.filter(&:conditional?)
|
||||
.partition(&:visible?)
|
||||
.map { |champs| champs_to_one_selector(champs) }
|
||||
|
@ -382,7 +382,7 @@ module Users
|
|||
# FIXME: require(:dossier) when all the champs are united
|
||||
def champs_params
|
||||
params.permit(dossier: {
|
||||
champs_attributes: [
|
||||
champs_public_attributes: [
|
||||
:id, :value, :value_other, :external_id, :primary_value, :secondary_value, :numero_allocataire, :code_postal, :identifiant, :numero_fiscal, :reference_avis, :ine, :piece_justificative_file, :departement, :code_departement, value: [],
|
||||
champs_attributes: [:id, :_destroy, :value, :value_other, :external_id, :primary_value, :secondary_value, :numero_allocataire, :code_postal, :identifiant, :numero_fiscal, :reference_avis, :ine, :piece_justificative_file, :departement, :code_departement, value: []]
|
||||
]
|
||||
|
@ -446,10 +446,10 @@ module Users
|
|||
@dossier.assign_attributes(champs_params[:dossier])
|
||||
# FIXME: in some cases a removed repetition bloc row is submitted.
|
||||
# In this case it will be treated as a new record, and the action will fail.
|
||||
@dossier.champs.filter(&:block?).each do |champ|
|
||||
@dossier.champs_public.filter(&:block?).each do |champ|
|
||||
champ.champs = champ.champs.filter(&:persisted?)
|
||||
end
|
||||
if @dossier.champs.any?(&:changed_for_autosave?)
|
||||
if @dossier.champs_public.any?(&:changed_for_autosave?)
|
||||
@dossier.last_champ_updated_at = Time.zone.now
|
||||
end
|
||||
if !@dossier.save(**validation_options)
|
||||
|
|
|
@ -122,7 +122,7 @@ module Types
|
|||
.load(ApplicationRecord.id_from_typed_id(id))
|
||||
else
|
||||
Loaders::Association
|
||||
.for(object.class, champs: :type_de_champ)
|
||||
.for(object.class, champs_public: :type_de_champ)
|
||||
.load(object)
|
||||
.then { |champs| champs.filter(&:visible?) }
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ class AttestationTemplate < ApplicationRecord
|
|||
end
|
||||
|
||||
def unspecified_champs_for_dossier(dossier)
|
||||
all_champs_with_libelle_index = (dossier.champs + dossier.champs_private).index_by { |champ| "tdc#{champ.stable_id}" }
|
||||
all_champs_with_libelle_index = (dossier.champs_public + dossier.champs_private).index_by { |champ| "tdc#{champ.stable_id}" }
|
||||
|
||||
used_tags.filter_map do |used_tag|
|
||||
corresponding_champ = all_champs_with_libelle_index[used_tag]
|
||||
|
|
|
@ -166,7 +166,7 @@ class Champ < ApplicationRecord
|
|||
|
||||
# A predictable string to use when generating an input name for this champ.
|
||||
#
|
||||
# Rail's FormBuilder can auto-generate input names, using the form "dossier[champs_attributes][5]",
|
||||
# Rail's FormBuilder can auto-generate input names, using the form "dossier[champs_public_attributes][5]",
|
||||
# where [5] is the index of the field in the form.
|
||||
# However the field index makes it difficult to render a single field, independent from the ordering of the others.
|
||||
#
|
||||
|
@ -218,7 +218,7 @@ class Champ < ApplicationRecord
|
|||
private
|
||||
|
||||
def champs_for_condition
|
||||
private? ? dossier.champs_private : dossier.champs
|
||||
private? ? dossier.champs_private : dossier.champs_public
|
||||
end
|
||||
|
||||
def html_id
|
||||
|
@ -229,7 +229,7 @@ class Champ < ApplicationRecord
|
|||
if private?
|
||||
"champs_private_attributes"
|
||||
else
|
||||
"champs_attributes"
|
||||
"champs_public_attributes"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -139,7 +139,11 @@ module DossierRebaseConcern
|
|||
champ = target_coordinate
|
||||
.type_de_champ
|
||||
.build_champ(params)
|
||||
parent.champs << champ
|
||||
if parent.is_a?(Dossier)
|
||||
parent.champs_public << champ
|
||||
else
|
||||
parent.champs << champ
|
||||
end
|
||||
end
|
||||
|
||||
def delete_champs_for_revision(stable_id)
|
||||
|
|
|
@ -287,7 +287,7 @@ module TagsSubstitutionConcern
|
|||
tokens = parse_tags(text)
|
||||
|
||||
tags_and_datas = [
|
||||
[champ_public_tags(dossier: dossier), dossier.champs],
|
||||
[champ_public_tags(dossier: dossier), dossier.champs_public],
|
||||
[champ_private_tags(dossier: dossier), dossier.champs_private],
|
||||
[dossier_tags, dossier],
|
||||
[ROUTAGE_TAGS, dossier],
|
||||
|
|
|
@ -74,7 +74,7 @@ class Dossier < ApplicationRecord
|
|||
|
||||
has_one_attached :justificatif_motivation
|
||||
|
||||
has_many :champs, -> { root.public_ordered }, inverse_of: false, dependent: :destroy
|
||||
has_many :champs_public, -> { root.public_ordered }, class_name: 'Champ', inverse_of: false, dependent: :destroy
|
||||
has_many :champs_private, -> { root.private_ordered }, class_name: 'Champ', inverse_of: false, dependent: :destroy
|
||||
has_many :commentaires, inverse_of: :dossier, dependent: :destroy
|
||||
has_many :invites, dependent: :destroy
|
||||
|
@ -140,7 +140,7 @@ class Dossier < ApplicationRecord
|
|||
belongs_to :transfer, class_name: 'DossierTransfer', foreign_key: 'dossier_transfer_id', optional: true, inverse_of: :dossiers
|
||||
has_many :transfer_logs, class_name: 'DossierTransferLog', dependent: :destroy
|
||||
|
||||
accepts_nested_attributes_for :champs
|
||||
accepts_nested_attributes_for :champs_public
|
||||
accepts_nested_attributes_for :champs_private
|
||||
|
||||
include AASM
|
||||
|
@ -252,7 +252,7 @@ class Dossier < ApplicationRecord
|
|||
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
|
||||
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
|
||||
scope :with_champs, -> {
|
||||
includes(champs: [
|
||||
includes(champs_public: [
|
||||
:type_de_champ,
|
||||
:geo_areas,
|
||||
piece_justificative_file_attachment: :blob,
|
||||
|
@ -465,7 +465,7 @@ class Dossier < ApplicationRecord
|
|||
def update_search_terms
|
||||
self.search_terms = [
|
||||
user&.email,
|
||||
*champs.flat_map(&:search_terms),
|
||||
*champs_public.flat_map(&:search_terms),
|
||||
*etablissement&.search_terms,
|
||||
individual&.nom,
|
||||
individual&.prenom
|
||||
|
@ -474,8 +474,8 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def build_default_champs
|
||||
revision.build_champs.each do |champ|
|
||||
champs << champ
|
||||
revision.build_champs_public.each do |champ|
|
||||
champs_public << champ
|
||||
end
|
||||
revision.build_champs_private.each do |champ|
|
||||
champs_private << champ
|
||||
|
@ -983,11 +983,11 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def remove_titres_identite!
|
||||
champs.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
|
||||
champs_public.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
|
||||
end
|
||||
|
||||
def check_mandatory_and_visible_champs
|
||||
(champs + champs.filter(&:block?).filter(&:visible?).flat_map(&:champs))
|
||||
(champs_public + champs_public.filter(&:block?).filter(&:visible?).flat_map(&:champs))
|
||||
.filter(&:visible?)
|
||||
.filter(&:mandatory_blank?)
|
||||
.map do |champ|
|
||||
|
@ -1088,7 +1088,7 @@ class Dossier < ApplicationRecord
|
|||
if procedure.routing_enabled?
|
||||
columns << ['Groupe instructeur', groupe_instructeur.label]
|
||||
end
|
||||
columns + self.class.champs_for_export(champs + champs_private, types_de_champ)
|
||||
columns + self.class.champs_for_export(champs_public + champs_private, types_de_champ)
|
||||
end
|
||||
|
||||
# Get all the champs values for the types de champ in the final list.
|
||||
|
@ -1119,7 +1119,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def linked_dossiers_for(instructeur_or_expert)
|
||||
dossier_ids = champs.filter(&:dossier_link?).filter_map(&:value)
|
||||
dossier_ids = champs_public.filter(&:dossier_link?).filter_map(&:value)
|
||||
instructeur_or_expert.dossiers.where(id: dossier_ids)
|
||||
end
|
||||
|
||||
|
@ -1168,7 +1168,7 @@ class Dossier < ApplicationRecord
|
|||
@sections = Hash.new do |hash, parent|
|
||||
case parent
|
||||
when :public
|
||||
hash[parent] = champs.filter(&:header_section?)
|
||||
hash[parent] = champs_public.filter(&:header_section?)
|
||||
when :private
|
||||
hash[parent] = champs_private.filter(&:header_section?)
|
||||
else
|
||||
|
@ -1199,7 +1199,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def geo_areas
|
||||
champs.flat_map(&:geo_areas) + champs_private.flat_map(&:geo_areas)
|
||||
champs_public.flat_map(&:geo_areas) + champs_private.flat_map(&:geo_areas)
|
||||
end
|
||||
|
||||
def bounding_box
|
||||
|
|
|
@ -78,7 +78,7 @@ class DossierPreloader
|
|||
def load_dossier(dossier, champs, children_by_parent = {})
|
||||
champs_public, champs_private = champs.partition(&:public?)
|
||||
|
||||
load_champs(dossier, :champs, champs_public, dossier, children_by_parent)
|
||||
load_champs(dossier, :champs_public, champs_public, dossier, children_by_parent)
|
||||
load_champs(dossier, :champs_private, champs_private, dossier, children_by_parent)
|
||||
|
||||
# We need to do this because of the check on `Etablissement#champ` in
|
||||
|
|
|
@ -124,11 +124,11 @@ class Instructeur < ApplicationRecord
|
|||
|
||||
def notifications_for_dossier(dossier)
|
||||
follow = Follow
|
||||
.includes(dossier: [:champs, :avis, :commentaires])
|
||||
.includes(dossier: [:champs_public, :champs_private, :avis, :commentaires])
|
||||
.find_by(instructeur: self, dossier: dossier)
|
||||
|
||||
if follow.present?
|
||||
demande = follow.dossier.champs.updated_since?(follow.demande_seen_at).any? ||
|
||||
demande = follow.dossier.champs_public.updated_since?(follow.demande_seen_at).any? ||
|
||||
follow.dossier.groupe_instructeur_updated_at&.>(follow.demande_seen_at) ||
|
||||
dossier.identity_updated_at&.>(follow.demande_seen_at) ||
|
||||
false
|
||||
|
|
|
@ -255,7 +255,7 @@ class Procedure < ApplicationRecord
|
|||
includes(
|
||||
:groupe_instructeurs,
|
||||
dossiers: {
|
||||
champs: [
|
||||
champs_public: [
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [
|
||||
piece_justificative_file_attachment: :blob
|
||||
|
|
|
@ -32,7 +32,7 @@ class ProcedureRevision < ApplicationRecord
|
|||
|
||||
validate :conditions_are_valid?
|
||||
|
||||
def build_champs
|
||||
def build_champs_public
|
||||
# reload: it can be out of sync in test if some tdcs are added wihtout using add_tdc
|
||||
types_de_champ_public.reload.map { |tdc| tdc.build_champ(revision: self) }
|
||||
end
|
||||
|
@ -154,7 +154,7 @@ class ProcedureRevision < ApplicationRecord
|
|||
def new_dossier
|
||||
Dossier.new(
|
||||
revision: self,
|
||||
champs: build_champs,
|
||||
champs_public: build_champs_public,
|
||||
champs_private: build_champs_private,
|
||||
groupe_instructeur: procedure.defaut_groupe_instructeur
|
||||
)
|
||||
|
|
|
@ -30,7 +30,7 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
has_many :champs, serializer: ChampSerializer
|
||||
|
||||
def champs
|
||||
champs = object.champs.reject { |c| c.type_de_champ.old_pj.present? }
|
||||
champs = object.champs_public.reject { |c| c.type_de_champ.old_pj.present? }
|
||||
|
||||
if object.expose_legacy_carto_api?
|
||||
champ_carte = champs.find do |champ|
|
||||
|
|
|
@ -45,7 +45,7 @@ class PiecesJustificativesService
|
|||
end
|
||||
|
||||
def self.serialize_champs_as_pjs(dossier)
|
||||
dossier.champs.filter { |champ| champ.type_de_champ.old_pj }.map do |champ|
|
||||
dossier.champs_public.filter { |champ| champ.type_de_champ.old_pj }.map do |champ|
|
||||
{
|
||||
created_at: champ.created_at&.in_time_zone('UTC'),
|
||||
type_de_piece_justificative_id: champ.type_de_champ.old_pj[:stable_id],
|
||||
|
|
|
@ -52,10 +52,10 @@ class ProcedureArchiveService
|
|||
end
|
||||
|
||||
def self.liste_pieces_justificatives_for_archive(dossier)
|
||||
champs_blocs_repetables = dossier.champs
|
||||
champs_blocs_repetables = dossier.champs_public
|
||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||
.flat_map(&:champs)
|
||||
|
||||
attachments_from_champs_piece_justificative(champs_blocs_repetables + dossier.champs)
|
||||
attachments_from_champs_piece_justificative(champs_blocs_repetables + dossier.champs_public)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,7 +82,7 @@ class ProcedureExportService
|
|||
|
||||
def etablissements
|
||||
@etablissements ||= dossiers.flat_map do |dossier|
|
||||
[dossier.champs, dossier.champs_private]
|
||||
[dossier.champs_public, dossier.champs_private]
|
||||
.flatten
|
||||
.filter { |champ| champ.is_a?(Champs::SiretChamp) }
|
||||
end.filter_map(&:etablissement) + dossiers.filter_map(&:etablissement)
|
||||
|
@ -94,7 +94,7 @@ class ProcedureExportService
|
|||
|
||||
def champs_repetables_options
|
||||
champs_by_stable_id = dossiers
|
||||
.flat_map { |dossier| (dossier.champs + dossier.champs_private).filter(&:repetition?) }
|
||||
.flat_map { |dossier| (dossier.champs_public + dossier.champs_private).filter(&:repetition?) }
|
||||
.group_by(&:stable_id)
|
||||
|
||||
procedure
|
||||
|
|
|
@ -225,7 +225,7 @@ prawn_document(page_size: "A4") do |pdf|
|
|||
|
||||
add_title(pdf, 'Formulaire')
|
||||
add_single_line(pdf, @dossier.procedure.description + "\n", 9, :italic) if @dossier.procedure.description.present?
|
||||
add_champs(pdf, @dossier.champs)
|
||||
add_champs(pdf, @dossier.champs_public)
|
||||
add_page_numbering(pdf)
|
||||
add_procedure(pdf, @dossier)
|
||||
end
|
||||
|
|
|
@ -248,7 +248,7 @@ prawn_document(page_size: "A4") do |pdf|
|
|||
end
|
||||
|
||||
add_title(pdf, 'Formulaire')
|
||||
add_champs(pdf, @dossier.champs)
|
||||
add_champs(pdf, @dossier.champs_public)
|
||||
|
||||
if @include_infos_administration && @dossier.champs_private.present?
|
||||
add_title(pdf, "Annotations privées")
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
%h2 Formulaire
|
||||
|
||||
- champs = @dossier.champs
|
||||
- champs = @dossier.champs_public
|
||||
- if champs.any? || @dossier.procedure.routing_enabled?
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' }
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
%form.form
|
||||
= form_for @dossier, url: '', html: { class: 'form' } do |f|
|
||||
= f.fields_for :champs do |champ_form|
|
||||
= f.fields_for :champs_public do |champ_form|
|
||||
= render EditableChamp::EditableChampComponent.new champ: champ_form.object, form: champ_form
|
||||
|
||||
.editable-champ.editable-champ-text
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
= link_to t('views.shared.dossiers.demande.edit_identity'), identite_dossier_path(dossier), class: 'button'
|
||||
|
||||
.tab-title= t('views.shared.dossiers.demande.form')
|
||||
- champs = dossier.champs.includes(:type_de_champ)
|
||||
- champs = dossier.champs_public.includes(:type_de_champ)
|
||||
- if champs.any? || dossier.procedure.routing_enabled?
|
||||
.card
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: dossier, demande_seen_at: demande_seen_at, profile: profile }
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
dossier.procedure.groupe_instructeurs.actif.map { |gi| [gi.label, gi.id] },
|
||||
{ include_blank: dossier.brouillon? }
|
||||
|
||||
- dossier.champs.each do |champ|
|
||||
- dossier.champs_public.each do |champ|
|
||||
= fields_for champ.input_name, champ do |form|
|
||||
= render EditableChamp::EditableChampComponent.new form: form, champ: champ
|
||||
|
||||
|
|
|
@ -467,7 +467,7 @@ describe API::V2::GraphqlController do
|
|||
}
|
||||
end,
|
||||
avis: [],
|
||||
champs: dossier.champs.map do |champ|
|
||||
champs: dossier.champs_public.map do |champ|
|
||||
{
|
||||
id: champ.to_typed_id,
|
||||
label: champ.libelle,
|
||||
|
@ -475,7 +475,7 @@ describe API::V2::GraphqlController do
|
|||
}
|
||||
end
|
||||
})
|
||||
expect(gql_data[:dossier][:champs][0][:id]).to eq(dossier.champs[0].type_de_champ.to_typed_id)
|
||||
expect(gql_data[:dossier][:champs][0][:id]).to eq(dossier.champs_public[0].type_de_champ.to_typed_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -606,8 +606,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.first }
|
||||
let(:champ_datetime) { dossier.champs.second }
|
||||
let(:champ_date) { dossier.champs_public.first }
|
||||
let(:champ_datetime) { dossier.champs_public.second }
|
||||
|
||||
before do
|
||||
champ_date.update(value: '2019-07-10')
|
||||
|
|
|
@ -5,7 +5,7 @@ describe Champs::CarteController, type: :controller do
|
|||
let(:params) do
|
||||
{
|
||||
dossier: {
|
||||
champs_attributes: {
|
||||
champs_public_attributes: {
|
||||
'1' => { value: value }
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4,13 +4,13 @@ describe Champs::DossierLinkController, type: :controller do
|
|||
|
||||
describe '#show' do
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:champ) { dossier.champs_public.first }
|
||||
|
||||
context 'when user is connected' do
|
||||
render_views
|
||||
before { sign_in user }
|
||||
|
||||
let(:champs_attributes) do
|
||||
let(:champs_public_attributes) do
|
||||
champ_attributes = []
|
||||
champ_attributes[champ.id] = { value: dossier_id }
|
||||
champ_attributes
|
||||
|
@ -19,7 +19,7 @@ describe Champs::DossierLinkController, type: :controller do
|
|||
{
|
||||
champ_id: champ.id,
|
||||
dossier: {
|
||||
champs_attributes: champs_attributes
|
||||
champs_public_attributes: champs_public_attributes
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ describe Champs::PieceJustificativeController, type: :controller do
|
|||
let(:user) { create(:user) }
|
||||
let(:procedure) { create(:procedure, :published, :with_piece_justificative) }
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:champ) { dossier.champs_public.first }
|
||||
|
||||
describe '#update' do
|
||||
render_views
|
||||
|
|
|
@ -4,9 +4,9 @@ describe Champs::RNAController, type: :controller do
|
|||
|
||||
describe '#show' do
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:champ) { dossier.champs_public.first }
|
||||
|
||||
let(:champs_attributes) do
|
||||
let(:champs_public_attributes) do
|
||||
champ_attributes = []
|
||||
champ_attributes[champ.id] = { value: rna }
|
||||
champ_attributes
|
||||
|
@ -15,7 +15,7 @@ describe Champs::RNAController, type: :controller do
|
|||
{
|
||||
champ_id: champ.id,
|
||||
dossier: {
|
||||
champs_attributes: champs_attributes
|
||||
champs_public_attributes: champs_public_attributes
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ describe Champs::SiretController, type: :controller do
|
|||
|
||||
describe '#show' do
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:champ) { dossier.champs_public.first }
|
||||
|
||||
let(:champs_attributes) do
|
||||
let(:champs_public_attributes) do
|
||||
champ_attributes = []
|
||||
champ_attributes[champ.id] = { value: siret }
|
||||
champ_attributes
|
||||
|
@ -15,7 +15,7 @@ describe Champs::SiretController, type: :controller do
|
|||
{
|
||||
champ_id: champ.id,
|
||||
dossier: {
|
||||
champs_attributes: champs_attributes
|
||||
champs_public_attributes: champs_public_attributes
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -368,7 +368,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.filter(&:dossier_link?).filter_map(&:value)) }
|
||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs_public.filter(&:dossier_link?).filter_map(&:value)) }
|
||||
let(:linked_avis) { create(:avis, dossier: linked_dossier, claimant: claimant) }
|
||||
let(:invite_linked_dossiers) { true }
|
||||
|
||||
|
|
|
@ -591,7 +591,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
context 'and the expert can access the linked dossiers' do
|
||||
let(:saved_avis) { Avis.last(2).first }
|
||||
let(:linked_avis) { Avis.last }
|
||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.filter(&:dossier_link?).filter_map(&:value)) }
|
||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs_public.filter(&:dossier_link?).filter_map(&:value)) }
|
||||
let(:invite_linked_dossiers) do
|
||||
instructeur.assign_to_procedure(linked_dossier.procedure)
|
||||
true
|
||||
|
@ -763,7 +763,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
dossier_id: dossier.id,
|
||||
dossier: {
|
||||
champs_private_attributes: {},
|
||||
champs_attributes: {
|
||||
champs_public_attributes: {
|
||||
'0': {
|
||||
id: champ_multiple_drop_down_list.id,
|
||||
value: ['', 'un', 'deux']
|
||||
|
|
|
@ -19,14 +19,14 @@ describe RechercheController, type: :controller do
|
|||
before do
|
||||
instructeur.assign_to_procedure(dossier.procedure)
|
||||
|
||||
dossier.champs[0].value = "Name of district A"
|
||||
dossier.champs[1].value = "Name of city A"
|
||||
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.save!
|
||||
|
||||
dossier_with_expert.champs[0].value = "Name of district B"
|
||||
dossier_with_expert.champs[1].value = "name of city B"
|
||||
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.save!
|
||||
|
|
|
@ -342,7 +342,7 @@ describe Users::DossiersController, type: :controller do
|
|||
before { sign_in(user) }
|
||||
|
||||
let!(:dossier) { create(:dossier, user: user) }
|
||||
let(:first_champ) { dossier.champs.first }
|
||||
let(:first_champ) { dossier.champs_public.first }
|
||||
let(:value) { 'beautiful value' }
|
||||
let(:now) { Time.zone.parse('01/01/2100') }
|
||||
let(:payload) { { id: dossier.id } }
|
||||
|
@ -437,8 +437,8 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_piece_justificative) }
|
||||
let!(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
let(:first_champ) { dossier.champs.first }
|
||||
let(:piece_justificative_champ) { dossier.champs.last }
|
||||
let(:first_champ) { dossier.champs_public.first }
|
||||
let(:piece_justificative_champ) { dossier.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') }
|
||||
|
@ -448,7 +448,7 @@ describe Users::DossiersController, type: :controller do
|
|||
id: dossier.id,
|
||||
dossier: {
|
||||
groupe_instructeur_id: dossier.groupe_instructeur_id,
|
||||
champs_attributes: [
|
||||
champs_public_attributes: [
|
||||
{
|
||||
id: first_champ.id,
|
||||
value: value
|
||||
|
@ -494,7 +494,7 @@ describe Users::DossiersController, type: :controller do
|
|||
{
|
||||
id: dossier.id,
|
||||
dossier: {
|
||||
champs_attributes: {}
|
||||
champs_public_attributes: {}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
@ -532,8 +532,8 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_piece_justificative) }
|
||||
let!(:dossier) { create(:dossier, :en_construction, user: user, procedure: procedure) }
|
||||
let(:first_champ) { dossier.champs.first }
|
||||
let(:piece_justificative_champ) { dossier.champs.last }
|
||||
let(:first_champ) { dossier.champs_public.first }
|
||||
let(:piece_justificative_champ) { dossier.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') }
|
||||
|
@ -543,7 +543,7 @@ describe Users::DossiersController, type: :controller do
|
|||
id: dossier.id,
|
||||
dossier: {
|
||||
groupe_instructeur_id: dossier.groupe_instructeur_id,
|
||||
champs_attributes: [
|
||||
champs_public_attributes: [
|
||||
{
|
||||
id: first_champ.id,
|
||||
value: value
|
||||
|
@ -608,7 +608,7 @@ describe Users::DossiersController, type: :controller do
|
|||
{
|
||||
id: dossier.id,
|
||||
dossier: {
|
||||
champs_attributes: [
|
||||
champs_public_attributes: [
|
||||
{
|
||||
id: piece_justificative_champ.id,
|
||||
piece_justificative_file: file
|
||||
|
@ -703,14 +703,14 @@ describe Users::DossiersController, type: :controller do
|
|||
context 'when the champ is a phone number' do
|
||||
let(:procedure) { create(:procedure, :published, :with_phone) }
|
||||
let!(:dossier) { create(:dossier, :en_construction, user: user, procedure: procedure) }
|
||||
let(:first_champ) { dossier.champs.first }
|
||||
let(:first_champ) { dossier.champs_public.first }
|
||||
let(:now) { Time.zone.parse('01/01/2100') }
|
||||
|
||||
let(:submit_payload) do
|
||||
{
|
||||
id: dossier.id,
|
||||
dossier: {
|
||||
champs_attributes: [
|
||||
champs_public_attributes: [
|
||||
{
|
||||
id: first_champ.id,
|
||||
value: value
|
||||
|
|
|
@ -84,7 +84,7 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
# find champ with the type de champ
|
||||
champ = dossier.reload.champs.find do |c|
|
||||
champ = dossier.reload.champs_public.find do |c|
|
||||
c.type_de_champ == type_de_champ
|
||||
end
|
||||
|
||||
|
@ -217,7 +217,7 @@ FactoryBot.define do
|
|||
|
||||
trait :with_populated_champs do
|
||||
after(:create) do |dossier, _evaluator|
|
||||
dossier.champs = dossier.types_de_champ.map do |type_de_champ|
|
||||
dossier.champs_public = dossier.types_de_champ.map do |type_de_champ|
|
||||
build(:"champ_#{type_de_champ.type_champ}", dossier: dossier, type_de_champ: type_de_champ)
|
||||
end
|
||||
dossier.save!
|
||||
|
|
|
@ -49,7 +49,7 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
end
|
||||
|
||||
before do
|
||||
dossier.champs.second.update(data: address)
|
||||
dossier.champs_public.second.update(data: address)
|
||||
end
|
||||
|
||||
it { expect(data[:dossier][:champs][0][:__typename]).to eq "CommuneChamp" }
|
||||
|
@ -67,7 +67,7 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
let(:checkbox_value) { 'on' }
|
||||
|
||||
before do
|
||||
dossier.champs.first.update(value: checkbox_value)
|
||||
dossier.champs_public.first.update(value: checkbox_value)
|
||||
end
|
||||
|
||||
context 'when checkbox is true' do
|
||||
|
@ -116,7 +116,7 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
let(:variables) { { number: dossier.id } }
|
||||
|
||||
before do
|
||||
dossier.champs.first.update(value: linked_dossier.id)
|
||||
dossier.champs_public.first.update(value: linked_dossier.id)
|
||||
end
|
||||
|
||||
context 'en_construction' do
|
||||
|
@ -145,7 +145,7 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
let(:variables) { { number: dossier.id } }
|
||||
|
||||
let(:rows) do
|
||||
dossier.champs.first.rows.map do |champs|
|
||||
dossier.champs_public.first.rows.map do |champs|
|
||||
{ champs: champs.map { { id: _1.to_typed_id } } }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ describe '20220705164551_remove_unused_champs' do
|
|||
let(:rake_task) { Rake::Task['after_party:remove_unused_champs'] }
|
||||
let(:procedure) { create(:procedure, :with_all_champs) }
|
||||
let(:dossier) { create(:dossier, :with_populated_champs, procedure: procedure) }
|
||||
let(:champ_repetition) { dossier.champs.find(&:repetition?) }
|
||||
let(:champ_repetition) { dossier.champs_public.find(&:repetition?) }
|
||||
|
||||
subject(:run_task) do
|
||||
dossier
|
||||
|
|
|
@ -153,11 +153,11 @@ describe AttestationTemplate, type: :model do
|
|||
|
||||
context 'and their value in the dossier are not nil' do
|
||||
before do
|
||||
dossier.champs
|
||||
dossier.champs_public
|
||||
.find { |champ| champ.libelle == 'libelleA' }
|
||||
.update(value: 'libelle1')
|
||||
|
||||
dossier.champs
|
||||
dossier.champs_public
|
||||
.find { |champ| champ.libelle == 'libelleB' }
|
||||
.update(value: 'libelle2')
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe Champ do
|
|||
|
||||
context 'when the parent dossier is discarded' do
|
||||
let(:discarded_dossier) { create(:dossier, :discarded) }
|
||||
subject(:champ) { discarded_dossier.champs.first }
|
||||
subject(:champ) { discarded_dossier.champs_public.first }
|
||||
|
||||
it { expect(champ.reload.dossier).to eq discarded_dossier }
|
||||
end
|
||||
|
@ -35,7 +35,7 @@ describe Champ do
|
|||
let(:dossier) { create(:dossier) }
|
||||
|
||||
it 'partition public and private' do
|
||||
expect(dossier.champs.count).to eq(1)
|
||||
expect(dossier.champs_public.count).to eq(1)
|
||||
expect(dossier.champs_private.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ describe Champ do
|
|||
|
||||
context 'when a procedure has 2 revisions' do
|
||||
it 'does not duplicate the champs' do
|
||||
expect(dossier.champs.count).to eq(1)
|
||||
expect(dossier.champs_public.count).to eq(1)
|
||||
expect(procedure.revisions.count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
@ -80,11 +80,11 @@ describe Champ do
|
|||
end
|
||||
end
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:public_champ) { dossier.champs.first }
|
||||
let(:public_champ) { dossier.champs_public.first }
|
||||
let(:private_champ) { dossier.champs_private.first }
|
||||
let(:champ_in_repetition) { dossier.champs.find(&:repetition?).champs.first }
|
||||
let(:champ_in_repetition) { dossier.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.filter(&:header_section?) }
|
||||
let(:public_sections) { dossier.champs_public.filter(&:header_section?) }
|
||||
let(:private_sections) { dossier.champs_private.filter(&:header_section?) }
|
||||
let(:sections_in_repetition) { champ_in_repetition.parent.champs.filter(&:header_section?) }
|
||||
|
||||
|
@ -498,7 +498,7 @@ describe Champ do
|
|||
let(:tdc_text) { procedure.active_revision.children_of(tdc_repetition).first }
|
||||
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.find(&:repetition?) }
|
||||
let(:champ) { dossier.champs_public.find(&:repetition?) }
|
||||
let(:champ_text) { champ.champs.find { |c| c.type_champ == 'text' } }
|
||||
let(:champ_integer) { champ.champs.find { |c| c.type_champ == 'integer_number' } }
|
||||
let(:champ_text_attrs) { attributes_for(:champ_text, type_de_champ: tdc_text, row: 1) }
|
||||
|
@ -517,7 +517,7 @@ describe Champ do
|
|||
|
||||
context 'when updating using nested attributes' do
|
||||
subject do
|
||||
dossier.update!(champs_attributes: [
|
||||
dossier.update!(champs_public_attributes: [
|
||||
{
|
||||
id: champ.id,
|
||||
champs_attributes: [champ_text_attrs]
|
||||
|
@ -530,7 +530,7 @@ describe Champ do
|
|||
it 'associates nested champs to the parent dossier' do
|
||||
subject
|
||||
|
||||
expect(dossier.champs.size).to eq(2)
|
||||
expect(dossier.champs_public.size).to eq(2)
|
||||
expect(champ.rows.size).to eq(2)
|
||||
second_row = champ.rows.second
|
||||
expect(second_row.size).to eq(1)
|
||||
|
@ -590,7 +590,7 @@ describe Champ do
|
|||
|
||||
context "#input_name" do
|
||||
let(:champ) { create(:champ_text) }
|
||||
it { expect(champ.input_name).to eq "dossier[champs_attributes][#{champ.id}]" }
|
||||
it { expect(champ.input_name).to eq "dossier[champs_public_attributes][#{champ.id}]" }
|
||||
|
||||
context "when private" do
|
||||
let(:champ) { create(:champ_text, private: true) }
|
||||
|
@ -599,7 +599,7 @@ describe Champ do
|
|||
|
||||
context "when has parent" do
|
||||
let(:champ) { create(:champ_text, parent: create(:champ_text)) }
|
||||
it { expect(champ.input_name).to eq "dossier[champs_attributes][#{champ.parent_id}][champs_attributes][#{champ.id}]" }
|
||||
it { expect(champ.input_name).to eq "dossier[champs_public_attributes][#{champ.parent_id}][champs_attributes][#{champ.id}]" }
|
||||
end
|
||||
|
||||
context "when has private parent" do
|
||||
|
|
|
@ -14,8 +14,8 @@ describe Champs::HeaderSectionChamp do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
context 'for root-level champs' do
|
||||
let(:first_header) { dossier.champs.first }
|
||||
let(:second_header) { dossier.champs.fourth }
|
||||
let(:first_header) { dossier.champs_public.first }
|
||||
let(:second_header) { dossier.champs_public.fourth }
|
||||
|
||||
it 'returns the index of the section (starting from 1)' do
|
||||
expect(first_header.section_index).to eq 1
|
||||
|
@ -26,8 +26,8 @@ describe Champs::HeaderSectionChamp do
|
|||
context 'for repetition champs' do
|
||||
let(:types_de_champ_public) { [{ type: :repetition, children: types_de_champ }] }
|
||||
|
||||
let(:first_header) { dossier.champs.first.champs.first }
|
||||
let(:second_header) { dossier.champs.first.champs.fourth }
|
||||
let(:first_header) { dossier.champs_public.first.champs.first }
|
||||
let(:second_header) { dossier.champs_public.first.champs.fourth }
|
||||
|
||||
it 'returns the index of the section in the repetition (starting from 1)' do
|
||||
expect(first_header.section_index).to eq 1
|
||||
|
|
|
@ -124,11 +124,11 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
|
||||
context 'and their value in the dossier are not nil' do
|
||||
before do
|
||||
dossier.champs
|
||||
dossier.champs_public
|
||||
.find { |champ| champ.libelle == 'libelleA' }
|
||||
.update(value: 'libelle1')
|
||||
|
||||
dossier.champs
|
||||
dossier.champs_public
|
||||
.find { |champ| champ.libelle == "libelle\xc2\xA0B".encode('utf-8') }
|
||||
.update(value: 'libelle2')
|
||||
end
|
||||
|
@ -150,7 +150,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
|
||||
context 'and their value in the dossier are not nil' do
|
||||
before do
|
||||
dossier.champs
|
||||
dossier.champs_public
|
||||
.find { |champ| champ.libelle == "Intitulé de l'‘«\"évènement\"»’" }
|
||||
.update(value: 'ceci est mon évènement')
|
||||
end
|
||||
|
@ -176,7 +176,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
end
|
||||
|
||||
before do
|
||||
repetition = dossier.champs
|
||||
repetition = dossier.champs_public
|
||||
.find { |champ| champ.libelle == 'Répétition' }
|
||||
repetition.add_row(dossier.revision)
|
||||
paul_champs, pierre_champs = repetition.rows
|
||||
|
@ -202,7 +202,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
|
||||
context 'and the champ has a primary value' do
|
||||
before do
|
||||
dossier.champs.find_by(type_de_champ: type_de_champ).update(primary_value: 'primo')
|
||||
dossier.champs_public.find_by(type_de_champ: type_de_champ).update(primary_value: 'primo')
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
@ -210,7 +210,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
|
||||
context 'and the champ has a secondary value' do
|
||||
before do
|
||||
dossier.champs.find_by(type_de_champ: type_de_champ).update(secondary_value: 'secundo')
|
||||
dossier.champs_public.find_by(type_de_champ: type_de_champ).update(secondary_value: 'secundo')
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
@ -283,7 +283,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
context 'champs publics are valid tags' do
|
||||
let(:types_de_champ_public) { [{ libelle: 'libelleA' }] }
|
||||
|
||||
before { dossier.champs.first.update(value: 'libelle1') }
|
||||
before { dossier.champs_public.first.update(value: 'libelle1') }
|
||||
|
||||
it { is_expected.to eq('libelle1') }
|
||||
end
|
||||
|
@ -302,11 +302,11 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
|
||||
context 'and its value in the dossier are not nil' do
|
||||
before do
|
||||
dossier.champs
|
||||
dossier.champs_public
|
||||
.find { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:date) }
|
||||
.update(value: '2017-04-15')
|
||||
|
||||
dossier.champs
|
||||
dossier.champs_public
|
||||
.find { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) }
|
||||
.update(value: '2017-09-13 09:00')
|
||||
end
|
||||
|
@ -353,7 +353,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
end
|
||||
|
||||
context "match breaking and non breaking spaces" do
|
||||
before { dossier.champs.first.update(value: 'valeur') }
|
||||
before { dossier.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
|
||||
|
@ -400,7 +400,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
|
||||
before do
|
||||
draft_type_de_champ.update(libelle: 'mon nouveau libellé')
|
||||
dossier.champs.first.update(value: 'valeur')
|
||||
dossier.champs_public.first.update(value: 'valeur')
|
||||
procedure.update!(draft_revision: procedure.create_new_revision, published_revision: procedure.draft_revision)
|
||||
end
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ 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.second }
|
||||
let(:first_child) { subject.champs.second.champs.first }
|
||||
let(:repetition) { subject.champs_public.second }
|
||||
let(:first_child) { subject.champs_public.second.champs.first }
|
||||
|
||||
describe 'all' do
|
||||
subject { DossierPreloader.load_one(dossier, pj_template: true) }
|
||||
|
@ -21,13 +21,13 @@ 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.size).to eq(types_de_champ.size)
|
||||
expect(subject.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.first.type_de_champ.piece_justificative_template.attached?).to eq(false)
|
||||
expect(subject.champs_public.first.dossier).to eq(subject)
|
||||
expect(subject.champs_public.first.type_de_champ.piece_justificative_template.attached?).to eq(false)
|
||||
expect(first_child.parent).to eq(repetition)
|
||||
end
|
||||
|
||||
|
|
|
@ -158,17 +158,17 @@ describe Dossier do
|
|||
let(:yes_no_type_de_champ) { procedure.types_de_champ.find { |tdc| tdc.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } }
|
||||
|
||||
let(:text_type_de_champ) { procedure.types_de_champ.find(&:mandatory?) }
|
||||
let(:text_champ) { dossier.champs.find(&:mandatory?) }
|
||||
let(:rebased_text_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:text) } }
|
||||
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_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } }
|
||||
let(:rebased_datetime_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:date) } }
|
||||
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_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.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } }
|
||||
let(:rebased_repetition_champ) { dossier.champs.find { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } }
|
||||
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) } }
|
||||
|
||||
before do
|
||||
procedure.publish!
|
||||
|
@ -200,7 +200,7 @@ describe Dossier do
|
|||
libelle = text_type_de_champ.libelle
|
||||
|
||||
expect(dossier.revision).to eq(procedure.published_revision)
|
||||
expect(dossier.champs.size).to eq(4)
|
||||
expect(dossier.champs_public.size).to eq(4)
|
||||
expect(repetition_champ.rows.size).to eq(2)
|
||||
expect(repetition_champ.rows[0].size).to eq(1)
|
||||
expect(repetition_champ.rows[1].size).to eq(1)
|
||||
|
@ -212,7 +212,7 @@ describe Dossier do
|
|||
|
||||
expect(procedure.revisions.size).to eq(3)
|
||||
expect(dossier.revision).to eq(procedure.published_revision)
|
||||
expect(dossier.champs.size).to eq(4)
|
||||
expect(dossier.champs_public.size).to eq(4)
|
||||
expect(rebased_text_champ.value).to eq(text_champ.value)
|
||||
expect(rebased_text_champ.type_de_champ_id).not_to eq(text_champ.type_de_champ_id)
|
||||
expect(rebased_datetime_champ.type_champ).to eq(TypeDeChamp.type_champs.fetch(:date))
|
||||
|
@ -244,14 +244,14 @@ describe Dossier do
|
|||
|
||||
context 'when a dropdown option is changed' do
|
||||
before do
|
||||
dossier.champs.first.update(value: 'v1')
|
||||
dossier.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_list_value: 'option updated')
|
||||
end
|
||||
|
||||
it { expect { subject }.to change { dossier.champs.first.value }.from('v1').to(nil) }
|
||||
it { expect { subject }.to change { dossier.champs_public.first.value }.from('v1').to(nil) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -266,14 +266,14 @@ describe Dossier do
|
|||
|
||||
context 'and the cadastre are removed' do
|
||||
before do
|
||||
dossier.champs.first.update(value: 'v1', geo_areas: [create(:geo_area, :cadastre)])
|
||||
dossier.champs_public.first.update(value: 'v1', geo_areas: [create(:geo_area, :cadastre)])
|
||||
|
||||
stable_id = procedure.draft_revision.types_de_champ.find_by(libelle: 'l1')
|
||||
tdc_to_update = procedure.draft_revision.find_and_ensure_exclusive_use(stable_id)
|
||||
tdc_to_update.update(cadastres: false)
|
||||
end
|
||||
|
||||
it { expect { subject }.to change { dossier.champs.first.cadastres.count }.from(1).to(0) }
|
||||
it { expect { subject }.to change { dossier.champs_public.first.cadastres.count }.from(1).to(0) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -287,7 +287,7 @@ describe Dossier do
|
|||
end
|
||||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
def champ_libelles = dossier.champs.map(&:libelle)
|
||||
def champ_libelles = dossier.champs_public.map(&:libelle)
|
||||
|
||||
context 'when a tdc is added in the middle' do
|
||||
before do
|
||||
|
@ -328,7 +328,7 @@ describe Dossier do
|
|||
end
|
||||
|
||||
context 'when the first tdc type is updated' do
|
||||
def first_champ = dossier.champs.first
|
||||
def first_champ = dossier.champs_public.first
|
||||
|
||||
before do
|
||||
first_champ.update(value: 'v1', external_id: '123', geo_areas: [create(:geo_area)])
|
||||
|
@ -349,7 +349,7 @@ describe Dossier do
|
|||
tdc_to_update.update(type_champ: :integer_number)
|
||||
end
|
||||
|
||||
it { expect { subject }.to change { dossier.champs.map(&:type_champ) }.from(['text', 'text']).to(['integer_number', 'text']) }
|
||||
it { expect { subject }.to change { dossier.champs_public.map(&:type_champ) }.from(['text', 'text']).to(['integer_number', 'text']) }
|
||||
it { expect { subject }.to change { first_champ.class }.from(Champs::TextChamp).to(Champs::IntegerNumberChamp) }
|
||||
it { expect { subject }.to change { first_champ.value }.from('v1').to(nil) }
|
||||
it { expect { subject }.to change { first_champ.external_id }.from('123').to(nil) }
|
||||
|
@ -373,7 +373,7 @@ describe Dossier do
|
|||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:repetition_stable_id) { procedure.draft_revision.types_de_champ.find(&:repetition?) }
|
||||
|
||||
def child_libelles = dossier.champs[0].champs.map(&:libelle)
|
||||
def child_libelles = dossier.champs_public.first.champs.map(&:libelle)
|
||||
|
||||
context 'when a child tdc is added in the middle' do
|
||||
before do
|
||||
|
@ -410,7 +410,7 @@ describe Dossier do
|
|||
tdc_to_update.update(type_champ: :integer_number)
|
||||
end
|
||||
|
||||
it { expect { subject }.to change { dossier.champs[0].champs.map(&:type_champ) }.from(['text', 'text']).to(['integer_number', 'text']) }
|
||||
it { expect { subject }.to change { dossier.champs_public.first.champs.map(&:type_champ) }.from(['text', 'text']).to(['integer_number', 'text']) }
|
||||
end
|
||||
|
||||
context 'when the parents type is changed' do
|
||||
|
@ -420,7 +420,7 @@ describe Dossier do
|
|||
parent.update(type_champ: :integer_number)
|
||||
end
|
||||
|
||||
it { expect { subject }.to change { dossier.champs[0].champs.count }.from(2).to(0) }
|
||||
it { expect { subject }.to change { dossier.champs_public.first.champs.count }.from(2).to(0) }
|
||||
it { expect { subject }.to change { Champ.count }.from(3).to(1) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ describe Dossier do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
it do
|
||||
expect(Dossier.with_champs.find(dossier.id).champs.map(&:libelle)).to match(['l1', 'l2', 'l3'])
|
||||
expect(Dossier.with_champs.find(dossier.id).champs_public.map(&:libelle)).to match(['l1', 'l2', 'l3'])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -264,7 +264,7 @@ describe Dossier do
|
|||
let(:dossier) { create(:dossier, etablissement: etablissement, user: user, procedure: procedure) }
|
||||
let(:france_connect_information) { build(:france_connect_information, given_name: 'Chris', family_name: 'Harrisson') }
|
||||
let(:user) { build(:user, france_connect_information: france_connect_information) }
|
||||
let(:champ_public) { dossier.champs.first }
|
||||
let(:champ_public) { dossier.champs_public.first }
|
||||
let(:champ_private) { dossier.champs_private.first }
|
||||
|
||||
before do
|
||||
|
@ -280,7 +280,7 @@ describe Dossier do
|
|||
context 'with an update' do
|
||||
before do
|
||||
dossier.update(
|
||||
champs_attributes: [{ id: champ_public.id, value: 'nouvelle valeur publique' }],
|
||||
champs_public_attributes: [{ id: champ_public.id, value: 'nouvelle valeur publique' }],
|
||||
champs_private_attributes: [{ id: champ_private.id, value: 'nouvelle valeur privee' }]
|
||||
)
|
||||
end
|
||||
|
@ -295,7 +295,7 @@ describe Dossier do
|
|||
let(:dossier) { create(:dossier, procedure: procedure, user: user) }
|
||||
|
||||
it 'builds public and private champs' do
|
||||
expect(dossier.champs.count).to eq(1)
|
||||
expect(dossier.champs_public.count).to eq(1)
|
||||
expect(dossier.champs_private.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
@ -401,7 +401,7 @@ describe Dossier do
|
|||
let!(:tdc_2) { create(:type_de_champ, libelle: 'l2', position: 2, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
it { expect(dossier.champs.pluck(:libelle)).to match(['l1', 'l2', 'l3']) }
|
||||
it { expect(dossier.champs_public.pluck(:libelle)).to match(['l1', 'l2', 'l3']) }
|
||||
end
|
||||
|
||||
describe '#champs_private' do
|
||||
|
@ -748,7 +748,7 @@ describe Dossier do
|
|||
let(:tdc_8) { { libelle: "unspecified annotation privée-in-body" } }
|
||||
|
||||
before do
|
||||
(dossier.champs + dossier.champs_private)
|
||||
(dossier.champs_public + dossier.champs_private)
|
||||
.filter { |c| c.libelle.match?(/^specified/) }
|
||||
.each { |c| c.update_attribute(:value, "specified") }
|
||||
end
|
||||
|
@ -810,7 +810,7 @@ describe Dossier do
|
|||
it { is_expected.not_to eq(modif_date) }
|
||||
|
||||
context 'when a champ is modified' do
|
||||
before { dossier.champs.first.update_attribute('value', 'yop') }
|
||||
before { dossier.champs_public.first.update_attribute('value', 'yop') }
|
||||
|
||||
it { is_expected.to eq(modif_date) }
|
||||
end
|
||||
|
@ -1187,7 +1187,7 @@ describe Dossier do
|
|||
|
||||
context "with mandatory champs" do
|
||||
let(:type_de_champ) { { mandatory: true } }
|
||||
let(:champ_with_error) { dossier.champs.first }
|
||||
let(:champ_with_error) { dossier.champs_public.first }
|
||||
|
||||
before do
|
||||
champ_with_error.value = nil
|
||||
|
@ -1211,7 +1211,7 @@ describe Dossier do
|
|||
|
||||
context "with mandatory SIRET champ" do
|
||||
let(:type_de_champ) { { type: :siret, mandatory: true } }
|
||||
let(:champ_siret) { dossier.champs.first }
|
||||
let(:champ_siret) { dossier.champs_public.first }
|
||||
|
||||
before do
|
||||
champ_siret.value = '44011762001530'
|
||||
|
@ -1240,38 +1240,38 @@ describe Dossier do
|
|||
let(:type_de_champ_repetition) { revision.types_de_champ.first }
|
||||
|
||||
context "when no champs" do
|
||||
let(:champ_with_error) { dossier.champs.first }
|
||||
let(:champ_with_error) { dossier.champs_public.first }
|
||||
|
||||
it 'should have errors' do
|
||||
dossier.champs.first.champs.destroy_all
|
||||
expect(dossier.champs.first.rows).to be_empty
|
||||
dossier.champs_public.first.champs.destroy_all
|
||||
expect(dossier.champs_public.first.rows).to be_empty
|
||||
expect(errors).not_to be_empty
|
||||
expect(errors.first).to eq("Le champ #{champ_with_error.libelle} doit être rempli.")
|
||||
end
|
||||
end
|
||||
|
||||
context "when mandatory champ inside repetition" do
|
||||
let(:champ_with_error) { dossier.champs.first.champs.first }
|
||||
let(:champ_with_error) { dossier.champs_public.first.champs.first }
|
||||
|
||||
it 'should have errors' do
|
||||
expect(dossier.champs.first.rows).not_to be_empty
|
||||
expect(dossier.champs_public.first.rows).not_to be_empty
|
||||
expect(errors).not_to be_empty
|
||||
expect(errors.first).to eq("Le champ #{champ_with_error.libelle} doit être rempli.")
|
||||
end
|
||||
|
||||
context "conditionaly visible" do
|
||||
let(:champ_with_error) { dossier.champs.second.champs.first }
|
||||
let(:champ_with_error) { dossier.champs_public.second.champs.first }
|
||||
let(:types_de_champ) { [{ type: :yes_no, stable_id: 99 }, type_de_champ] }
|
||||
let(:type_de_champ) { { type: :repetition, mandatory: true, children: [{ mandatory: true }], condition: ds_eq(champ_value(99), constant(true)) } }
|
||||
|
||||
it 'should not have errors' do
|
||||
expect(dossier.champs.second.rows).not_to be_empty
|
||||
expect(dossier.champs_public.second.rows).not_to be_empty
|
||||
expect(errors).to be_empty
|
||||
end
|
||||
|
||||
it 'should have errors' do
|
||||
dossier.champs.first.update(value: 'true')
|
||||
expect(dossier.champs.second.rows).not_to be_empty
|
||||
dossier.champs_public.first.update(value: 'true')
|
||||
expect(dossier.champs_public.second.rows).not_to be_empty
|
||||
expect(errors).not_to be_empty
|
||||
expect(errors.first).to eq("Le champ #{champ_with_error.libelle} doit être rempli.")
|
||||
end
|
||||
|
@ -1427,7 +1427,7 @@ describe Dossier do
|
|||
let(:champ_carte) { create(:champ_carte, type_de_champ: type_de_champ_carte, geo_areas: [geo_area]) }
|
||||
|
||||
before do
|
||||
dossier.champs << champ_carte
|
||||
dossier.champs_public << champ_carte
|
||||
end
|
||||
|
||||
it 'should have all champs carto' do
|
||||
|
@ -1491,12 +1491,12 @@ describe Dossier do
|
|||
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(:repetition_champ) { dossier.champs.find(&:repetition?) }
|
||||
let(:repetition_second_revision_champ) { dossier_second_revision.champs.find(&: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) }
|
||||
let(:dossier_second_revision) { create(:dossier, procedure: procedure) }
|
||||
let(:dossier_champs_for_export) { Dossier.champs_for_export(dossier.champs, procedure.types_de_champ_for_procedure_presentation.not_repetition) }
|
||||
let(:dossier_second_revision_champs_for_export) { Dossier.champs_for_export(dossier_second_revision.champs, procedure.types_de_champ_for_procedure_presentation.not_repetition) }
|
||||
let(:dossier_champs_for_export) { Dossier.champs_for_export(dossier.champs_public, procedure.types_de_champ_for_procedure_presentation.not_repetition) }
|
||||
let(:dossier_second_revision_champs_for_export) { Dossier.champs_for_export(dossier_second_revision.champs_public, procedure.types_de_champ_for_procedure_presentation.not_repetition) }
|
||||
let(:repetition_second_revision_champs_for_export) { Dossier.champs_for_export(repetition_second_revision_champ.champs, procedure.types_de_champ_for_procedure_presentation.repetition) }
|
||||
|
||||
context "when procedure published" do
|
||||
|
@ -1535,7 +1535,7 @@ describe Dossier do
|
|||
repetition = proc_test.types_de_champ_for_procedure_presentation.repetition.first
|
||||
type_champs = proc_test.types_de_champ_for_procedure_presentation(repetition).to_a
|
||||
expect(type_champs.size).to eq(1)
|
||||
expect(Dossier.champs_for_export(dossier.champs, type_champs).size).to eq(3)
|
||||
expect(Dossier.champs_for_export(dossier.champs_public, type_champs).size).to eq(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1556,14 +1556,14 @@ describe Dossier do
|
|||
let(:dossier) { create(:dossier, procedure:) }
|
||||
let(:yes_no_tdc) { procedure.types_de_champ.first }
|
||||
let(:text_tdc) { procedure.types_de_champ.second }
|
||||
let(:tdcs) { dossier.champs.map(&:type_de_champ) }
|
||||
let(:tdcs) { dossier.champs_public.map(&:type_de_champ) }
|
||||
|
||||
subject { Dossier.champs_for_export(dossier.champs, tdcs) }
|
||||
subject { Dossier.champs_for_export(dossier.champs_public, tdcs) }
|
||||
|
||||
before do
|
||||
text_tdc.update(condition: ds_eq(champ_value(yes_no_tdc.stable_id), constant(true)))
|
||||
|
||||
yes_no, text = dossier.champs
|
||||
yes_no, text = dossier.champs_public
|
||||
yes_no.update(value: yes_no_value)
|
||||
text.update(value: 'text')
|
||||
end
|
||||
|
@ -1582,7 +1582,7 @@ describe Dossier 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.map(&:type_de_champ) << tdc_from_another_revision }
|
||||
let(:tdcs) { dossier.champs_public.map(&:type_de_champ) << tdc_from_another_revision }
|
||||
let(:yes_no_value) { 'true' }
|
||||
|
||||
let(:expected) do
|
||||
|
@ -1609,8 +1609,8 @@ describe Dossier do
|
|||
|
||||
before do
|
||||
champ_titre_identite_vide.piece_justificative_file.purge
|
||||
dossier.champs << champ_titre_identite
|
||||
dossier.champs << champ_titre_identite_vide
|
||||
dossier.champs_public << champ_titre_identite
|
||||
dossier.champs_public << champ_titre_identite_vide
|
||||
end
|
||||
|
||||
it "clean up titres identite on accepter" do
|
||||
|
|
|
@ -195,7 +195,7 @@ describe Instructeur, type: :model do
|
|||
end
|
||||
|
||||
context 'when there is a modification on public champs' do
|
||||
before { dossier.champs.first.update_attribute('value', 'toto') }
|
||||
before { dossier.champs_public.first.update_attribute('value', 'toto') }
|
||||
|
||||
it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false }) }
|
||||
end
|
||||
|
@ -301,7 +301,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.first.update_attribute('value', 'toto') }
|
||||
before { dossier_on_procedure_2.champs_public.first.update_attribute('value', 'toto') }
|
||||
|
||||
it { is_expected.to match([]) }
|
||||
end
|
||||
|
|
|
@ -231,8 +231,8 @@ describe ProcedurePresentation do
|
|||
let(:tartine_dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
before do
|
||||
beurre_dossier.champs.first.update(value: 'beurre')
|
||||
tartine_dossier.champs.first.update(value: 'tartine')
|
||||
beurre_dossier.champs_public.first.update(value: 'beurre')
|
||||
tartine_dossier.champs_public.first.update(value: 'tartine')
|
||||
end
|
||||
|
||||
context 'asc' do
|
||||
|
@ -261,8 +261,8 @@ describe ProcedurePresentation do
|
|||
nothing_dossier
|
||||
procedure.draft_revision.add_type_de_champ(tdc)
|
||||
procedure.publish_revision!
|
||||
beurre_dossier.champs.last.update(value: 'beurre')
|
||||
tartine_dossier.champs.last.update(value: 'tartine')
|
||||
beurre_dossier.champs_public.last.update(value: 'beurre')
|
||||
tartine_dossier.champs_public.last.update(value: 'tartine')
|
||||
end
|
||||
|
||||
context 'asc' do
|
||||
|
@ -515,8 +515,8 @@ describe ProcedurePresentation do
|
|||
|
||||
context 'with single value' do
|
||||
before do
|
||||
kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'keep me')
|
||||
discarded_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'discard me')
|
||||
kept_dossier.champs_public.find_by(type_de_champ: type_de_champ).update(value: 'keep me')
|
||||
discarded_dossier.champs_public.find_by(type_de_champ: type_de_champ).update(value: 'discard me')
|
||||
end
|
||||
|
||||
it { is_expected.to contain_exactly(kept_dossier.id) }
|
||||
|
@ -533,9 +533,9 @@ describe ProcedurePresentation do
|
|||
let(:other_kept_dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
before do
|
||||
kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'keep me')
|
||||
discarded_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'discard me')
|
||||
other_kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'and me too')
|
||||
kept_dossier.champs_public.find_by(type_de_champ: type_de_champ).update(value: 'keep me')
|
||||
discarded_dossier.champs_public.find_by(type_de_champ: type_de_champ).update(value: 'discard me')
|
||||
other_kept_dossier.champs_public.find_by(type_de_champ: type_de_champ).update(value: 'and me too')
|
||||
end
|
||||
|
||||
it 'returns every dossier that matches any of the search criteria for a given column' do
|
||||
|
@ -548,8 +548,8 @@ describe ProcedurePresentation do
|
|||
let(:procedure) { create(:procedure, :with_yes_no) }
|
||||
|
||||
before do
|
||||
kept_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'true')
|
||||
discarded_dossier.champs.find_by(type_de_champ: type_de_champ).update(value: 'false')
|
||||
kept_dossier.champs_public.find_by(type_de_champ: type_de_champ).update(value: 'true')
|
||||
discarded_dossier.champs_public.find_by(type_de_champ: type_de_champ).update(value: 'false')
|
||||
end
|
||||
|
||||
it { is_expected.to contain_exactly(kept_dossier.id) }
|
||||
|
|
|
@ -1169,11 +1169,11 @@ describe Procedure do
|
|||
|
||||
it { expect(dossier.procedure).to eq(procedure) }
|
||||
|
||||
it { expect(dossier.champs.size).to eq(2) }
|
||||
it { expect(dossier.champs[0].type).to eq("Champs::TextChamp") }
|
||||
it { expect(dossier.champs_public.size).to eq(2) }
|
||||
it { expect(dossier.champs_public.first.type).to eq("Champs::TextChamp") }
|
||||
|
||||
it { expect(dossier.champs_private.size).to eq(1) }
|
||||
it { expect(dossier.champs_private[0].type).to eq("Champs::TextareaChamp") }
|
||||
it { expect(dossier.champs_private.first.type).to eq("Champs::TextareaChamp") }
|
||||
|
||||
it { expect(Champ.count).to eq(0) }
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ describe ChampPolicy do
|
|||
|
||||
subject { Pundit.policy_scope(account, Champ) }
|
||||
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:champ) { dossier.champs_public.first }
|
||||
let(:champ_private) { dossier.champs_private.first }
|
||||
|
||||
shared_examples_for 'they can access a public champ' do
|
||||
|
|
|
@ -21,11 +21,11 @@ describe DossierSerializer do
|
|||
let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure, :published, :with_type_de_champ)) }
|
||||
|
||||
before do
|
||||
dossier.champs << build(:champ_carte, dossier: dossier)
|
||||
dossier.champs << build(:champ_siret, dossier: dossier)
|
||||
dossier.champs << build(:champ_integer_number, dossier: dossier)
|
||||
dossier.champs << build(:champ_decimal_number, dossier: dossier)
|
||||
dossier.champs << build(:champ_linked_drop_down_list, dossier: dossier)
|
||||
dossier.champs_public << build(:champ_carte, dossier: dossier)
|
||||
dossier.champs_public << build(:champ_siret, dossier: dossier)
|
||||
dossier.champs_public << build(:champ_integer_number, dossier: dossier)
|
||||
dossier.champs_public << build(:champ_decimal_number, dossier: dossier)
|
||||
dossier.champs_public << build(:champ_linked_drop_down_list, dossier: dossier)
|
||||
end
|
||||
|
||||
it {
|
||||
|
@ -58,7 +58,7 @@ describe DossierSerializer do
|
|||
end
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ_public: [cloned_type_de_champ]) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:champ_pj) { dossier.champs.last }
|
||||
let(:champ_pj) { dossier.champs_public.last }
|
||||
|
||||
before do
|
||||
champ_pj.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
||||
|
|
|
@ -19,9 +19,9 @@ describe DossierProjectionService do
|
|||
end
|
||||
|
||||
before do
|
||||
dossier_1.champs.first.update(value: 'champ_1')
|
||||
dossier_2.champs.first.update(value: 'champ_2')
|
||||
dossier_3.champs.first.destroy
|
||||
dossier_1.champs_public.first.update(value: 'champ_1')
|
||||
dossier_2.champs_public.first.update(value: 'champ_2')
|
||||
dossier_3.champs_public.first.destroy
|
||||
end
|
||||
|
||||
let(:result) { subject }
|
||||
|
@ -155,7 +155,7 @@ describe DossierProjectionService do
|
|||
let(:dossier) { create(:dossier) }
|
||||
let(:column) { dossier.procedure.types_de_champ.first.stable_id.to_s }
|
||||
|
||||
before { dossier.champs.first.update(value: 'kale') }
|
||||
before { dossier.champs_public.first.update(value: 'kale') }
|
||||
|
||||
it { is_expected.to eq('kale') }
|
||||
end
|
||||
|
@ -176,7 +176,7 @@ describe DossierProjectionService do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:column) { dossier.procedure.types_de_champ.first.stable_id.to_s }
|
||||
|
||||
before { dossier.champs.first.update(value: 'true') }
|
||||
before { dossier.champs_public.first.update(value: 'true') }
|
||||
|
||||
it { is_expected.to eq('Oui') }
|
||||
end
|
||||
|
@ -187,7 +187,7 @@ describe DossierProjectionService do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:column) { dossier.procedure.types_de_champ.first.stable_id.to_s }
|
||||
|
||||
before { dossier.champs.first.update(data: { 'label' => '18 a la bonne rue', 'departement' => 'd' }) }
|
||||
before { dossier.champs_public.first.update(data: { 'label' => '18 a la bonne rue', 'departement' => 'd' }) }
|
||||
|
||||
it { is_expected.to eq('18 a la bonne rue') }
|
||||
end
|
||||
|
@ -204,7 +204,7 @@ describe DossierProjectionService do
|
|||
|
||||
context 'when external id is set' do
|
||||
before do
|
||||
dossier.champs.first.update(external_id: 'GB')
|
||||
dossier.champs_public.first.update(external_id: 'GB')
|
||||
end
|
||||
|
||||
it { is_expected.to eq('Royaume-Uni') }
|
||||
|
@ -212,7 +212,7 @@ describe DossierProjectionService do
|
|||
|
||||
context 'when no external id is set' do
|
||||
before do
|
||||
dossier.champs.first.update(value: "qu'il est beau mon pays")
|
||||
dossier.champs_public.first.update(value: "qu'il est beau mon pays")
|
||||
end
|
||||
|
||||
it { is_expected.to eq("qu'il est beau mon pays") }
|
||||
|
|
|
@ -13,7 +13,7 @@ describe PiecesJustificativesService do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:witness) { create(:dossier, procedure: procedure) }
|
||||
|
||||
let(:pj_champ) { -> (d) { d.champs.find { |c| c.type == 'Champs::PieceJustificativeChamp' } } }
|
||||
let(:pj_champ) { -> (d) { d.champs_public.find { |c| c.type == 'Champs::PieceJustificativeChamp' } } }
|
||||
|
||||
before do
|
||||
attach_file_to_champ(pj_champ.call(dossier))
|
||||
|
@ -26,7 +26,7 @@ describe PiecesJustificativesService do
|
|||
context 'with a pj not safe on a champ' do
|
||||
let(:procedure) { create(:procedure, :with_piece_justificative) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:pj_champ) { -> (d) { d.champs.find { |c| c.type == 'Champs::PieceJustificativeChamp' } } }
|
||||
let(:pj_champ) { -> (d) { d.champs_public.find { |c| c.type == 'Champs::PieceJustificativeChamp' } } }
|
||||
|
||||
before { attach_file_to_champ(pj_champ.call(dossier), safe = false) }
|
||||
|
||||
|
@ -60,7 +60,7 @@ describe PiecesJustificativesService do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:witness) { create(:dossier, procedure: procedure) }
|
||||
|
||||
let(:champ_identite) { dossier.champs.find { |c| c.type == 'Champs::TitreIdentiteChamp' } }
|
||||
let(:champ_identite) { dossier.champs_public.find { |c| c.type == 'Champs::TitreIdentiteChamp' } }
|
||||
|
||||
before { attach_file_to_champ(champ_identite) }
|
||||
|
||||
|
|
|
@ -348,7 +348,7 @@ describe ProcedureExportService do
|
|||
create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure)
|
||||
]
|
||||
end
|
||||
let(:champ_repetition) { dossiers.first.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||
let(:champ_repetition) { dossiers.first.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.libelle_for_export])
|
||||
|
@ -402,7 +402,7 @@ describe ProcedureExportService do
|
|||
|
||||
context 'with non unique labels' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
|
||||
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||
let(:champ_repetition) { dossier.champs_public.find { |champ| champ.type_champ == 'repetition' } }
|
||||
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, procedure: procedure, libelle: champ_repetition.libelle) }
|
||||
let!(:another_champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
|
||||
|
||||
|
@ -413,7 +413,7 @@ describe ProcedureExportService do
|
|||
|
||||
context 'with empty repetition' do
|
||||
before do
|
||||
dossiers.flat_map { |dossier| dossier.champs.filter(&:repetition?) }.each do |champ|
|
||||
dossiers.flat_map { |dossier| dossier.champs_public.filter(&:repetition?) }.each do |champ|
|
||||
champ.champs.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -277,7 +277,7 @@ describe 'fetch API Particulier Data', js: true do
|
|||
wait_for_autosave
|
||||
|
||||
dossier = Dossier.last
|
||||
cnaf_champ = dossier.champs.find(&:cnaf?)
|
||||
cnaf_champ = dossier.champs_public.find(&:cnaf?)
|
||||
|
||||
wait_until { cnaf_champ.reload.code_postal == 'wrong_code' }
|
||||
|
||||
|
@ -332,7 +332,7 @@ describe 'fetch API Particulier Data', js: true do
|
|||
wait_for_autosave
|
||||
|
||||
dossier = Dossier.last
|
||||
pole_emploi_champ = dossier.champs.find(&:pole_emploi?)
|
||||
pole_emploi_champ = dossier.champs_public.find(&:pole_emploi?)
|
||||
|
||||
wait_until { pole_emploi_champ.reload.identifiant == 'wrong code' }
|
||||
|
||||
|
@ -403,7 +403,7 @@ describe 'fetch API Particulier Data', js: true do
|
|||
wait_for_autosave
|
||||
|
||||
dossier = Dossier.last
|
||||
mesri_champ = dossier.champs.find(&:mesri?)
|
||||
mesri_champ = dossier.champs_public.find(&:mesri?)
|
||||
|
||||
wait_until { mesri_champ.reload.ine == 'wrong code' }
|
||||
clear_enqueued_jobs
|
||||
|
@ -465,7 +465,7 @@ describe 'fetch API Particulier Data', js: true do
|
|||
wait_for_autosave
|
||||
|
||||
dossier = Dossier.last
|
||||
dgfip_champ = dossier.champs.find(&:dgfip?)
|
||||
dgfip_champ = dossier.champs_public.find(&:dgfip?)
|
||||
|
||||
wait_until { dgfip_champ.reload.reference_avis == 'wrong_code' }
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ describe 'Inviting an expert:' do
|
|||
let(:procedure) { create(:procedure, :published, :with_piece_justificative, instructeurs: [instructeur]) }
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:champ) { dossier.champs_public.first }
|
||||
let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }
|
||||
|
||||
context 'when I don’t already have an account' do
|
||||
|
|
|
@ -8,7 +8,7 @@ describe 'Inviting an expert:', js: true do
|
|||
let(:expert_password) { 'mot de passe d’expert' }
|
||||
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.filter(&:dossier_link?).filter_map(&:value)) }
|
||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs_public.filter(&:dossier_link?).filter_map(&:value)) }
|
||||
|
||||
before do
|
||||
clear_emails
|
||||
|
|
|
@ -197,7 +197,7 @@ describe 'Instructing a dossier:', js: true do
|
|||
context 'with dossiers having attached files', js: true do
|
||||
let(:procedure) { create(:procedure, :published, :with_piece_justificative, instructeurs: [instructeur]) }
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:champ) { dossier.champs_public.first }
|
||||
let(:path) { 'spec/fixtures/files/piece_justificative_0.pdf' }
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ describe "procedure sort" do
|
|||
|
||||
before do
|
||||
instructeur.follow(followed_dossier)
|
||||
followed_dossier.champs.first.update(value: '123')
|
||||
followed_dossier.champs_public.first.update(value: '123')
|
||||
|
||||
login_as(instructeur.user, scope: :user)
|
||||
visit instructeur_procedure_path(procedure)
|
||||
|
|
|
@ -116,7 +116,7 @@ describe 'The routing', js: true do
|
|||
click_on litteraire_user.dossiers.first.id.to_s
|
||||
click_on 'Modifier mon dossier'
|
||||
|
||||
fill_in litteraire_user.dossiers.first.champs.first.libelle, with: 'some value'
|
||||
fill_in litteraire_user.dossiers.first.champs_public.first.libelle, with: 'some value'
|
||||
wait_for_autosave(false)
|
||||
|
||||
log_out
|
||||
|
|
|
@ -466,7 +466,7 @@ describe 'The user' do
|
|||
end
|
||||
|
||||
def champ_value_for(libelle)
|
||||
champs = user_dossier.reload.champs
|
||||
champs = user_dossier.reload.champs_public
|
||||
champs.find { |c| c.libelle == libelle }.value
|
||||
end
|
||||
|
||||
|
|
|
@ -51,8 +51,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.first.value == "Secondary 1.2" }
|
||||
expect(user_dossier.champs.first.value).to eq("Secondary 1.2")
|
||||
wait_until { user_dossier.champs_public.first.value == "Secondary 1.2" }
|
||||
expect(user_dossier.champs_public.first.value).to eq("Secondary 1.2")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ describe 'user access to the list of their dossiers', js: true do
|
|||
context "when user search for something inside the dossier" do
|
||||
let(:dossier_en_construction2) { create(:dossier, :with_populated_champs, :en_construction, user: user) }
|
||||
before do
|
||||
page.find_by_id('q').set(dossier_en_construction.champs.first.value)
|
||||
page.find_by_id('q').set(dossier_en_construction.champs_public.first.value)
|
||||
end
|
||||
|
||||
context 'when it only matches one dossier' do
|
||||
|
@ -137,7 +137,7 @@ describe 'user access to the list of their dossiers', js: true do
|
|||
|
||||
context 'when it matches multiple dossier' do
|
||||
before do
|
||||
dossier_en_construction2.champs.first.update(value: dossier_en_construction.champs.first.value)
|
||||
dossier_en_construction2.champs_public.first.update(value: dossier_en_construction.champs_public.first.value)
|
||||
find('.fr-search-bar .fr-btn').click
|
||||
end
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ describe 'shared/dossiers/demande.html.haml', type: :view do
|
|||
let(:procedure) { create(:procedure, :published, :with_type_de_champ) }
|
||||
|
||||
it 'renders the champs' do
|
||||
dossier.champs.each do |champ|
|
||||
dossier.champs_public.each do |champ|
|
||||
expect(subject).to include(champ.libelle)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
|
|||
let(:champ_textarea) { create(:champ_textarea, dossier: dossier, value: 'Some long text in a textarea.') }
|
||||
let(:champs) { [champ_checkbox, champ_header_section, champ_explication, champ_dossier_link, champ_textarea] }
|
||||
|
||||
before { dossier.champs << champs }
|
||||
before { dossier.champs_public << champs }
|
||||
|
||||
it 'renders labels and editable values of champs' do
|
||||
expect(subject).to have_field(champ_checkbox.libelle, checked: true)
|
||||
|
@ -45,7 +45,7 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
|
|||
let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options }
|
||||
let(:mandatory) { true }
|
||||
|
||||
before { dossier.champs << champ }
|
||||
before { dossier.champs_public << champ }
|
||||
|
||||
context 'when the list is short' do
|
||||
it 'renders the list as radio buttons' do
|
||||
|
@ -78,7 +78,7 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
|
|||
let(:options) { type_de_champ.drop_down_list_options }
|
||||
let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options }
|
||||
|
||||
before { dossier.champs << champ }
|
||||
before { dossier.champs_public << champ }
|
||||
|
||||
context 'when the list is short' do
|
||||
let(:drop_down_list_value) { ['valid', 'invalid', 'not sure yet'].join("\r\n") }
|
||||
|
@ -111,7 +111,7 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
|
|||
|
||||
context 'when dossier is en construction' do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
before { dossier.champs << champ }
|
||||
before { dossier.champs_public << champ }
|
||||
|
||||
it 'cannot delete a piece justificative' do
|
||||
expect(subject).not_to have_text('Supprimer')
|
||||
|
@ -120,7 +120,7 @@ describe 'shared/dossiers/edit.html.haml', type: :view do
|
|||
|
||||
context 'when dossier is brouillon' do
|
||||
before do
|
||||
dossier.champs << champ
|
||||
dossier.champs_public << champ
|
||||
end
|
||||
|
||||
it 'can delete a piece justificative' do
|
||||
|
|
Loading…
Reference in a new issue