Merge pull request #5494 from betagouv/dev

2020-08-20-01
This commit is contained in:
krichtof 2020-08-20 16:08:57 +02:00 committed by GitHub
commit 770765c4f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 590 additions and 435 deletions

View file

@ -9,14 +9,11 @@ module EtablissementHelper
end end
def raison_sociale_or_name(etablissement) def raison_sociale_or_name(etablissement)
if etablissement.association? etablissement.association_titre.presence ||
etablissement.association_titre etablissement.enseigne.presence ||
elsif etablissement.entreprise_raison_sociale.present? etablissement.entreprise_raison_sociale.presence ||
etablissement.entreprise_raison_sociale
else
"#{etablissement.entreprise_nom} #{etablissement.entreprise_prenom}" "#{etablissement.entreprise_nom} #{etablissement.entreprise_prenom}"
end end
end
def effectif(etablissement) def effectif(etablissement)
{ {

View file

@ -25,6 +25,7 @@ class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter
:siege_social, :siege_social,
:naf, :naf,
:libelle_naf, :libelle_naf,
:enseigne,
:diffusable_commercialement :diffusable_commercialement
] ]
end end

View file

@ -14,8 +14,8 @@
# procedure_id :integer # procedure_id :integer
# #
class AssignTo < ApplicationRecord class AssignTo < ApplicationRecord
belongs_to :instructeur belongs_to :instructeur, optional: false
belongs_to :groupe_instructeur belongs_to :groupe_instructeur, optional: false
has_one :procedure_presentation, dependent: :destroy has_one :procedure_presentation, dependent: :destroy
has_one :procedure, through: :groupe_instructeur has_one :procedure, through: :groupe_instructeur

View file

@ -9,7 +9,7 @@
# dossier_id :integer not null # dossier_id :integer not null
# #
class Attestation < ApplicationRecord class Attestation < ApplicationRecord
belongs_to :dossier belongs_to :dossier, optional: false
has_one_attached :pdf has_one_attached :pdf

View file

@ -15,7 +15,7 @@ class AttestationTemplate < ApplicationRecord
include ActionView::Helpers::NumberHelper include ActionView::Helpers::NumberHelper
include TagsSubstitutionConcern include TagsSubstitutionConcern
belongs_to :procedure belongs_to :procedure, optional: false
has_one_attached :logo has_one_attached :logo
has_one_attached :signature has_one_attached :signature

View file

@ -17,9 +17,9 @@
class Avis < ApplicationRecord class Avis < ApplicationRecord
include EmailSanitizableConcern include EmailSanitizableConcern
belongs_to :dossier, inverse_of: :avis, touch: true belongs_to :dossier, inverse_of: :avis, touch: true, optional: false
belongs_to :instructeur belongs_to :instructeur, optional: true
belongs_to :claimant, class_name: 'Instructeur' belongs_to :claimant, class_name: 'Instructeur', optional: false
has_one_attached :piece_justificative_file has_one_attached :piece_justificative_file
has_one_attached :introduction_file has_one_attached :introduction_file

View file

@ -15,16 +15,16 @@
# type_de_champ_id :integer # type_de_champ_id :integer
# #
class Champ < ApplicationRecord class Champ < ApplicationRecord
belongs_to :dossier, -> { with_discarded }, inverse_of: :champs, touch: true belongs_to :dossier, -> { with_discarded }, inverse_of: :champs, touch: true, optional: false
belongs_to :type_de_champ, inverse_of: :champ belongs_to :type_de_champ, inverse_of: :champ, optional: false
belongs_to :parent, class_name: 'Champ' belongs_to :parent, class_name: 'Champ', optional: true
has_many :commentaires has_many :commentaires
has_one_attached :piece_justificative_file has_one_attached :piece_justificative_file
# We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp) # We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp)
# here because otherwise we can't easily use includes in our queries. # here because otherwise we can't easily use includes in our queries.
has_many :geo_areas, dependent: :destroy has_many :geo_areas, dependent: :destroy
belongs_to :etablissement, dependent: :destroy belongs_to :etablissement, optional: true, dependent: :destroy
has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
delegate :libelle, delegate :libelle,
@ -49,7 +49,7 @@ class Champ < ApplicationRecord
scope :ordered, -> { includes(:type_de_champ).order(:row, 'types_de_champ.order_place') } scope :ordered, -> { includes(:type_de_champ).order(:row, 'types_de_champ.order_place') }
scope :root, -> { where(parent_id: nil) } scope :root, -> { where(parent_id: nil) }
before_create :set_dossier_id, if: :needs_dossier_id? before_validation :set_dossier_id, if: :needs_dossier_id?
validates :type_de_champ_id, uniqueness: { scope: [:dossier_id, :row] } validates :type_de_champ_id, uniqueness: { scope: [:dossier_id, :row] }

View file

@ -15,4 +15,10 @@
# type_de_champ_id :integer # type_de_champ_id :integer
# #
class Champs::PhoneChamp < Champs::TextChamp class Champs::PhoneChamp < Champs::TextChamp
validates :value,
phone: {
possible: true,
allow_blank: true,
message: I18n.t(:not_a_phone, scope: 'activerecord.errors.messages')
}
end end

View file

@ -12,10 +12,10 @@
# user_id :bigint # user_id :bigint
# #
class Commentaire < ApplicationRecord class Commentaire < ApplicationRecord
belongs_to :dossier, inverse_of: :commentaires, touch: true belongs_to :dossier, inverse_of: :commentaires, touch: true, optional: false
belongs_to :user belongs_to :user, optional: true
belongs_to :instructeur belongs_to :instructeur, optional: true
validate :messagerie_available?, on: :create validate :messagerie_available?, on: :create

View file

@ -12,7 +12,7 @@
# procedure_id :bigint # procedure_id :bigint
# #
class DeletedDossier < ApplicationRecord class DeletedDossier < ApplicationRecord
belongs_to :procedure, -> { with_discarded }, inverse_of: :deleted_dossiers belongs_to :procedure, -> { with_discarded }, inverse_of: :deleted_dossiers, optional: false
validates :dossier_id, uniqueness: true validates :dossier_id, uniqueness: true

View file

@ -75,10 +75,10 @@ class Dossier < ApplicationRecord
has_many :dossier_operation_logs, -> { order(:created_at) }, dependent: :nullify, inverse_of: :dossier has_many :dossier_operation_logs, -> { order(:created_at) }, dependent: :nullify, inverse_of: :dossier
belongs_to :groupe_instructeur belongs_to :groupe_instructeur, optional: false
has_one :procedure, through: :groupe_instructeur has_one :procedure, through: :groupe_instructeur
belongs_to :revision, class_name: 'ProcedureRevision', optional: true belongs_to :revision, class_name: 'ProcedureRevision', optional: true
belongs_to :user belongs_to :user, optional: false
accepts_nested_attributes_for :champs accepts_nested_attributes_for :champs
accepts_nested_attributes_for :champs_private accepts_nested_attributes_for :champs_private

View file

@ -14,6 +14,7 @@
# code_postal :string # code_postal :string
# complement_adresse :string # complement_adresse :string
# diffusable_commercialement :boolean # diffusable_commercialement :boolean
# enseigne :string
# entreprise_bilans_bdf :jsonb # entreprise_bilans_bdf :jsonb
# entreprise_bilans_bdf_monnaie :string # entreprise_bilans_bdf_monnaie :string
# entreprise_capital_social :bigint # entreprise_capital_social :bigint
@ -47,7 +48,7 @@
# entreprise_id :integer # entreprise_id :integer
# #
class Etablissement < ApplicationRecord class Etablissement < ApplicationRecord
belongs_to :dossier belongs_to :dossier, optional: true
has_one :champ, class_name: 'Champs::SiretChamp' has_one :champ, class_name: 'Champs::SiretChamp'
has_many :exercices, dependent: :destroy has_many :exercices, dependent: :destroy
@ -75,6 +76,7 @@ class Etablissement < ApplicationRecord
association_titre, association_titre,
association_objet, association_objet,
siret, siret,
enseigne,
naf, naf,
libelle_naf, libelle_naf,
adresse, adresse,
@ -89,6 +91,7 @@ class Etablissement < ApplicationRecord
['Dossier ID', :dossier_id_for_export], ['Dossier ID', :dossier_id_for_export],
['Champ', :libelle_for_export], ['Champ', :libelle_for_export],
['Établissement SIRET', :siret], ['Établissement SIRET', :siret],
['Etablissement enseigne', :enseigne],
['Établissement siège social', :siege_social], ['Établissement siège social', :siege_social],
['Établissement NAF', :naf], ['Établissement NAF', :naf],
['Établissement libellé NAF', :libelle_naf], ['Établissement libellé NAF', :libelle_naf],

View file

@ -12,7 +12,7 @@
# etablissement_id :integer # etablissement_id :integer
# #
class Exercice < ApplicationRecord class Exercice < ApplicationRecord
belongs_to :etablissement belongs_to :etablissement, optional: false
validates :ca, presence: true, allow_blank: false, allow_nil: false validates :ca, presence: true, allow_blank: false, allow_nil: false
end end

View file

@ -9,7 +9,7 @@
# user_id :bigint # user_id :bigint
# #
class Feedback < ApplicationRecord class Feedback < ApplicationRecord
belongs_to :user belongs_to :user, optional: false
enum rating: { enum rating: {
happy: 'happy', happy: 'happy',

View file

@ -14,8 +14,8 @@
# instructeur_id :integer not null # instructeur_id :integer not null
# #
class Follow < ApplicationRecord class Follow < ApplicationRecord
belongs_to :instructeur belongs_to :instructeur, optional: false
belongs_to :dossier belongs_to :dossier, optional: false
validates :instructeur_id, uniqueness: { scope: [:dossier_id, :unfollowed_at] } validates :instructeur_id, uniqueness: { scope: [:dossier_id, :unfollowed_at] }

View file

@ -15,7 +15,7 @@
# user_id :integer # user_id :integer
# #
class FranceConnectInformation < ApplicationRecord class FranceConnectInformation < ApplicationRecord
belongs_to :user belongs_to :user, optional: true
validates :france_connect_particulier_id, presence: true, allow_blank: false, allow_nil: false validates :france_connect_particulier_id, presence: true, allow_blank: false, allow_nil: false
end end

View file

@ -12,7 +12,7 @@
# geo_reference_id :string # geo_reference_id :string
# #
class GeoArea < ApplicationRecord class GeoArea < ApplicationRecord
belongs_to :champ belongs_to :champ, optional: false
store :properties, accessors: [ store :properties, accessors: [
:description, :description,

View file

@ -10,7 +10,7 @@
# #
class GroupeInstructeur < ApplicationRecord class GroupeInstructeur < ApplicationRecord
DEFAULT_LABEL = 'défaut' DEFAULT_LABEL = 'défaut'
belongs_to :procedure, -> { with_discarded }, inverse_of: :groupe_instructeurs belongs_to :procedure, -> { with_discarded }, inverse_of: :groupe_instructeurs, optional: false
has_many :assign_tos, dependent: :destroy has_many :assign_tos, dependent: :destroy
has_many :instructeurs, through: :assign_tos has_many :instructeurs, through: :assign_tos
has_many :dossiers has_many :dossiers

View file

@ -12,7 +12,7 @@
# dossier_id :integer # dossier_id :integer
# #
class Individual < ApplicationRecord class Individual < ApplicationRecord
belongs_to :dossier belongs_to :dossier, optional: false
validates :dossier_id, uniqueness: true validates :dossier_id, uniqueness: true
validates :gender, presence: true, allow_nil: false, on: :update validates :gender, presence: true, allow_nil: false, on: :update

View file

@ -14,8 +14,8 @@
class Invite < ApplicationRecord class Invite < ApplicationRecord
include EmailSanitizableConcern include EmailSanitizableConcern
belongs_to :dossier belongs_to :dossier, optional: false
belongs_to :user belongs_to :user, optional: true
before_validation -> { sanitize_email(:email) } before_validation -> { sanitize_email(:email) }

View file

@ -13,7 +13,7 @@ module Mails
class ClosedMail < ApplicationRecord class ClosedMail < ApplicationRecord
include MailTemplateConcern include MailTemplateConcern
belongs_to :procedure belongs_to :procedure, optional: false
SLUG = "closed_mail" SLUG = "closed_mail"
DISPLAYED_NAME = "Accusé d'acceptation" DISPLAYED_NAME = "Accusé d'acceptation"

View file

@ -13,7 +13,7 @@ module Mails
class InitiatedMail < ApplicationRecord class InitiatedMail < ApplicationRecord
include MailTemplateConcern include MailTemplateConcern
belongs_to :procedure belongs_to :procedure, optional: false
SLUG = "initiated_mail" SLUG = "initiated_mail"
DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/initiated_mail" DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/initiated_mail"

View file

@ -13,7 +13,7 @@ module Mails
class ReceivedMail < ApplicationRecord class ReceivedMail < ApplicationRecord
include MailTemplateConcern include MailTemplateConcern
belongs_to :procedure belongs_to :procedure, optional: false
SLUG = "received_mail" SLUG = "received_mail"
DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/received_mail" DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/received_mail"

View file

@ -13,7 +13,7 @@ module Mails
class RefusedMail < ApplicationRecord class RefusedMail < ApplicationRecord
include MailTemplateConcern include MailTemplateConcern
belongs_to :procedure belongs_to :procedure, optional: false
SLUG = "refused_mail" SLUG = "refused_mail"
DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/refused_mail" DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/refused_mail"

View file

@ -13,7 +13,7 @@ module Mails
class WithoutContinuationMail < ApplicationRecord class WithoutContinuationMail < ApplicationRecord
include MailTemplateConcern include MailTemplateConcern
belongs_to :procedure belongs_to :procedure, optional: false
SLUG = "without_continuation" SLUG = "without_continuation"
DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/without_continuation_mail" DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/without_continuation_mail"

View file

@ -12,5 +12,5 @@
# procedure_id :integer # procedure_id :integer
# #
class ModuleAPICarto < ApplicationRecord class ModuleAPICarto < ApplicationRecord
belongs_to :procedure belongs_to :procedure, optional: false
end end

View file

@ -66,9 +66,9 @@ class Procedure < ApplicationRecord
has_one :module_api_carto, dependent: :destroy has_one :module_api_carto, dependent: :destroy
has_one :attestation_template, dependent: :destroy has_one :attestation_template, dependent: :destroy
belongs_to :parent_procedure, class_name: 'Procedure' belongs_to :parent_procedure, class_name: 'Procedure', optional: true
belongs_to :canonical_procedure, class_name: 'Procedure' belongs_to :canonical_procedure, class_name: 'Procedure', optional: true
belongs_to :service belongs_to :service, optional: true
def active_revision def active_revision
brouillon? ? draft_revision : published_revision brouillon? ? draft_revision : published_revision

View file

@ -16,7 +16,7 @@ class ProcedurePresentation < ApplicationRecord
'self' => ['id', 'state'] 'self' => ['id', 'state']
} }
belongs_to :assign_to belongs_to :assign_to, optional: false
delegate :procedure, to: :assign_to delegate :procedure, to: :assign_to

View file

@ -16,7 +16,7 @@
# #
class Service < ApplicationRecord class Service < ApplicationRecord
has_many :procedures has_many :procedures
belongs_to :administrateur belongs_to :administrateur, optional: false
scope :ordered, -> { order(nom: :asc) } scope :ordered, -> { order(nom: :asc) }

View file

@ -10,7 +10,7 @@
# dossier_id :bigint # dossier_id :bigint
# #
class Traitement < ApplicationRecord class Traitement < ApplicationRecord
belongs_to :dossier belongs_to :dossier, optional: false
scope :termine_close_to_expiration, -> do scope :termine_close_to_expiration, -> do
joins(dossier: :procedure) joins(dossier: :procedure)

View file

@ -12,7 +12,7 @@ class TrustedDeviceToken < ApplicationRecord
LOGIN_TOKEN_VALIDITY = 1.week LOGIN_TOKEN_VALIDITY = 1.week
LOGIN_TOKEN_YOUTH = 15.minutes LOGIN_TOKEN_YOUTH = 15.minutes
belongs_to :instructeur belongs_to :instructeur, optional: false
has_secure_token has_secure_token
def token_valid? def token_valid?

View file

@ -49,10 +49,10 @@ class TypeDeChamp < ApplicationRecord
repetition: 'repetition' repetition: 'repetition'
} }
belongs_to :procedure belongs_to :procedure, optional: false
belongs_to :revision, class_name: 'ProcedureRevision', optional: true belongs_to :revision, class_name: 'ProcedureRevision', optional: true
belongs_to :parent, class_name: 'TypeDeChamp' belongs_to :parent, class_name: 'TypeDeChamp', optional: true
has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy
store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles, :old_pj, :drop_down_options, :skip_pj_validation store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles, :old_pj, :drop_down_options, :skip_pj_validation
@ -73,8 +73,8 @@ class TypeDeChamp < ApplicationRecord
serialize :options, WithIndifferentAccess serialize :options, WithIndifferentAccess
after_initialize :set_dynamic_type after_initialize :set_dynamic_type
before_validation :setup_procedure
after_create :populate_stable_id after_create :populate_stable_id
before_save :setup_procedure
attr_reader :dynamic_type attr_reader :dynamic_type

View file

@ -45,8 +45,8 @@ class User < ApplicationRecord
has_many :dossiers_invites, through: :invites, source: :dossier has_many :dossiers_invites, through: :invites, source: :dossier
has_many :feedbacks, dependent: :destroy has_many :feedbacks, dependent: :destroy
has_one :france_connect_information, dependent: :destroy has_one :france_connect_information, dependent: :destroy
belongs_to :instructeur belongs_to :instructeur, optional: true
belongs_to :administrateur belongs_to :administrateur, optional: true
accepts_nested_attributes_for :france_connect_information accepts_nested_attributes_for :france_connect_information

View file

@ -11,6 +11,6 @@
= f.email_field :email, value: @email, disabled: true = f.email_field :email, value: @email, disabled: true
= f.label :password, "Mot de passe" = f.label :password, "Mot de passe"
= f.password_field :password, autofocus: true, required: true, placeholder: "#{PASSWORD_MIN_LENGTH} caractères minimum" = f.password_field :password, required: true, placeholder: "#{PASSWORD_MIN_LENGTH} caractères minimum"
= f.submit "Créer un compte", class: "button large primary expand" = f.submit "Créer un compte", class: "button large primary expand"

View file

@ -1,3 +1,4 @@
= form.date_field :value, = form.date_field :value,
value: champ.value, value: champ.value,
required: champ.mandatory? required: champ.mandatory?,
placeholder: 'aaaa-mm-jj'

View file

@ -1,23 +1,7 @@
-# Allowed formats: -# Allowed formats:
-# 0123456789 -# very light validation is made client-side
-# 01 23 45 67 89 -# stronger validation is made server-side
-# 01.23.45.67.89
-# 0123 45.67.89
-# 0033 123-456-789
-# 0035 123-456-789
-# 0033 123-456-789
-# 0033(0)123456789
-# +33-1.23.45.67.89
-# +33 - 123 456 789
-# +33(0) 123 456 789
-# +33 (0)123 45 67 89
-# +33 (0)1 2345-6789
-# +33(0) - 123456789
-# +1(0) - 123456789
-# +2 123456789
-# 012345678
-# 01234567890
= form.phone_field :value, = form.phone_field :value,
placeholder: champ.libelle, placeholder: champ.libelle,
required: champ.mandatory?, required: champ.mandatory?,
pattern: "([\\+\\d\\(][\\(\\)\\s\\.\\-\\d]{4,}\\d)" pattern: "[^a-z^A-Z]+"

View file

@ -45,12 +45,6 @@ module TPS
default_allowed_tags = ['strong', 'em', 'b', 'i', 'p', 'code', 'pre', 'tt', 'samp', 'kbd', 'var', 'sub', 'sup', 'dfn', 'cite', 'big', 'small', 'address', 'hr', 'br', 'div', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'abbr', 'acronym', 'a', 'img', 'blockquote', 'del', 'ins'] default_allowed_tags = ['strong', 'em', 'b', 'i', 'p', 'code', 'pre', 'tt', 'samp', 'kbd', 'var', 'sub', 'sup', 'dfn', 'cite', 'big', 'small', 'address', 'hr', 'br', 'div', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'abbr', 'acronym', 'a', 'img', 'blockquote', 'del', 'ins']
config.action_view.sanitized_allowed_tags = default_allowed_tags + ['u'] config.action_view.sanitized_allowed_tags = default_allowed_tags + ['u']
# Since Rails 5.0, this option is enabled by default.
# However we keep it disabled for now, because many of our specs and fatories
# do not build the required associations properly.
# TODO: fix the specs, and enable this option.
config.active_record.belongs_to_required_by_default = false
# Some mobile browsers have a behaviour where, although they will delete the session # Some mobile browsers have a behaviour where, although they will delete the session
# cookie when the browser shutdowns, they will still serve a cached version # cookie when the browser shutdowns, they will still serve a cached version
# of the page on relaunch. # of the page on relaunch.

View file

@ -129,6 +129,7 @@ fr:
blank: "doit être rempli" blank: "doit être rempli"
not_a_number: 'doit être un nombre' not_a_number: 'doit être un nombre'
not_an_integer: 'doit être un nombre entier (sans chiffres après la virgule)' not_an_integer: 'doit être un nombre entier (sans chiffres après la virgule)'
not_a_phone: 'Numéro de téléphone invalide'
greater_than: "doit être supérieur à %{count}" greater_than: "doit être supérieur à %{count}"
greater_than_or_equal_to: "doit être supérieur ou égal à %{count}" greater_than_or_equal_to: "doit être supérieur ou égal à %{count}"
less_than: "doit être inférieur à %{count}" less_than: "doit être inférieur à %{count}"

View file

@ -0,0 +1,5 @@
class AddEnseigneToEtablissements < ActiveRecord::Migration[6.0]
def change
add_column :etablissements, :enseigne, :string
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_07_22_135121) do ActiveRecord::Schema.define(version: 2020_08_19_153016) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -323,6 +323,7 @@ ActiveRecord::Schema.define(version: 2020_07_22_135121) do
t.string "entreprise_effectif_annuel_annee" t.string "entreprise_effectif_annuel_annee"
t.jsonb "entreprise_bilans_bdf" t.jsonb "entreprise_bilans_bdf"
t.string "entreprise_bilans_bdf_monnaie" t.string "entreprise_bilans_bdf_monnaie"
t.string "enseigne"
t.index ["dossier_id"], name: "index_etablissements_on_dossier_id" t.index ["dossier_id"], name: "index_etablissements_on_dossier_id"
end end

View file

@ -1,14 +1,14 @@
describe Champs::SiretController, type: :controller do describe Champs::SiretController, type: :controller do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) } let(:procedure) do
tdc_siret = build(:type_de_champ_siret, procedure: nil)
create(:procedure, :published, types_de_champ: [tdc_siret])
end
describe '#show' do describe '#show' do
let(:dossier) { create(:dossier, user: user, procedure: procedure) } let(:dossier) { create(:dossier, user: user, procedure: procedure) }
let(:champ) do let(:champ) { dossier.champs.first }
d = dossier
type_de_champ = create(:type_de_champ_siret, procedure: procedure)
type_de_champ.champ.create(dossier: d, value: nil, etablissement: nil)
end
let(:params) do let(:params) do
{ {
champ_id: champ.id, champ_id: champ.id,
@ -27,6 +27,7 @@ describe Champs::SiretController, type: :controller do
let(:api_etablissement_status) { 200 } let(:api_etablissement_status) { 200 }
let(:api_etablissement_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') } let(:api_etablissement_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
let(:token_expired) { false } let(:token_expired) { false }
before do before do
sign_in user sign_in user
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
@ -112,7 +113,7 @@ describe Champs::SiretController, type: :controller do
champ.reload champ.reload
expect(champ.value).to eq(siret) expect(champ.value).to eq(siret)
expect(champ.etablissement.siret).to eq(siret) expect(champ.etablissement.siret).to eq(siret)
expect(champ.reload.etablissement.naf).to eq("6202A") expect(champ.etablissement.naf).to eq("6202A")
expect(dossier.reload.etablissement).to eq(nil) expect(dossier.reload.etablissement).to eq(nil)
end end
end end

View file

@ -561,32 +561,35 @@ describe Instructeurs::DossiersController, type: :controller do
describe "#update_annotations" do describe "#update_annotations" do
let(:champ_multiple_drop_down_list) do let(:champ_multiple_drop_down_list) do
create(:type_de_champ_multiple_drop_down_list, :private, libelle: 'libelle').champ.create tdc = create(:type_de_champ_multiple_drop_down_list, :private, procedure: procedure, libelle: 'libelle')
create(:champ_multiple_drop_down_list, :private, type_de_champ: tdc, dossier: dossier)
end end
let(:champ_linked_drop_down_list) do let(:champ_linked_drop_down_list) do
create(:type_de_champ_linked_drop_down_list, :private, libelle: 'libelle').champ.create tdc = create(:type_de_champ_linked_drop_down_list, :private, procedure: procedure, libelle: 'libelle')
create(:champ_linked_drop_down_list, :private, type_de_champ: tdc, dossier: dossier)
end end
let(:champ_datetime) do let(:champ_datetime) do
create(:type_de_champ_datetime, :private, libelle: 'libelle').champ.create tdc = create(:type_de_champ_datetime, :private, procedure: procedure, libelle: 'libelle')
create(:champ_datetime, :private, type_de_champ: tdc, dossier: dossier)
end end
let(:champ_repetition) do let(:champ_repetition) do
tdc = create(:type_de_champ_repetition, :private, libelle: 'libelle') tdc = create(:type_de_champ_repetition, :private, :with_types_de_champ, procedure: procedure, libelle: 'libelle')
tdc.types_de_champ << create(:type_de_champ_text, libelle: 'libelle') tdc.types_de_champ << create(:type_de_champ_text, procedure: procedure, libelle: 'libelle')
champ = tdc.champ.create champ = create(:champ_repetition, :private, type_de_champ: tdc, dossier: dossier)
champ.add_row champ.add_row
champ champ
end end
let(:dossier) do let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
create(:dossier, :en_construction, procedure: procedure, champs_private: [champ_multiple_drop_down_list, champ_linked_drop_down_list, champ_datetime, champ_repetition])
end
let(:now) { Time.zone.parse('01/01/2100') } let(:now) { Time.zone.parse('01/01/2100') }
before do before do
dossier.champs_private << [champ_multiple_drop_down_list, champ_linked_drop_down_list, champ_datetime, champ_repetition]
Timecop.freeze(now) Timecop.freeze(now)
patch :update_annotations, params: params patch :update_annotations, params: params

View file

@ -400,8 +400,8 @@ describe Users::DossiersController, type: :controller do
before do before do
allow(DossierMailer).to receive(:notify_new_dossier_depose_to_instructeur).and_return(double(deliver_later: nil)) allow(DossierMailer).to receive(:notify_new_dossier_depose_to_instructeur).and_return(double(deliver_later: nil))
create(:assign_to, instructeur: instructeur_with_instant_email_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: true, groupe_instructeur: dossier.procedure.defaut_groupe_instructeur) create(:assign_to, instructeur: instructeur_with_instant_email_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: true)
create(:assign_to, instructeur: instructeur_without_instant_email_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: false, groupe_instructeur: dossier.procedure.defaut_groupe_instructeur) create(:assign_to, instructeur: instructeur_without_instant_email_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: false)
end end
it "sends notification mail to instructeurs" do it "sends notification mail to instructeurs" do
@ -838,8 +838,8 @@ describe Users::DossiersController, type: :controller do
allow(DossierMailer).to receive(:notify_new_commentaire_to_instructeur).and_return(double(deliver_later: nil)) allow(DossierMailer).to receive(:notify_new_commentaire_to_instructeur).and_return(double(deliver_later: nil))
instructeur_with_instant_message.follow(dossier) instructeur_with_instant_message.follow(dossier)
instructeur_without_instant_message.follow(dossier) instructeur_without_instant_message.follow(dossier)
create(:assign_to, instructeur: instructeur_with_instant_message, procedure: procedure, instant_email_message_notifications_enabled: true, groupe_instructeur: procedure.defaut_groupe_instructeur) create(:assign_to, instructeur: instructeur_with_instant_message, procedure: procedure, instant_email_message_notifications_enabled: true)
create(:assign_to, instructeur: instructeur_without_instant_message, procedure: procedure, instant_email_message_notifications_enabled: false, groupe_instructeur: procedure.defaut_groupe_instructeur) create(:assign_to, instructeur: instructeur_without_instant_message, procedure: procedure, instant_email_message_notifications_enabled: false)
end end
after { Timecop.return } after { Timecop.return }

View file

@ -1,11 +1,5 @@
FactoryBot.define do FactoryBot.define do
factory :assign_to do factory :assign_to do
after(:build) do |assign_to, evaluator| groupe_instructeur { procedure.defaut_groupe_instructeur }
if evaluator.groupe_instructeur.persisted?
assign_to.groupe_instructeur = evaluator.groupe_instructeur
else
assign_to.groupe_instructeur = assign_to.procedure.defaut_groupe_instructeur
end
end
end end
end end

View file

@ -1,7 +1,7 @@
FactoryBot.define do FactoryBot.define do
factory :attestation do factory :attestation do
title { 'title' } title { 'title' }
dossier { create(:dossier) } association :dossier
end end
trait :with_pdf do trait :with_pdf do

View file

@ -4,6 +4,8 @@ FactoryBot.define do
body { 'body' } body { 'body' }
footer { 'footer' } footer { 'footer' }
activated { true } activated { true }
association :procedure
end end
trait :with_files do trait :with_files do

View file

@ -9,6 +9,11 @@ FactoryBot.define do
association :dossier association :dossier
association :claimant, factory: :instructeur association :claimant, factory: :instructeur
trait :with_instructeur do
email { nil }
instructeur { association :instructeur, email: generate(:expert_email) }
end
trait :with_answer do trait :with_answer do
answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." } answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." }
end end

View file

@ -1,156 +1,142 @@
FactoryBot.define do FactoryBot.define do
factory :champ do factory :champ do
type_de_champ { create(:type_de_champ) } add_attribute(:private) { false }
trait :checkbox do dossier { association :dossier }
type_de_champ { create(:type_de_champ_checkbox) } type_de_champ { association :type_de_champ, procedure: dossier.procedure }
end
trait :header_section do trait :private do
type_de_champ { create(:type_de_champ_header_section) } add_attribute(:private) { true }
end
trait :explication do
type_de_champ { create(:type_de_champ_explication) }
end
trait :dossier_link do
type_de_champ { create(:type_de_champ_dossier_link) }
end
trait :piece_justificative do
type_de_champ { create(:type_de_champ_piece_justificative) }
end end
trait :with_piece_justificative_file do trait :with_piece_justificative_file do
after(:create) do |champ, _evaluator| after(:build) do |champ, _evaluator|
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain") champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
end end
end end
end
factory :champ_text, class: 'Champs::TextChamp' do factory :champ_text, class: 'Champs::TextChamp' do
type_de_champ { create(:type_de_champ_text) } type_de_champ { association :type_de_champ_text, procedure: dossier.procedure }
value { 'text' } value { 'text' }
end end
factory :champ_textarea, class: 'Champs::TextareaChamp' do factory :champ_textarea, class: 'Champs::TextareaChamp' do
type_de_champ { create(:type_de_champ_textarea) } type_de_champ { association :type_de_champ_textarea, procedure: dossier.procedure }
value { 'textarea' } value { 'textarea' }
end end
factory :champ_date, class: 'Champs::DateChamp' do factory :champ_date, class: 'Champs::DateChamp' do
type_de_champ { create(:type_de_champ_date) } type_de_champ { association :type_de_champ_date, procedure: dossier.procedure }
value { '2019-07-10' } value { '2019-07-10' }
end end
factory :champ_datetime, class: 'Champs::DatetimeChamp' do factory :champ_datetime, class: 'Champs::DatetimeChamp' do
type_de_champ { create(:type_de_champ_datetime) } type_de_champ { association :type_de_champ_datetime, procedure: dossier.procedure }
value { '15/09/1962 15:35' } value { '15/09/1962 15:35' }
end end
factory :champ_number, class: 'Champs::NumberChamp' do factory :champ_number, class: 'Champs::NumberChamp' do
type_de_champ { create(:type_de_champ_number) } type_de_champ { association :type_de_champ_number, procedure: dossier.procedure }
value { '42' } value { '42' }
end end
factory :champ_decimal_number, class: 'Champs::DecimalNumberChamp' do factory :champ_decimal_number, class: 'Champs::DecimalNumberChamp' do
type_de_champ { create(:type_de_champ_decimal_number) } type_de_champ { association :type_de_champ_decimal_number, procedure: dossier.procedure }
value { '42.1' } value { '42.1' }
end end
factory :champ_integer_number, class: 'Champs::IntegerNumberChamp' do factory :champ_integer_number, class: 'Champs::IntegerNumberChamp' do
type_de_champ { create(:type_de_champ_integer_number) } type_de_champ { association :type_de_champ_integer_number, procedure: dossier.procedure }
value { '42' } value { '42' }
end end
factory :champ_checkbox, class: 'Champs::CheckboxChamp' do factory :champ_checkbox, class: 'Champs::CheckboxChamp' do
type_de_champ { create(:type_de_champ_checkbox) } type_de_champ { association :type_de_champ_checkbox, procedure: dossier.procedure }
value { 'on' } value { 'on' }
end end
factory :champ_civilite, class: 'Champs::CiviliteChamp' do factory :champ_civilite, class: 'Champs::CiviliteChamp' do
type_de_champ { create(:type_de_champ_civilite) } type_de_champ { association :type_de_champ_civilite, procedure: dossier.procedure }
value { 'M.' } value { 'M.' }
end end
factory :champ_email, class: 'Champs::EmailChamp' do factory :champ_email, class: 'Champs::EmailChamp' do
type_de_champ { create(:type_de_champ_email) } type_de_champ { association :type_de_champ_email, procedure: dossier.procedure }
value { 'yoda@beta.gouv.fr' } value { 'yoda@beta.gouv.fr' }
end end
factory :champ_phone, class: 'Champs::PhoneChamp' do factory :champ_phone, class: 'Champs::PhoneChamp' do
type_de_champ { create(:type_de_champ_phone) } type_de_champ { association :type_de_champ_phone, procedure: dossier.procedure }
value { '0666666666' } value { '0666666666' }
end end
factory :champ_address, class: 'Champs::AddressChamp' do factory :champ_address, class: 'Champs::AddressChamp' do
type_de_champ { create(:type_de_champ_address) } type_de_champ { association :type_de_champ_address, procedure: dossier.procedure }
value { '2 rue des Démarches' } value { '2 rue des Démarches' }
end end
factory :champ_yes_no, class: 'Champs::YesNoChamp' do factory :champ_yes_no, class: 'Champs::YesNoChamp' do
type_de_champ { create(:type_de_champ_yes_no) } type_de_champ { association :type_de_champ_yes_no, procedure: dossier.procedure }
value { 'true' } value { 'true' }
end end
factory :champ_drop_down_list, class: 'Champs::DropDownListChamp' do factory :champ_drop_down_list, class: 'Champs::DropDownListChamp' do
type_de_champ { create(:type_de_champ_drop_down_list) } type_de_champ { association :type_de_champ_drop_down_list, procedure: dossier.procedure }
value { 'choix 1' } value { 'choix 1' }
end end
factory :champ_multiple_drop_down_list, class: 'Champs::MultipleDropDownListChamp' do factory :champ_multiple_drop_down_list, class: 'Champs::MultipleDropDownListChamp' do
type_de_champ { create(:type_de_champ_multiple_drop_down_list) } type_de_champ { association :type_de_champ_multiple_drop_down_list, procedure: dossier.procedure }
value { '["choix 1", "choix 2"]' } value { '["choix 1", "choix 2"]' }
end end
factory :champ_linked_drop_down_list, class: 'Champs::LinkedDropDownListChamp' do factory :champ_linked_drop_down_list, class: 'Champs::LinkedDropDownListChamp' do
type_de_champ { create(:type_de_champ_linked_drop_down_list) } type_de_champ { association :type_de_champ_linked_drop_down_list, procedure: dossier.procedure }
value { '["categorie 1", "choix 1"]' } value { '["categorie 1", "choix 1"]' }
end end
factory :champ_pays, class: 'Champs::PaysChamp' do factory :champ_pays, class: 'Champs::PaysChamp' do
type_de_champ { create(:type_de_champ_pays) } type_de_champ { association :type_de_champ_pays, procedure: dossier.procedure }
value { 'France' } value { 'France' }
end end
factory :champ_regions, class: 'Champs::RegionChamp' do factory :champ_regions, class: 'Champs::RegionChamp' do
type_de_champ { create(:type_de_champ_regions) } type_de_champ { association :type_de_champ_regions, procedure: dossier.procedure }
value { 'Guadeloupe' } value { 'Guadeloupe' }
end end
factory :champ_departements, class: 'Champs::DepartementChamp' do factory :champ_departements, class: 'Champs::DepartementChamp' do
type_de_champ { create(:type_de_champ_departements) } type_de_champ { association :type_de_champ_departements, procedure: dossier.procedure }
value { '971 - Guadeloupe' } value { '971 - Guadeloupe' }
end end
factory :champ_communes, class: 'Champs::CommuneChamp' do factory :champ_communes, class: 'Champs::CommuneChamp' do
type_de_champ { create(:type_de_champ_communes) } type_de_champ { association :type_de_champ_communes, procedure: dossier.procedure }
value { 'Paris' } value { 'Paris' }
end end
factory :champ_engagement, class: 'Champs::EngagementChamp' do factory :champ_engagement, class: 'Champs::EngagementChamp' do
type_de_champ { create(:type_de_champ_engagement) } type_de_champ { association :type_de_champ_engagement, procedure: dossier.procedure }
value { 'true' } value { 'true' }
end end
factory :champ_header_section, class: 'Champs::HeaderSectionChamp' do factory :champ_header_section, class: 'Champs::HeaderSectionChamp' do
type_de_champ { create(:type_de_champ_header_section) } type_de_champ { association :type_de_champ_header_section, procedure: dossier.procedure }
value { 'une section' } value { 'une section' }
end end
factory :champ_explication, class: 'Champs::ExplicationChamp' do factory :champ_explication, class: 'Champs::ExplicationChamp' do
type_de_champ { create(:type_de_champ_explication) } type_de_champ { association :type_de_champ_explication, procedure: dossier.procedure }
value { '' } value { '' }
end end
factory :champ_dossier_link, class: 'Champs::DossierLinkChamp' do factory :champ_dossier_link, class: 'Champs::DossierLinkChamp' do
type_de_champ { create(:type_de_champ_dossier_link) } type_de_champ { association :type_de_champ_dossier_link, procedure: dossier.procedure }
value { create(:dossier).id } value { create(:dossier).id }
end end
factory :champ_piece_justificative, class: 'Champs::PieceJustificativeChamp' do factory :champ_piece_justificative, class: 'Champs::PieceJustificativeChamp' do
type_de_champ { create(:type_de_champ_piece_justificative) } type_de_champ { association :type_de_champ_piece_justificative, procedure: dossier.procedure }
after(:build) do |champ, _evaluator| after(:build) do |champ, _evaluator|
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain") champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
@ -158,7 +144,7 @@ FactoryBot.define do
end end
factory :champ_carte, class: 'Champs::CarteChamp' do factory :champ_carte, class: 'Champs::CarteChamp' do
type_de_champ { create(:type_de_champ_carte) } type_de_champ { association :type_de_champ_carte, procedure: dossier.procedure }
end end
factory :champ_siret, class: 'Champs::SiretChamp' do factory :champ_siret, class: 'Champs::SiretChamp' do
@ -168,30 +154,67 @@ FactoryBot.define do
end end
factory :champ_repetition, class: 'Champs::RepetitionChamp' do factory :champ_repetition, class: 'Champs::RepetitionChamp' do
type_de_champ { create(:type_de_champ_repetition) } type_de_champ { association :type_de_champ_repetition, procedure: dossier.procedure }
after(:build) do |champ_repetition, _evaluator| after(:build) do |champ_repetition, _evaluator|
type_de_champ_text = create(:type_de_champ_text, order_place: 0, parent: champ_repetition.type_de_champ, libelle: 'Nom') types_de_champ = champ_repetition.type_de_champ.types_de_champ
type_de_champ_number = create(:type_de_champ_number, order_place: 1, parent: champ_repetition.type_de_champ, libelle: 'Age') existing_type_de_champ_text = types_de_champ.find { |tdc| tdc.libelle == 'Nom' }
type_de_champ_text = existing_type_de_champ_text || build(
:type_de_champ_text,
order_place: 0,
procedure: champ_repetition.dossier.procedure,
parent: champ_repetition.type_de_champ,
libelle: 'Nom'
)
create(:champ_text, row: 0, type_de_champ: type_de_champ_text, parent: champ_repetition) types_de_champ << type_de_champ_text
create(:champ_number, row: 0, type_de_champ: type_de_champ_number, parent: champ_repetition) existing_type_de_champ_number = types_de_champ.find { |tdc| tdc.libelle == 'Age' }
create(:champ_text, row: 1, type_de_champ: type_de_champ_text, parent: champ_repetition) type_de_champ_number = existing_type_de_champ_number || build(
create(:champ_number, row: 1, type_de_champ: type_de_champ_number, parent: champ_repetition) :type_de_champ_number,
order_place: 1,
procedure: champ_repetition.dossier.procedure,
parent: champ_repetition.type_de_champ,
libelle: 'Age'
)
types_de_champ << type_de_champ_number
champ_repetition.champs << [
build(:champ_text, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_text, parent: champ_repetition),
build(:champ_number, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_number, parent: champ_repetition),
build(:champ_text, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_text, parent: champ_repetition),
build(:champ_number, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_number, parent: champ_repetition)
]
end
trait :without_champs do
after(:build) do |champ_repetition, _evaluator|
champ_repetition.champs = []
end
end end
end end
factory :champ_repetition_with_piece_jointe, class: 'Champs::RepetitionChamp' do factory :champ_repetition_with_piece_jointe, class: 'Champs::RepetitionChamp' do
type_de_champ { create(:type_de_champ_repetition) } type_de_champ { association :type_de_champ_repetition, procedure: dossier.procedure }
after(:build) do |champ_repetition, _evaluator| after(:build) do |champ_repetition, _evaluator|
type_de_champ_pj0 = create(:type_de_champ_piece_justificative, order_place: 0, parent: champ_repetition.type_de_champ, libelle: 'Justificatif de domicile') type_de_champ_pj0 = build(:type_de_champ_piece_justificative,
type_de_champ_pj1 = create(:type_de_champ_piece_justificative, order_place: 1, parent: champ_repetition.type_de_champ, libelle: 'Carte d\'identité') procedure: champ_repetition.dossier.procedure,
order_place: 0,
parent: champ_repetition.type_de_champ,
libelle: 'Justificatif de domicile')
type_de_champ_pj1 = build(:type_de_champ_piece_justificative,
procedure: champ_repetition.dossier.procedure,
order_place: 1,
parent: champ_repetition.type_de_champ,
libelle: 'Carte d\'identité')
create(:champ_piece_justificative, row: 0, type_de_champ: type_de_champ_pj0, parent: champ_repetition) champ_repetition.champs << [
create(:champ_piece_justificative, row: 0, type_de_champ: type_de_champ_pj1, parent: champ_repetition) build(:champ_piece_justificative, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_pj0),
create(:champ_piece_justificative, row: 1, type_de_champ: type_de_champ_pj0, parent: champ_repetition) build(:champ_piece_justificative, dossier: champ_repetition.dossier, row: 0, type_de_champ: type_de_champ_pj1),
create(:champ_piece_justificative, row: 1, type_de_champ: type_de_champ_pj1, parent: champ_repetition) build(:champ_piece_justificative, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_pj0),
build(:champ_piece_justificative, dossier: champ_repetition.dossier, row: 1, type_de_champ: type_de_champ_pj1)
]
end
end end
end end
end end

View file

@ -1,12 +1,8 @@
FactoryBot.define do FactoryBot.define do
factory :commentaire do factory :commentaire do
body { 'plop' } association :dossier, :en_construction
before(:create) do |commentaire, _evaluator| body { 'plop' }
if !commentaire.dossier
commentaire.dossier = create :dossier, :en_construction
end
end
trait :with_file do trait :with_file do
piece_jointe { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') } piece_jointe { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }

View file

@ -2,7 +2,7 @@ FactoryBot.define do
factory :dossier do factory :dossier do
autorisation_donnees { true } autorisation_donnees { true }
state { Dossier.states.fetch(:brouillon) } state { Dossier.states.fetch(:brouillon) }
association :user, factory: [:user] association :user
transient do transient do
procedure { nil } procedure { nil }
@ -49,7 +49,7 @@ FactoryBot.define do
if !dossier.procedure.for_individual? if !dossier.procedure.for_individual?
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`' raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
end end
dossier.individual = create(:individual) dossier.individual = build(:individual, dossier: dossier)
end end
end end
@ -183,9 +183,9 @@ FactoryBot.define do
end end
trait :with_attestation do trait :with_attestation do
after(:create) do |dossier, _evaluator| after(:build) do |dossier, _evaluator|
if dossier.procedure.attestation_template.blank? if dossier.procedure.attestation_template.blank?
dossier.procedure.attestation_template = create(:attestation_template) dossier.procedure.attestation_template = build(:attestation_template)
end end
dossier.attestation = dossier.build_attestation dossier.attestation = dossier.build_attestation
end end
@ -203,7 +203,7 @@ FactoryBot.define do
trait :with_all_champs do trait :with_all_champs do
after(:create) do |dossier, _evaluator| after(:create) do |dossier, _evaluator|
dossier.champs = dossier.procedure.types_de_champ.map do |type_de_champ| dossier.champs = dossier.procedure.types_de_champ.map do |type_de_champ|
build(:"champ_#{type_de_champ.type_champ}", type_de_champ: type_de_champ) build(:"champ_#{type_de_champ.type_champ}", dossier: dossier, type_de_champ: type_de_champ)
end end
dossier.save! dossier.save!
end end
@ -212,7 +212,7 @@ FactoryBot.define do
trait :with_all_annotations do trait :with_all_annotations do
after(:create) do |dossier, _evaluator| after(:create) do |dossier, _evaluator|
dossier.champs = dossier.procedure.types_de_champ.map do |type_de_champ| dossier.champs = dossier.procedure.types_de_champ.map do |type_de_champ|
build(:"champ_#{type_de_champ.type_champ}", type_de_champ: type_de_champ) build(:"champ_#{type_de_champ.type_champ}", dossier: dossier, type_de_champ: type_de_champ)
end end
dossier.save! dossier.save!
end end

View file

@ -25,9 +25,7 @@ FactoryBot.define do
entreprise_date_creation { "1990-04-24" } entreprise_date_creation { "1990-04-24" }
trait :with_exercices do trait :with_exercices do
after(:create) do |etablissement, _evaluator| exercices { [association(:exercice)] }
create(:exercice, etablissement: etablissement)
end
end end
trait :with_effectif_mensuel do trait :with_effectif_mensuel do

View file

@ -3,6 +3,6 @@ FactoryBot.define do
ca { '12345678' } ca { '12345678' }
date_fin_exercice { "2014-12-30 23:00:00" } date_fin_exercice { "2014-12-30 23:00:00" }
date_fin_exercice_timestamp { 1419980400 } date_fin_exercice_timestamp { 1419980400 }
association :etablissement, factory: [:etablissement] association :etablissement
end end
end end

View file

@ -1,6 +1,6 @@
FactoryBot.define do FactoryBot.define do
factory :export do factory :export do
format { :csv } format { :csv }
groupe_instructeurs { [create(:groupe_instructeur)] } groupe_instructeurs { [association(:groupe_instructeur)] }
end end
end end

View file

@ -1,6 +1,7 @@
FactoryBot.define do FactoryBot.define do
factory :feedback do factory :feedback do
rating { Feedback.ratings.fetch(:happy) } rating { Feedback.ratings.fetch(:happy) }
association :user
trait :happy do trait :happy do
rating { Feedback.ratings.fetch(:happy) } rating { Feedback.ratings.fetch(:happy) }

View file

@ -1,4 +1,6 @@
FactoryBot.define do FactoryBot.define do
factory :follow do factory :follow do
association :instructeur
association :dossier
end end
end end

View file

@ -1,5 +1,7 @@
FactoryBot.define do FactoryBot.define do
factory :geo_area do factory :geo_area do
association :champ
trait :cadastre do trait :cadastre do
source { GeoArea.sources.fetch(:cadastre) } source { GeoArea.sources.fetch(:cadastre) }
numero { '42' } numero { '42' }

View file

@ -3,6 +3,6 @@ FactoryBot.define do
factory :groupe_instructeur do factory :groupe_instructeur do
label { generate(:groupe_label) } label { generate(:groupe_label) }
procedure { create(:procedure) } association :procedure
end end
end end

View file

@ -4,5 +4,6 @@ FactoryBot.define do
nom { 'Julien' } nom { 'Julien' }
prenom { 'Xavier' } prenom { 'Xavier' }
birthdate { Date.new(1991, 11, 01) } birthdate { Date.new(1991, 11, 01) }
association :dossier
end end
end end

View file

@ -1,24 +1,17 @@
FactoryBot.define do FactoryBot.define do
factory :invite do factory :invite do
email { 'plop@octo.com' } email { 'plop@octo.com' }
user { nil }
association :dossier
after(:build) do |invite, _evaluator| after(:build) do |invite, _evaluator|
if invite.dossier.nil?
invite.dossier = create(:dossier)
end
if invite.user.present? if invite.user.present?
invite.email = invite.user.email invite.email = invite.user.email
end end
end end
trait :with_user do trait :with_user do
after(:build) do |invite, _evaluator| association :user
if invite.user.nil?
invite.user = create(:user)
invite.email = invite.user.email
end
end
end end
end end
end end

View file

@ -2,6 +2,7 @@ FactoryBot.define do
factory :closed_mail, class: Mails::ClosedMail do factory :closed_mail, class: Mails::ClosedMail do
subject { "Subject, voila voila" } subject { "Subject, voila voila" }
body { "Blabla ceci est mon body" } body { "Blabla ceci est mon body" }
association :procedure
factory :received_mail, class: Mails::ReceivedMail factory :received_mail, class: Mails::ReceivedMail

View file

@ -70,7 +70,7 @@ FactoryBot.define do
trait :with_instructeur do trait :with_instructeur do
after(:create) do |procedure, _evaluator| after(:create) do |procedure, _evaluator|
procedure.defaut_groupe_instructeur.instructeurs << create(:instructeur) procedure.defaut_groupe_instructeur.instructeurs << build(:instructeur)
end end
end end
@ -232,10 +232,10 @@ FactoryBot.define do
if libelle == 'drop_down_list' if libelle == 'drop_down_list'
libelle = 'simple_drop_down_list' libelle = 'simple_drop_down_list'
end end
build(:"type_de_champ_#{type_champ}", mandatory: true, libelle: libelle, order_place: index) build(:"type_de_champ_#{type_champ}", procedure: procedure, mandatory: true, libelle: libelle, order_place: index)
end end
procedure.types_de_champ << build(:type_de_champ_drop_down_list, :long, mandatory: true, libelle: 'simple_choice_drop_down_list_long') procedure.types_de_champ << build(:type_de_champ_drop_down_list, :long, procedure: procedure, mandatory: true, libelle: 'simple_choice_drop_down_list_long')
procedure.types_de_champ << build(:type_de_champ_multiple_drop_down_list, :long, mandatory: true, libelle: 'multiple_choice_drop_down_list_long') procedure.types_de_champ << build(:type_de_champ_multiple_drop_down_list, :long, procedure: procedure, mandatory: true, libelle: 'multiple_choice_drop_down_list_long')
end end
end end
@ -245,7 +245,7 @@ FactoryBot.define do
if libelle == 'drop_down_list' if libelle == 'drop_down_list'
libelle = 'simple_drop_down_list' libelle = 'simple_drop_down_list'
end end
build(:"type_de_champ_#{type_champ}", libelle: libelle, order_place: index) build(:"type_de_champ_#{type_champ}", procedure: procedure, libelle: libelle, order_place: index)
end end
end end
end end
@ -256,7 +256,7 @@ FactoryBot.define do
if libelle == 'drop_down_list' if libelle == 'drop_down_list'
libelle = 'simple_drop_down_list' libelle = 'simple_drop_down_list'
end end
build(:"type_de_champ_#{type_champ}", private: true, libelle: libelle, order_place: index) build(:"type_de_champ_#{type_champ}", procedure: procedure, private: true, libelle: libelle, order_place: index)
end end
end end
end end

View file

@ -1,6 +1,10 @@
FactoryBot.define do FactoryBot.define do
factory :procedure_presentation do factory :procedure_presentation do
assign_to { create(:assign_to, procedure: create(:procedure, :with_type_de_champ)) } transient do
procedure { create(:procedure, :with_instructeur, :with_type_de_champ) }
end
assign_to { association :assign_to, procedure: procedure, instructeur: procedure.instructeurs.first }
sort { { "table" => "user", "column" => "email", "order" => "asc" } } sort { { "table" => "user", "column" => "email", "order" => "asc" } }
end end
end end

View file

@ -3,10 +3,11 @@ FactoryBot.define do
nom { 'service' } nom { 'service' }
organisme { 'organisme' } organisme { 'organisme' }
type_organisme { Service.type_organismes.fetch(:association) } type_organisme { Service.type_organismes.fetch(:association) }
administrateur { create(:administrateur) }
email { 'email@toto.com' } email { 'email@toto.com' }
telephone { '1234' } telephone { '1234' }
horaires { 'de 9 h à 18 h' } horaires { 'de 9 h à 18 h' }
adresse { 'adresse' } adresse { 'adresse' }
association :administrateur
end end
end end

View file

@ -0,0 +1,5 @@
FactoryBot.define do
factory :trusted_device_token do
association :instructeur
end
end

View file

@ -7,6 +7,8 @@ FactoryBot.define do
mandatory { false } mandatory { false }
add_attribute(:private) { false } add_attribute(:private) { false }
association :procedure
factory :type_de_champ_text do factory :type_de_champ_text do
type_champ { TypeDeChamp.type_champs.fetch(:text) } type_champ { TypeDeChamp.type_champs.fetch(:text) }
end end
@ -94,7 +96,7 @@ FactoryBot.define do
factory :type_de_champ_piece_justificative do factory :type_de_champ_piece_justificative do
type_champ { TypeDeChamp.type_champs.fetch(:piece_justificative) } type_champ { TypeDeChamp.type_champs.fetch(:piece_justificative) }
after(:create) do |tc, _evaluator| after(:build) do |tc, _evaluator|
tc.piece_justificative_template.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain") tc.piece_justificative_template.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
end end
end end
@ -109,7 +111,7 @@ FactoryBot.define do
trait :with_types_de_champ do trait :with_types_de_champ do
after(:build) do |type_de_champ, _evaluator| after(:build) do |type_de_champ, _evaluator|
type_de_champ.types_de_champ << create(:type_de_champ, libelle: 'sub type de champ') type_de_champ.types_de_champ << build(:type_de_champ, procedure: type_de_champ.procedure, libelle: 'sub type de champ')
end end
end end
end end

View file

@ -19,7 +19,7 @@ feature 'The user' do
check('checkbox') check('checkbox')
choose('Madame') choose('Madame')
fill_in('email', with: 'loulou@yopmail.com') fill_in('email', with: 'loulou@yopmail.com')
fill_in('phone', with: '1234567890') fill_in('phone', with: '0123456789')
choose('Non') choose('Non')
choose('val2') choose('val2')
check('val1') check('val1')
@ -55,7 +55,7 @@ feature 'The user' do
expect(champ_value_for('checkbox')).to eq('on') expect(champ_value_for('checkbox')).to eq('on')
expect(champ_value_for('civilite')).to eq('Mme') expect(champ_value_for('civilite')).to eq('Mme')
expect(champ_value_for('email')).to eq('loulou@yopmail.com') expect(champ_value_for('email')).to eq('loulou@yopmail.com')
expect(champ_value_for('phone')).to eq('1234567890') expect(champ_value_for('phone')).to eq('0123456789')
expect(champ_value_for('yes_no')).to eq('false') expect(champ_value_for('yes_no')).to eq('false')
expect(champ_value_for('simple_drop_down_list')).to eq('val2') expect(champ_value_for('simple_drop_down_list')).to eq('val2')
expect(champ_value_for('simple_choice_drop_down_list_long')).to eq('bravo') expect(champ_value_for('simple_choice_drop_down_list_long')).to eq('bravo')
@ -79,7 +79,7 @@ feature 'The user' do
expect(page).to have_checked_field('checkbox') expect(page).to have_checked_field('checkbox')
expect(page).to have_checked_field('Madame') expect(page).to have_checked_field('Madame')
expect(page).to have_field('email', with: 'loulou@yopmail.com') expect(page).to have_field('email', with: 'loulou@yopmail.com')
expect(page).to have_field('phone', with: '1234567890') expect(page).to have_field('phone', with: '0123456789')
expect(page).to have_checked_field('Non') expect(page).to have_checked_field('Non')
expect(page).to have_checked_field('val2') expect(page).to have_checked_field('val2')
expect(page).to have_checked_field('val1') expect(page).to have_checked_field('val1')

View file

@ -0,0 +1,53 @@
{
"etablissement": {
"adresse": {
"cedex": null,
"code_insee_localite": "31555",
"code_postal": "31400",
"complement_adresse": null,
"l1": "DIRECTION INTERREGIONALE DES SERVICES PENITENTIAIRES TOULOUSE - SUD",
"l2": "SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION, DE LA HAUTE-GARONNE",
"l3": null,
"l4": "109 AV DE LESPINET",
"l5": "BP 4087",
"l6": "31400 TOULOUSE",
"l7": "FRANCE",
"localite": "TOULOUSE",
"nom_voie": "DE LESPINET",
"numero_voie": "109",
"type_voie": "AV"
},
"commune_implantation": {
"code": "31555",
"value": "Toulouse"
},
"date_creation_etablissement": 1458946800,
"date_mise_a_jour": 1533648919,
"diffusable_commercialement": true,
"enseigne": "SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION, DE LA HAUTE-GARONNE",
"etat_administratif": {
"date_fermeture": null,
"value": "A"
},
"libelle_naf": "Justice",
"naf": "8423Z",
"pays_implantation": {
"code": "FR",
"value": "FRANCE"
},
"region_implantation": {
"code": "76",
"value": "Occitanie"
},
"siege_social": false,
"siret": "17310120500719",
"tranche_effectif_salarie_etablissement": {
"a": null,
"code": null,
"date_reference": null,
"de": null,
"intitule": null
}
},
"gateway_error": false
}

View file

@ -41,8 +41,8 @@ RSpec.describe DossierHelper, type: :helper do
describe ".demandeur_dossier" do describe ".demandeur_dossier" do
subject { demandeur_dossier(dossier) } subject { demandeur_dossier(dossier) }
let(:individual) { create(:individual) } let(:individual) { build(:individual, dossier: nil) }
let(:etablissement) { create(:etablissement) } let(:etablissement) { build(:etablissement) }
let(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) } let(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) }
context "when the dossier is for an individual" do context "when the dossier is for an individual" do

View file

@ -1,10 +1,12 @@
RSpec.describe EtablissementHelper, type: :helper do RSpec.describe EtablissementHelper, type: :helper do
let(:code_effectif) { '00' } let(:code_effectif) { '00' }
let(:raison_sociale) { 'GRTGaz' } let(:raison_sociale) { 'GRTGaz' }
let(:enseigne) { "mon enseigne" }
let(:nom) { 'mon nom' } let(:nom) { 'mon nom' }
let(:prenom) { 'mon prenom' } let(:prenom) { 'mon prenom' }
let(:entreprise_params) do let(:etablissement_params) do
{ {
enseigne: enseigne,
entreprise_capital_social: 123_000, entreprise_capital_social: 123_000,
entreprise_code_effectif_entreprise: code_effectif, entreprise_code_effectif_entreprise: code_effectif,
entreprise_raison_sociale: raison_sociale, entreprise_raison_sociale: raison_sociale,
@ -12,13 +14,21 @@ RSpec.describe EtablissementHelper, type: :helper do
entreprise_prenom: prenom entreprise_prenom: prenom
} }
end end
let(:etablissement) { create(:etablissement, entreprise_params) } let(:etablissement) { create(:etablissement, etablissement_params) }
describe '#raison_sociale_or_name' do describe '#raison_sociale_or_name' do
subject { raison_sociale_or_name(etablissement) } subject { raison_sociale_or_name(etablissement) }
context 'when etablissement is not the siege and enseigne exist' do
let(:enseigne) { "mon enseigne" }
it 'display enseigne' do
expect(subject).to eq(enseigne)
end
end
context 'when raison_sociale exist' do context 'when raison_sociale exist' do
let(:raison_sociale) { 'ma super raison_sociale' } let(:raison_sociale) { 'ma super raison_sociale' }
let(:enseigne) { nil }
it 'display raison_sociale' do it 'display raison_sociale' do
expect(subject).to eq(raison_sociale) expect(subject).to eq(raison_sociale)
end end
@ -26,6 +36,7 @@ RSpec.describe EtablissementHelper, type: :helper do
context 'when raison_sociale is nil' do context 'when raison_sociale is nil' do
let(:raison_sociale) { nil } let(:raison_sociale) { nil }
let(:enseigne) { nil }
it 'display nom and prenom' do it 'display nom and prenom' do
expect(subject).to eq("#{nom} #{prenom}") expect(subject).to eq("#{nom} #{prenom}")
end end

View file

@ -2,7 +2,7 @@ RSpec.describe VirusScannerJob, type: :job do
include ActiveJob::TestHelper include ActiveJob::TestHelper
let(:champ) do let(:champ) do
champ = create(:champ, :piece_justificative) champ = create(:champ_piece_justificative)
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain") champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
champ.save champ.save
champ champ

View file

@ -1,5 +1,5 @@
describe ActiveStorage::DownloadableFile do describe ActiveStorage::DownloadableFile do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier, :en_construction) }
subject(:list) { ActiveStorage::DownloadableFile.create_list_from_dossier(dossier) } subject(:list) { ActiveStorage::DownloadableFile.create_list_from_dossier(dossier) }
@ -10,7 +10,7 @@ describe ActiveStorage::DownloadableFile do
context 'when there is a piece_justificative' do context 'when there is a piece_justificative' do
before do before do
dossier.champs << create(:champ, :piece_justificative, :with_piece_justificative_file) dossier.champs << create(:champ_piece_justificative, :with_piece_justificative_file, dossier: dossier)
end end
it { expect(list.length).to eq 1 } it { expect(list.length).to eq 1 }
@ -18,15 +18,16 @@ describe ActiveStorage::DownloadableFile do
context 'when there is a private piece_justificative' do context 'when there is a private piece_justificative' do
before do before do
dossier.champs_private << create(:champ, :piece_justificative, :with_piece_justificative_file, private: true) dossier.champs_private << create(:champ_piece_justificative, :with_piece_justificative_file, private: true, dossier: dossier)
end end
it { expect(list.length).to eq 1 } it { expect(list.length).to eq 1 }
end end
context 'when there is a repetition bloc' do context 'when there is a repetition bloc' do
let(:champ) { build(:champ_repetition_with_piece_jointe) } before do
let(:dossier) { create(:dossier, :en_construction, champs: [champ]) } dossier.champs << build(:champ_repetition_with_piece_jointe, dossier: dossier)
end
it 'should have 4 piece_justificatives' do it 'should have 4 piece_justificatives' do
expect(list.size).to eq 4 expect(list.size).to eq 4
@ -34,15 +35,17 @@ describe ActiveStorage::DownloadableFile do
end end
context 'when there is a message with no attachment' do context 'when there is a message with no attachment' do
let(:commentaire) { create(:commentaire) } before do
let(:dossier) { commentaire.dossier } dossier.commentaires << create(:commentaire, dossier: dossier)
end
it { expect(list.length).to eq 0 } it { expect(list.length).to eq 0 }
end end
context 'when there is a message with an attachment' do context 'when there is a message with an attachment' do
let(:commentaire) { create(:commentaire, :with_file) } before do
let(:dossier) { commentaire.dossier } dossier.commentaires << create(:commentaire, :with_file, dossier: dossier)
end
it { expect(list.length).to eq 1 } it { expect(list.length).to eq 1 }
end end

View file

@ -8,11 +8,12 @@ describe ApiEntreprise::EtablissementAdapter do
context 'SIRET valide avec infos diffusables' do context 'SIRET valide avec infos diffusables' do
let(:siret) { '41816609600051' } let(:siret) { '41816609600051' }
let(:fixture) { 'spec/fixtures/files/api_entreprise/etablissements.json' }
subject { described_class.new(siret, procedure_id).to_params } subject { described_class.new(siret, procedure_id).to_params }
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
.to_return(body: File.read('spec/fixtures/files/api_entreprise/etablissements.json', status: 200)) .to_return(body: File.read(fixture, status: 200))
end end
it '#to_params class est une Hash ?' do it '#to_params class est une Hash ?' do
@ -75,6 +76,22 @@ describe ApiEntreprise::EtablissementAdapter do
end end
end end
end end
context 'Attributs Etablissements pour etablissement non siege' do
let(:siret) { '17310120500719' }
let(:fixture) { 'spec/fixtures/files/api_entreprise/etablissements-non-siege.json' }
it 'L\'entreprise contient bien un siret' do
expect(subject[:siret]).to eq(siret)
end
it 'L\'etablissement contient bien un siege_social à false' do
expect(subject[:siege_social]).to eq(false)
end
it 'L\'etablissement contient bien une enseigne' do
expect(subject[:enseigne]).to eq("SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION, DE LA HAUTE-GARONNE")
end
end
end end
context 'SIRET valide avec infos non diffusables' do context 'SIRET valide avec infos non diffusables' do

View file

@ -1,7 +1,7 @@
describe AssignTo, type: :model do describe AssignTo, type: :model do
describe '#procedure_presentation_or_default_and_errors' do describe '#procedure_presentation_or_default_and_errors' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:assign_to) { create(:assign_to, procedure: procedure) } let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: create(:instructeur)) }
let(:procedure_presentation_and_errors) { assign_to.procedure_presentation_or_default_and_errors } let(:procedure_presentation_and_errors) { assign_to.procedure_presentation_or_default_and_errors }
let(:procedure_presentation_or_default) { procedure_presentation_and_errors.first } let(:procedure_presentation_or_default) { procedure_presentation_and_errors.first }

View file

@ -87,7 +87,7 @@ RSpec.describe Avis, type: :model do
describe '#try_to_assign_instructeur' do describe '#try_to_assign_instructeur' do
let!(:instructeur) { create(:instructeur) } let!(:instructeur) { create(:instructeur) }
let(:avis) { Avis.create(claimant: claimant, email: email, dossier: create(:dossier)) } let(:avis) { create(:avis, claimant: claimant, email: email, dossier: create(:dossier)) }
context 'when the email belongs to a instructeur' do context 'when the email belongs to a instructeur' do
let(:email) { instructeur.email } let(:email) { instructeur.email }

View file

@ -1,7 +1,7 @@
shared_examples 'champ_spec' do shared_examples 'champ_spec' do
describe 'mandatory_and_blank?' do describe 'mandatory_and_blank?' do
let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) } let(:type_de_champ) { build(:type_de_champ, mandatory: mandatory) }
let(:champ) { type_de_champ.champ.build(value: value) } let(:champ) { build(:champ, type_de_champ: type_de_champ, value: value) }
let(:value) { '' } let(:value) { '' }
let(:mandatory) { true } let(:mandatory) { true }
@ -33,8 +33,7 @@ shared_examples 'champ_spec' do
end end
context "when type_champ=date" do context "when type_champ=date" do
let(:type_de_champ) { create(:type_de_champ_date) } let(:champ) { build(:champ_date) }
let(:champ) { type_de_champ.champ.create }
it "should convert %d/%m/%Y format to ISO" do it "should convert %d/%m/%Y format to ISO" do
champ.value = "31/12/2017" champ.value = "31/12/2017"

View file

@ -47,7 +47,7 @@ describe Champ do
let(:public_champ) { dossier.champs.first } let(:public_champ) { dossier.champs.first }
let(:private_champ) { dossier.champs_private.first } let(:private_champ) { dossier.champs_private.first }
let(:champ_in_repetition) { dossier.champs.find(&:repetition?).champs.first } let(:champ_in_repetition) { dossier.champs.find(&:repetition?).champs.first }
let(:standalone_champ) { create(:champ, dossier: nil) } let(:standalone_champ) { build(:champ, type_de_champ: build(:type_de_champ), dossier: nil) }
it 'returns the sibling champs of a champ' do it 'returns the sibling champs of a champ' do
expect(public_champ.siblings).to eq(dossier.champs) expect(public_champ.siblings).to eq(dossier.champs)
@ -58,10 +58,9 @@ describe Champ do
end end
describe '#format_datetime' do describe '#format_datetime' do
let(:type_de_champ) { build(:type_de_champ_datetime) } let(:champ) { build(:champ_datetime, value: value) }
let(:champ) { type_de_champ.champ.build(value: value) }
before { champ.save } before { champ.save! }
context 'when the value is sent by a modern browser' do context 'when the value is sent by a modern browser' do
let(:value) { '2017-12-31 10:23' } let(:value) { '2017-12-31 10:23' }
@ -77,10 +76,9 @@ describe Champ do
end end
describe '#multiple_select_to_string' do describe '#multiple_select_to_string' do
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list) } let(:champ) { build(:champ_multiple_drop_down_list, value: value) }
let(:champ) { type_de_champ.champ.build(value: value) }
before { champ.save } before { champ.save! }
# when using the old form, and the ChampsService Class # when using the old form, and the ChampsService Class
# TODO: to remove # TODO: to remove
@ -360,7 +358,7 @@ describe Champ do
end end
let(:champ) { type_de_champ.champ.build(value: etablissement.siret, etablissement: etablissement) } let(:champ) { type_de_champ.champ.build(value: etablissement.siret, etablissement: etablissement) }
it { is_expected.to eq([etablissement.entreprise_siren, etablissement.entreprise_numero_tva_intracommunautaire, etablissement.entreprise_forme_juridique, etablissement.entreprise_forme_juridique_code, etablissement.entreprise_nom_commercial, etablissement.entreprise_raison_sociale, etablissement.entreprise_siret_siege_social, etablissement.entreprise_nom, etablissement.entreprise_prenom, etablissement.association_rna, etablissement.association_titre, etablissement.association_objet, etablissement.siret, etablissement.naf, etablissement.libelle_naf, etablissement.adresse, etablissement.code_postal, etablissement.localite, etablissement.code_insee_localite]) } it { is_expected.to eq([etablissement.entreprise_siren, etablissement.entreprise_numero_tva_intracommunautaire, etablissement.entreprise_forme_juridique, etablissement.entreprise_forme_juridique_code, etablissement.entreprise_nom_commercial, etablissement.entreprise_raison_sociale, etablissement.entreprise_siret_siege_social, etablissement.entreprise_nom, etablissement.entreprise_prenom, etablissement.association_rna, etablissement.association_titre, etablissement.association_objet, etablissement.siret, etablissement.enseigne, etablissement.naf, etablissement.libelle_naf, etablissement.adresse, etablissement.code_postal, etablissement.localite, etablissement.code_insee_localite]) }
end end
context 'when there is no etablissement' do context 'when there is no etablissement' do
@ -412,7 +410,7 @@ describe Champ do
end end
describe '#enqueue_virus_check' do describe '#enqueue_virus_check' do
let(:champ) { type_de_champ.champ.build(value: nil) } let(:champ) { build(:champ_piece_justificative, type_de_champ: type_de_champ) }
context 'when type_champ is type_de_champ_piece_justificative' do context 'when type_champ is type_de_champ_piece_justificative' do
let(:type_de_champ) { create(:type_de_champ_piece_justificative) } let(:type_de_champ) { create(:type_de_champ_piece_justificative) }
@ -420,7 +418,7 @@ describe Champ do
context 'and there is a blob' do context 'and there is a blob' do
before do before do
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain") champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
champ.save champ.save!
end end
it { expect(champ.piece_justificative_file.virus_scanner.started?).to be_truthy } it { expect(champ.piece_justificative_file.virus_scanner.started?).to be_truthy }
@ -428,50 +426,69 @@ describe Champ do
end end
end end
describe "repetition" do describe 'repetition' do
let(:dossier) { create(:dossier) } let(:procedure) { build(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private) }
let(:champ) { Champs::RepetitionChamp.create(dossier: dossier) } let(:tdc_text) { build(:type_de_champ_text, procedure: procedure) }
let(:champ_text) { create(:champ_text, row: 0) } let(:tdc_integer) { build(:type_de_champ_integer_number, procedure: procedure) }
let(:champ_integer_number) { create(:champ_integer_number, row: 0) } let(:tdc_repetition) { build(:type_de_champ_repetition, procedure: procedure, types_de_champ: [tdc_text, tdc_integer]) }
let(:champ_text_attrs) { attributes_for(:champ_text, row: 1) }
let(:champ_text_row_1) { create(:champ_text, row: 1, parent: champ) }
it "associates nested champs to the parent dossier" do let(:dossier) { create(:dossier, procedure: procedure) }
expect(champ.rows.size).to eq(0) let(:champ) { dossier.champs.find(&:repetition?) }
dossier.reload let(:champ_text) { champ.champs.find { |c| c.type_champ == 'text' } }
expect(dossier.champs.size).to eq(2) 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) }
dossier.update(champs_attributes: [ before do
procedure.types_de_champ << tdc_repetition
procedure.save!
procedure.reload
end
context 'when creating the model directly' do
let(:champ_text_row_1) { create(:champ_text, type_de_champ: tdc_text, row: 2, parent: champ, dossier: nil) }
it 'associates nested champs to the parent dossier' do
expect(champ_text_row_1.dossier_id).to eq(champ.dossier_id)
end
end
context 'when updating using nested attributes' do
subject do
dossier.update!(champs_attributes: [
{ {
id: champ.id, id: champ.id,
champs_attributes: [champ_text_attrs] champs_attributes: [champ_text_attrs]
} }
]) ])
champ.reload champ.reload
dossier.reload dossier.reload
expect(dossier.champs.size).to eq(2) end
expect(champ.rows.size).to eq(1)
expect(champ.champs.first.dossier).to eq(dossier) it 'associates nested champs to the parent dossier' do
subject
expect(dossier.champs.size).to eq(2)
expect(champ.rows.size).to eq(2)
second_row = champ.rows.second
expect(second_row.size).to eq(1)
expect(second_row.first.dossier).to eq(dossier)
# Make champs ordered # Make champs ordered
champ_integer_number.type_de_champ.update(order_place: 0) champ_integer.type_de_champ.update(order_place: 0)
champ_text.type_de_champ.update(order_place: 1) champ_text.type_de_champ.update(order_place: 1)
champ.champs << champ_integer_number champ.champs << champ_integer
row = champ.reload.rows.first first_row = champ.reload.rows.first
expect(row.size).to eq(1) expect(first_row.size).to eq(2)
expect(row.first).to eq(champ_integer_number) expect(first_row.first).to eq(champ_integer)
champ.champs << champ_text champ.champs << champ_text
row = champ.reload.rows.first first_row = champ.reload.rows.first
expect(row.size).to eq(2) expect(first_row.size).to eq(2)
expect(row.second).to eq(champ_text) expect(first_row.second).to eq(champ_text)
expect(champ.rows.size).to eq(2) expect(champ.rows.size).to eq(2)
end
expect(champ_text_row_1.dossier_id).to eq(champ.dossier_id)
end end
end end
end end

View file

@ -0,0 +1,25 @@
describe Champs::PhoneChamp do
describe '#valid?' do
it do
expect(build(:champ_phone, value: nil)).to be_valid
expect(build(:champ_phone, value: "0123456789 0123456789")).to_not be_valid
expect(build(:champ_phone, value: "01.23.45.67.89 01.23.45.67.89")).to_not be_valid
expect(build(:champ_phone, value: "3646")).to be_valid
expect(build(:champ_phone, value: "0123456789")).to be_valid
expect(build(:champ_phone, value: "01.23.45.67.89")).to be_valid
expect(build(:champ_phone, value: "0123 45.67.89")).to be_valid
expect(build(:champ_phone, value: "0033 123-456-789")).to be_valid
expect(build(:champ_phone, value: "0033 123-456-789")).to be_valid
expect(build(:champ_phone, value: "0033(0)123456789")).to be_valid
expect(build(:champ_phone, value: "+33-1.23.45.67.89")).to be_valid
expect(build(:champ_phone, value: "+33 - 123 456 789")).to be_valid
expect(build(:champ_phone, value: "+33(0) 123 456 789")).to be_valid
expect(build(:champ_phone, value: "+33 (0)123 45 67 89")).to be_valid
expect(build(:champ_phone, value: "+33 (0)1 2345-6789")).to be_valid
expect(build(:champ_phone, value: "+33(0) - 123456789")).to be_valid
expect(build(:champ_phone, value: "+1(0) - 123456789")).to be_valid
expect(build(:champ_phone, value: "+49 2109 87654321")).to be_valid
expect(build(:champ_phone, value: "012345678")).to be_valid
end
end
end

View file

@ -563,7 +563,7 @@ describe Dossier do
# - with a dash in the champ libelle / tag # - with a dash in the champ libelle / tag
let(:title) { "voici --specified champ-in-title-- un --unspecified champ-in-title-- beau --specified annotation privée-in-title-- titre --unspecified annotation privée-in-title-- non --numéro du dossier--" } let(:title) { "voici --specified champ-in-title-- un --unspecified champ-in-title-- beau --specified annotation privée-in-title-- titre --unspecified annotation privée-in-title-- non --numéro du dossier--" }
let(:body) { "voici --specified champ-in-body-- un --unspecified champ-in-body-- beau --specified annotation privée-in-body-- body --unspecified annotation privée-in-body-- non ?" } let(:body) { "voici --specified champ-in-body-- un --unspecified champ-in-body-- beau --specified annotation privée-in-body-- body --unspecified annotation privée-in-body-- non ?" }
let(:attestation_template) { create(:attestation_template, title: title, body: body, activated: activated) } let(:attestation_template) { build(:attestation_template, title: title, body: body, activated: activated) }
context "which is disabled" do context "which is disabled" do
let(:activated) { false } let(:activated) { false }

View file

@ -1,24 +1,24 @@
RSpec.describe GeoArea, type: :model do RSpec.describe GeoArea, type: :model do
describe '#area' do describe '#area' do
let(:geo_area) { create(:geo_area, :polygon) } let(:geo_area) { build(:geo_area, :polygon) }
it { expect(geo_area.area).to eq(219.0) } it { expect(geo_area.area).to eq(219.0) }
end end
describe '#length' do describe '#length' do
let(:geo_area) { create(:geo_area, :line_string) } let(:geo_area) { build(:geo_area, :line_string) }
it { expect(geo_area.length).to eq(30.8) } it { expect(geo_area.length).to eq(30.8) }
end end
describe '#location' do describe '#location' do
let(:geo_area) { create(:geo_area, :point) } let(:geo_area) { build(:geo_area, :point) }
it { expect(geo_area.location).to eq("2°25'42\"N 46°32'19\"E") } it { expect(geo_area.location).to eq("2°25'42\"N 46°32'19\"E") }
end end
describe '#rgeo_geometry' do describe '#rgeo_geometry' do
let(:geo_area) { create(:geo_area, geometry: geometry) } let(:geo_area) { build(:geo_area, geometry: geometry) }
context 'invalid' do context 'invalid' do
let(:geometry) do let(:geometry) do

View file

@ -2,7 +2,7 @@ describe Individual do
it { is_expected.to have_db_column(:gender) } it { is_expected.to have_db_column(:gender) }
it { is_expected.to have_db_column(:nom) } it { is_expected.to have_db_column(:nom) }
it { is_expected.to have_db_column(:prenom) } it { is_expected.to have_db_column(:prenom) }
it { is_expected.to belong_to(:dossier) } it { is_expected.to belong_to(:dossier).required }
describe "#save" do describe "#save" do
let(:individual) { build(:individual) } let(:individual) { build(:individual) }

View file

@ -389,7 +389,7 @@ describe Instructeur, type: :model do
let(:procedure_to_assign) { create(:procedure) } let(:procedure_to_assign) { create(:procedure) }
before do before do
create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, daily_email_notifications_enabled: true, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur) create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, daily_email_notifications_enabled: true)
end end
context 'when a dossier in construction exists' do context 'when a dossier in construction exists' do

View file

@ -1,18 +1,18 @@
describe ProcedurePresentation do describe ProcedurePresentation do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) } let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
let(:assign_to) { create(:assign_to, procedure: procedure) } let(:instructeur) { create(:instructeur) }
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) }
let(:first_type_de_champ) { assign_to.procedure.types_de_champ.first } let(:first_type_de_champ) { assign_to.procedure.types_de_champ.first }
let(:first_type_de_champ_id) { first_type_de_champ.id.to_s } let(:first_type_de_champ_id) { first_type_de_champ.id.to_s }
let(:procedure_presentation) { let(:procedure_presentation) {
ProcedurePresentation.create( create(:procedure_presentation,
assign_to: assign_to, assign_to: assign_to,
displayed_fields: [ displayed_fields: [
{ "label" => "test1", "table" => "user", "column" => "email" }, { "label" => "test1", "table" => "user", "column" => "email" },
{ "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id } { "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id }
], ],
sort: { "table" => "user", "column" => "email", "order" => "asc" }, sort: { "table" => "user", "column" => "email", "order" => "asc" },
filters: filters filters: filters)
)
} }
let(:procedure_presentation_id) { procedure_presentation.id } let(:procedure_presentation_id) { procedure_presentation.id }
let(:filters) { { "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "self", "column" => "created_at" }] } } let(:filters) { { "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "self", "column" => "created_at" }] } }
@ -86,7 +86,7 @@ describe ProcedurePresentation do
procedure.types_de_champ_private[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication)) procedure.types_de_champ_private[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication))
end end
subject { create(:procedure_presentation, assign_to: create(:assign_to, procedure: procedure)) } subject { create(:procedure_presentation, assign_to: assign_to) }
it { expect(subject.fields).to eq(expected) } it { expect(subject.fields).to eq(expected) }
end end
@ -96,7 +96,7 @@ describe ProcedurePresentation do
let(:surname_field) { { "label" => "Nom", "table" => "individual", "column" => "nom" } } let(:surname_field) { { "label" => "Nom", "table" => "individual", "column" => "nom" } }
let(:gender_field) { { "label" => "Civilité", "table" => "individual", "column" => "gender" } } let(:gender_field) { { "label" => "Civilité", "table" => "individual", "column" => "gender" } }
let(:procedure) { create(:procedure, :for_individual) } let(:procedure) { create(:procedure, :for_individual) }
let(:procedure_presentation) { create(:procedure_presentation, assign_to: create(:assign_to, procedure: procedure)) } let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
subject { procedure_presentation.fields } subject { procedure_presentation.fields }
@ -105,7 +105,7 @@ describe ProcedurePresentation do
end end
describe "#fields_for_select" do describe "#fields_for_select" do
subject { create(:procedure_presentation) } subject { create(:procedure_presentation, assign_to: assign_to) }
before do before do
allow(subject).to receive(:fields).and_return([ allow(subject).to receive(:fields).and_return([
@ -126,7 +126,7 @@ describe ProcedurePresentation do
end end
describe '#get_value' do describe '#get_value' do
let(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) } let(:procedure_presentation) { create(:procedure_presentation, procedure: procedure, assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) }
subject { procedure_presentation.displayed_field_values(dossier).first } subject { procedure_presentation.displayed_field_values(dossier).first }
@ -168,6 +168,7 @@ describe ProcedurePresentation do
context 'for individual table' do context 'for individual table' do
let(:table) { 'individual' } let(:table) { 'individual' }
let(:procedure) { create(:procedure, :for_individual, :with_type_de_champ, :with_type_de_champ_private) }
let(:dossier) { create(:dossier, procedure: procedure, individual: create(:individual, nom: 'Martin', prenom: 'Jacques', gender: 'M.')) } let(:dossier) { create(:dossier, procedure: procedure, individual: create(:individual, nom: 'Martin', prenom: 'Jacques', gender: 'M.')) }
context 'for prenom column' do context 'for prenom column' do
@ -248,7 +249,7 @@ describe ProcedurePresentation do
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) } let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) }
let(:sort) { { 'table' => table, 'column' => column, 'order' => order } } let(:sort) { { 'table' => table, 'column' => column, 'order' => order } }
let(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to, sort: sort) } let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to, sort: sort) }
subject { procedure_presentation.sorted_ids(procedure.dossiers, instructeur) } subject { procedure_presentation.sorted_ids(procedure.dossiers, instructeur) }
@ -416,7 +417,7 @@ describe ProcedurePresentation do
end end
describe '#filtered_ids' do describe '#filtered_ids' do
let(:procedure_presentation) { create(:procedure_presentation, assign_to: create(:assign_to, procedure: procedure), filters: { "suivis" => filter }) } let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to, filters: { "suivis" => filter }) }
subject { procedure_presentation.filtered_ids(procedure.dossiers.joins(:user), 'suivis') } subject { procedure_presentation.filtered_ids(procedure.dossiers.joins(:user), 'suivis') }
@ -755,13 +756,13 @@ describe ProcedurePresentation do
end end
describe '#eager_load_displayed_fields' do describe '#eager_load_displayed_fields' do
let(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) } let(:procedure_presentation) { create(:procedure_presentation, procedure: procedure, assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) }
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:displayed_dossier) { procedure_presentation.eager_load_displayed_fields(procedure.dossiers).first } let(:displayed_dossier) { procedure_presentation.eager_load_displayed_fields(procedure.dossiers).first }
context 'for type de champ' do context 'for type de champ' do
let(:table) { 'type_de_champ' } let(:table) { 'type_de_champ' }
let(:column) { procedure.types_de_champ.first.id } let(:column) { procedure.types_de_champ.first.id.to_s }
it 'preloads the champs relation' do it 'preloads the champs relation' do
# Ideally, we would only preload the champs for the matching column # Ideally, we would only preload the champs for the matching column
@ -778,7 +779,7 @@ describe ProcedurePresentation do
context 'for type de champ private' do context 'for type de champ private' do
let(:table) { 'type_de_champ_private' } let(:table) { 'type_de_champ_private' }
let(:column) { procedure.types_de_champ_private.first.id } let(:column) { procedure.types_de_champ_private.first.id.to_s }
it 'preloads the champs relation' do it 'preloads the champs relation' do
# Ideally, we would only preload the champs for the matching column # Ideally, we would only preload the champs for the matching column
@ -809,6 +810,7 @@ describe ProcedurePresentation do
end end
context 'for individual' do context 'for individual' do
let(:procedure) { create(:procedure, :for_individual, :with_type_de_champ, :with_type_de_champ_private) }
let(:table) { 'individual' } let(:table) { 'individual' }
let(:column) { 'nom' } let(:column) { 'nom' }
@ -855,9 +857,9 @@ describe ProcedurePresentation do
context 'for groupe_instructeur' do context 'for groupe_instructeur' do
let(:table) { 'groupe_instructeur' } let(:table) { 'groupe_instructeur' }
let(:column) { 'email' } let(:column) { 'label' }
it 'preloads the followers_instructeurs relation' do it 'preloads the groupe_instructeur relation' do
expect(displayed_dossier.association(:champs)).not_to be_loaded expect(displayed_dossier.association(:champs)).not_to be_loaded
expect(displayed_dossier.association(:champs_private)).not_to be_loaded expect(displayed_dossier.association(:champs_private)).not_to be_loaded
expect(displayed_dossier.association(:user)).not_to be_loaded expect(displayed_dossier.association(:user)).not_to be_loaded

View file

@ -82,7 +82,7 @@ describe Procedure do
context 'with a custom mail template' do context 'with a custom mail template' do
context 'that contains a lien attestation tag' do context 'that contains a lien attestation tag' do
let(:closed_mail) { create(:closed_mail, body: '--lien attestation--') } let(:closed_mail) { build(:closed_mail, body: '--lien attestation--') }
context 'when the procedure doesnt have an attestation' do context 'when the procedure doesnt have an attestation' do
let(:procedure) { procedure_without_attestation } let(:procedure) { procedure_without_attestation }
@ -104,7 +104,7 @@ describe Procedure do
end end
context 'that doesnt contain a lien attestation tag' do context 'that doesnt contain a lien attestation tag' do
let(:closed_mail) { create(:closed_mail) } let(:closed_mail) { build(:closed_mail) }
context 'when the procedure doesnt have an attestation' do context 'when the procedure doesnt have an attestation' do
let(:procedure) { procedure_without_attestation } let(:procedure) { procedure_without_attestation }
@ -342,7 +342,7 @@ describe Procedure do
let!(:type_de_champ_private_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } let!(:type_de_champ_private_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) }
let!(:type_de_champ_private_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) } let!(:type_de_champ_private_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) }
let!(:type_de_champ_private_2) { create(:type_de_champ_drop_down_list, :private, procedure: procedure, order_place: 2) } let!(:type_de_champ_private_2) { create(:type_de_champ_drop_down_list, :private, procedure: procedure, order_place: 2) }
let(:received_mail) { create(:received_mail) } let(:received_mail) { build(:received_mail) }
let(:from_library) { false } let(:from_library) { false }
let(:administrateur) { procedure.administrateurs.first } let(:administrateur) { procedure.administrateurs.first }

View file

@ -1,6 +1,6 @@
RSpec.describe TrustedDeviceToken, type: :model do RSpec.describe TrustedDeviceToken, type: :model do
describe '#token_valid?' do describe '#token_valid?' do
let(:token) { TrustedDeviceToken.create } let(:token) { create(:trusted_device_token) }
context 'when the token is create after login_token_validity' do context 'when the token is create after login_token_validity' do
it { expect(token.token_valid?).to be true } it { expect(token.token_valid?).to be true }
@ -14,7 +14,7 @@ RSpec.describe TrustedDeviceToken, type: :model do
end end
describe '#token_young?' do describe '#token_young?' do
let(:token) { TrustedDeviceToken.create } let(:token) { create(:trusted_device_token) }
context 'when the token is create after login_token_youth' do context 'when the token is create after login_token_youth' do
it { expect(token.token_young?).to be true } it { expect(token.token_young?).to be true }

View file

@ -156,14 +156,14 @@ shared_examples 'type_de_champ_spec' do
describe "repetition" do describe "repetition" do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:type_de_champ) { create(:type_de_champ_repetition, procedure: procedure) } let(:type_de_champ) { create(:type_de_champ_repetition, procedure: procedure) }
let(:type_de_champ_text) { create(:type_de_champ_text) } let(:type_de_champ_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_integer_number_attrs) { attributes_for(:type_de_champ_integer_number) } let(:type_de_champ_integer_number_attrs) { attributes_for(:type_de_champ_integer_number) }
it "associates nested types_de_champ to the parent procedure" do it "associates nested types_de_champ to the parent procedure" do
expect(type_de_champ.types_de_champ.size).to eq(0) expect(type_de_champ.types_de_champ.size).to eq(0)
expect(procedure.types_de_champ.size).to eq(1) expect(procedure.types_de_champ.size).to eq(1)
procedure.update(types_de_champ_attributes: [ procedure.update!(types_de_champ_attributes: [
{ {
id: type_de_champ.id, id: type_de_champ.id,
libelle: type_de_champ.libelle, libelle: type_de_champ.libelle,

View file

@ -21,11 +21,11 @@ describe DossierSerializer do
let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure, :published, :with_type_de_champ)) } let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure, :published, :with_type_de_champ)) }
before do before do
dossier.champs << create(:champ_carte) dossier.champs << build(:champ_carte)
dossier.champs << create(:champ_siret) dossier.champs << build(:champ_siret)
dossier.champs << create(:champ_integer_number) dossier.champs << build(:champ_integer_number)
dossier.champs << create(:champ_decimal_number) dossier.champs << build(:champ_decimal_number)
dossier.champs << create(:champ_linked_drop_down_list) dossier.champs << build(:champ_linked_drop_down_list)
end end
it { it {

View file

@ -253,6 +253,7 @@ describe ProcedureExportService do
"Dossier ID", "Dossier ID",
"Champ", "Champ",
"Établissement SIRET", "Établissement SIRET",
"Etablissement enseigne",
"Établissement siège social", "Établissement siège social",
"Établissement NAF", "Établissement NAF",
"Établissement libellé NAF", "Établissement libellé NAF",

View file

@ -13,11 +13,11 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
context "there are some champs" do context "there are some champs" do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:avis) { create :avis, dossier: dossier, instructeur: instructeur } let(:avis) { create :avis, dossier: dossier, instructeur: instructeur }
let(:champ1) { create(:champ, :checkbox, value: "on") } let(:champ1) { create(:champ_checkbox, dossier: dossier, value: "on") }
let(:champ2) { create(:champ, :header_section, value: "Section") } let(:champ2) { create(:champ_header_section, dossier: dossier, value: "Section") }
let(:champ3) { create(:champ, :explication, value: "mazette") } let(:champ3) { create(:champ_explication, dossier: dossier, value: "mazette") }
let(:champ4) { create(:champ, :dossier_link, value: dossier.id) } let(:champ4) { create(:champ_dossier_link, dossier: dossier, value: dossier.id) }
let(:champ5) { create(:champ_textarea, value: "Some long text in a textarea.") } let(:champ5) { create(:champ_textarea, dossier: dossier, value: "Some long text in a textarea.") }
let(:champs) { [champ1, champ2, champ3, champ4, champ5] } let(:champs) { [champ1, champ2, champ3, champ4, champ5] }
before { dossier.avis << avis } before { dossier.avis << avis }
@ -71,7 +71,7 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
context "with seen_at" do context "with seen_at" do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:nouveau_groupe_instructeur) { create(:groupe_instructeur, procedure: dossier.procedure) } let(:nouveau_groupe_instructeur) { create(:groupe_instructeur, procedure: dossier.procedure) }
let(:champ1) { create(:champ, :checkbox, value: "on") } let(:champ1) { create(:champ_checkbox, dossier: dossier, value: "on") }
let(:champs) { [champ1] } let(:champs) { [champ1] }
context "with a demande_seen_at after groupe_instructeur_updated_at" do context "with a demande_seen_at after groupe_instructeur_updated_at" do
@ -96,7 +96,7 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
context "with a dossier champ, but we are not authorized to acces the dossier" do context "with a dossier champ, but we are not authorized to acces the dossier" do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:champ) { create(:champ, :dossier_link, value: dossier.id) } let(:champ) { create(:champ_dossier_link, dossier: dossier, value: dossier.id) }
let(:champs) { [champ] } let(:champs) { [champ] }
it { is_expected.not_to have_link("Dossier nº #{dossier.id}") } it { is_expected.not_to have_link("Dossier nº #{dossier.id}") }
@ -106,7 +106,7 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
context "with a dossier_link champ but without value" do context "with a dossier_link champ but without value" do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:champ) { create(:champ, :dossier_link, value: nil) } let(:champ) { create(:champ_dossier_link, dossier: dossier, value: nil) }
let(:champs) { [champ] } let(:champs) { [champ] }
it { is_expected.to include("Pas de dossier associé") } it { is_expected.to include("Pas de dossier associé") }
@ -114,7 +114,7 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
context "with seen_at" do context "with seen_at" do
let(:dossier) { create(:dossier) } let(:dossier) { create(:dossier) }
let(:champ1) { create(:champ, :checkbox, value: "on") } let(:champ1) { create(:champ_checkbox, dossier: dossier, value: "on") }
let(:champs) { [champ1] } let(:champs) { [champ1] }
context "with a demande_seen_at after champ updated_at" do context "with a demande_seen_at after champ updated_at" do