Use enum to the fullest with TypeDeChamp.type_champs
This commit is contained in:
parent
16a719922b
commit
2d3b553e4d
21 changed files with 94 additions and 94 deletions
|
@ -26,11 +26,11 @@ class RootController < ApplicationController
|
|||
.map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) }
|
||||
|
||||
all_champs
|
||||
.select { |champ| champ.type_champ == 'header_section' }
|
||||
.select { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:header_section) }
|
||||
.each { |champ| champ.type_de_champ.libelle = 'un super titre de section' }
|
||||
|
||||
all_champs
|
||||
.select { |champ| %w(drop_down_list multiple_drop_down_list).include?(champ.type_champ) }
|
||||
.select { |champ| [TypeDeChamp.type_champs.fetch(:drop_down_list), TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)].include?(champ.type_champ) }
|
||||
.each do |champ|
|
||||
champ.type_de_champ.drop_down_list = DropDownList.new(type_de_champ: champ.type_de_champ)
|
||||
champ.drop_down_list.value =
|
||||
|
@ -42,9 +42,9 @@ class RootController < ApplicationController
|
|||
end
|
||||
|
||||
type_champ_values = {
|
||||
'date': '2016-07-26',
|
||||
'datetime': '26/07/2016 07:35',
|
||||
'textarea': 'Une description de mon projet'
|
||||
TypeDeChamp.type_champs.fetch(:date) => '2016-07-26',
|
||||
TypeDeChamp.type_champs.fetch(:datetime) => '26/07/2016 07:35',
|
||||
TypeDeChamp.type_champs.fetch(:textarea) => 'Une description de mon projet'
|
||||
}
|
||||
|
||||
type_champ_values.each do |(type_champ, value)|
|
||||
|
|
|
@ -2,17 +2,17 @@ class ChampDecorator < Draper::Decorator
|
|||
delegate_all
|
||||
|
||||
def value
|
||||
if type_champ == "date" && object.value.present?
|
||||
if type_champ == TypeDeChamp.type_champs.fetch(:date) && object.value.present?
|
||||
Date.parse(object.value).strftime("%d/%m/%Y")
|
||||
elsif type_champ.in? ["checkbox", "engagement"]
|
||||
elsif type_champ.in? [TypeDeChamp.type_champs.fetch(:checkbox), TypeDeChamp.type_champs.fetch(:engagement)]
|
||||
object.value == 'on' ? 'Oui' : 'Non'
|
||||
elsif type_champ == 'yes_no'
|
||||
elsif type_champ == TypeDeChamp.type_champs.fetch(:yes_no)
|
||||
if object.value == 'true'
|
||||
'Oui'
|
||||
elsif object.value == 'false'
|
||||
'Non'
|
||||
end
|
||||
elsif type_champ == 'multiple_drop_down_list' && object.value.present?
|
||||
elsif type_champ == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) && object.value.present?
|
||||
JSON.parse(object.value).join(', ')
|
||||
else
|
||||
object.value
|
||||
|
@ -21,9 +21,9 @@ class ChampDecorator < Draper::Decorator
|
|||
|
||||
def date_for_input
|
||||
if object.value.present?
|
||||
if type_champ == "date"
|
||||
if type_champ == TypeDeChamp.type_champs.fetch(:date)
|
||||
object.value
|
||||
elsif type_champ == "datetime" && object.value != ' 00:00'
|
||||
elsif type_champ == TypeDeChamp.type_champs.fetch(:datetime) && object.value != ' 00:00'
|
||||
DateTime.parse(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module ChampHelper
|
||||
def has_label?(champ)
|
||||
types_without_label = ['header_section', 'explication']
|
||||
types_without_label = [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]
|
||||
!types_without_label.include?(champ.type_champ)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module TypeDeChampHelper
|
||||
TOGGLES = {
|
||||
'piece_justificative' => :champ_pj?,
|
||||
'siret' => :champ_siret?,
|
||||
'linked_drop_down_list' => :champ_linked_dropdown?
|
||||
TypeDeChamp.type_champs.fetch(:piece_justificative) => :champ_pj?,
|
||||
TypeDeChamp.type_champs.fetch(:siret) => :champ_siret?,
|
||||
TypeDeChamp.type_champs.fetch(:linked_drop_down_list) => :champ_linked_dropdown?
|
||||
}
|
||||
|
||||
def tdc_options
|
||||
|
|
|
@ -19,7 +19,7 @@ class FindDubiousProceduresJob < ApplicationJob
|
|||
forbidden_tdcs = TypeDeChamp
|
||||
.joins(:procedure)
|
||||
.where("unaccent(types_de_champ.libelle) ~* unaccent(?)", forbidden_regexp)
|
||||
.where(type_champ: %w(text textarea))
|
||||
.where(type_champ: [TypeDeChamp.type_champs.fetch(:text), TypeDeChamp.type_champs.fetch(:textarea)])
|
||||
.where(procedures: { archived_at: nil, whitelisted_at: nil })
|
||||
|
||||
dubious_procedures_and_tdcs = forbidden_tdcs
|
||||
|
|
|
@ -19,6 +19,6 @@ class DropDownList < ApplicationRecord
|
|||
end
|
||||
|
||||
def multiple
|
||||
type_de_champ.type_champ == 'multiple_drop_down_list'
|
||||
type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -323,14 +323,14 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
|
||||
types_de_champ
|
||||
.reject { |tdc| ['header_section', 'explication'].include?(tdc.type_champ) }
|
||||
.reject { |tdc| [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)].include?(tdc.type_champ) }
|
||||
.each do |type_de_champ|
|
||||
|
||||
fields << field_hash(type_de_champ.libelle, 'type_de_champ', type_de_champ.id.to_s)
|
||||
end
|
||||
|
||||
types_de_champ_private
|
||||
.reject { |tdc| ['header_section', 'explication'].include?(tdc.type_champ) }
|
||||
.reject { |tdc| [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)].include?(tdc.type_champ) }
|
||||
.each do |type_de_champ|
|
||||
|
||||
fields << field_hash(type_de_champ.libelle, 'type_de_champ_private', type_de_champ.id.to_s)
|
||||
|
|
|
@ -72,7 +72,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
|
||||
def non_fillable?
|
||||
type_champ.in?(['header_section', 'explication'])
|
||||
type_champ.in?([TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)])
|
||||
end
|
||||
|
||||
def public?
|
||||
|
@ -86,7 +86,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
private
|
||||
|
||||
def remove_piece_justificative_template
|
||||
if type_champ != 'piece_justificative' && piece_justificative_template.attached?
|
||||
if type_champ != TypeDeChamp.type_champs.fetch(:piece_justificative) && piece_justificative_template.attached?
|
||||
piece_justificative_template.purge_later
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,17 +13,17 @@ class ChampsService
|
|||
|
||||
def check_piece_justificative_files(champs)
|
||||
champs.select do |champ|
|
||||
champ.type_champ == 'piece_justificative'
|
||||
champ.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)
|
||||
end.map { |c| c.piece_justificative_file_errors }.flatten
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fill_champs(champs, h)
|
||||
datetimes, not_datetimes = champs.partition { |c| c.type_champ == 'datetime' }
|
||||
datetimes, not_datetimes = champs.partition { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:datetime) }
|
||||
|
||||
not_datetimes.each do |c|
|
||||
if c.type_champ == 'piece_justificative' && h["champs"]["'#{c.id}'"].present?
|
||||
if c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) && h["champs"]["'#{c.id}'"].present?
|
||||
c.piece_justificative_file.attach(h["champs"]["'#{c.id}'"])
|
||||
else
|
||||
c.value = h[:champs]["'#{c.id}'"]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
= f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff|
|
||||
- type_champ = ff.object.object.type_champ
|
||||
|
||||
.form-inline{ class: (type_champ == 'header_section' ? 'header-section' : nil) }
|
||||
.form-inline{ class: (type_champ == TypeDeChamp.type_champs.fetch(:header_section) ? 'header-section' : nil) }
|
||||
.form-group.libelle
|
||||
%h4 Libellé
|
||||
= ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
|
||||
|
@ -20,9 +20,9 @@
|
|||
~ fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne et --valeur-- pour un séparateur.", rows: 3, cols: 30
|
||||
= fff.hidden_field :id
|
||||
|
||||
.form-group.pj-template{ class: (type_champ == 'piece_justificative') ? 'show-inline' : nil }
|
||||
.form-group.pj-template{ class: (type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)) ? 'show-inline' : nil }
|
||||
%h4 Modèle
|
||||
- if type_champ == 'piece_justificative'
|
||||
- if type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)
|
||||
- template = ff.object.object.piece_justificative_template
|
||||
|
||||
- if !template.attached?
|
||||
|
@ -38,7 +38,7 @@
|
|||
= ff.file_field :piece_justificative_template,
|
||||
direct_upload: true
|
||||
|
||||
- hide_mandatory = (ff.object.object.private? || type_champ == 'explication')
|
||||
- hide_mandatory = (ff.object.object.private? || type_champ == TypeDeChamp.type_champs.fetch(:explication))
|
||||
.form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil }
|
||||
%h4 Obligatoire ?
|
||||
.center
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
- if @facade.champs.present?
|
||||
- @facade.champs.each do |champ|
|
||||
- next if champ.type_champ == 'explication'
|
||||
- if champ.type_champ == 'header_section'
|
||||
- next if champ.type_champ == TypeDeChamp.type_champs.fetch(:explication)
|
||||
- if champ.type_champ == TypeDeChamp.type_champs.fetch(:header_section)
|
||||
.row.title-row.margin-top-40
|
||||
.col-xs-3.split-hr
|
||||
.col-xs-6.dossier-title= champ.libelle
|
||||
|
@ -38,7 +38,7 @@
|
|||
= "-"
|
||||
.col-xs-5.depositaire-info{ id: "champ-#{champ.id}-value" }
|
||||
- if champ.decorate.value.present? || champ.piece_justificative_file.attached?
|
||||
- if champ.type_champ == 'dossier_link'
|
||||
- if champ.type_champ == TypeDeChamp.type_champs.fetch(:dossier_link)
|
||||
- dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value)
|
||||
- if dossier
|
||||
= link_to("Dossier #{dossier.id}", modifier_dossier_path(dossier), target: '_blank')
|
||||
|
@ -46,11 +46,11 @@
|
|||
= sanitize(dossier.text_summary)
|
||||
- else
|
||||
Pas de dossier associé
|
||||
- elsif champ.type_champ == 'piece_justificative'
|
||||
- elsif champ.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)
|
||||
= render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: true }
|
||||
- elsif champ.type_champ == 'textarea'
|
||||
- elsif champ.type_champ == TypeDeChamp.type_champs.fetch(:textarea)
|
||||
= simple_format(champ.decorate.value)
|
||||
- elsif champ.type_champ == 'linked_drop_down_list'
|
||||
- elsif champ.type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
||||
= champ.for_display
|
||||
- else
|
||||
= sanitize(champ.decorate.value)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
%table.table.vertical.dossier-champs
|
||||
%tbody
|
||||
- champs.reject { |c| c.type_champ == "explication" }.each do |c|
|
||||
- champs.reject { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:explication) }.each do |c|
|
||||
%tr
|
||||
- case c.type_champ
|
||||
- when "header_section"
|
||||
- when TypeDeChamp.type_champs.fetch(:header_section)
|
||||
%th.header-section{ colspan: 3 }
|
||||
= c.libelle
|
||||
- when "multiple_drop_down_list"
|
||||
- when TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
||||
%th.libelle
|
||||
= "#{c.libelle} :"
|
||||
%td.rich-text
|
||||
|
@ -15,11 +15,11 @@
|
|||
- c.value.split(", ").each do |item|
|
||||
%li
|
||||
= item
|
||||
- when "linked_drop_down_list"
|
||||
- when TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
||||
%th.libelle
|
||||
= "#{c.libelle} :"
|
||||
%td= c.for_display
|
||||
- when "dossier_link"
|
||||
- when TypeDeChamp.type_champs.fetch(:dossier_link)
|
||||
%th.libelle
|
||||
= "#{c.libelle} :"
|
||||
%td.rich-text
|
||||
|
@ -34,7 +34,7 @@
|
|||
= sanitize(dossier.text_summary)
|
||||
- else
|
||||
Pas de dossier associé
|
||||
- when "piece_justificative"
|
||||
- when TypeDeChamp.type_champs.fetch(:piece_justificative)
|
||||
%th.libelle
|
||||
= "#{c.libelle} :"
|
||||
%td.rich-text
|
||||
|
@ -43,13 +43,13 @@
|
|||
= render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: c, user_can_upload: false }
|
||||
- else
|
||||
Pièce justificative non fournie
|
||||
- when "textarea"
|
||||
- when TypeDeChamp.type_champs.fetch(:textarea)
|
||||
%th.libelle
|
||||
= "#{c.libelle} :"
|
||||
%td.rich-text
|
||||
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
|
||||
= simple_format(c.value)
|
||||
- when "siret"
|
||||
- when TypeDeChamp.type_champs.fetch(:siret)
|
||||
%th.libelle
|
||||
= "#{c.libelle} :"
|
||||
%td.rich-text
|
||||
|
@ -62,7 +62,7 @@
|
|||
%td.rich-text
|
||||
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
|
||||
= sanitize(c.value)
|
||||
- if c.type_champ != "header_section"
|
||||
- if c.type_champ != TypeDeChamp.type_champs.fetch(:header_section)
|
||||
%td.updated-at
|
||||
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
|
||||
modifié le
|
||||
|
|
|
@ -32,7 +32,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
|
||||
describe '#update' do
|
||||
let(:libelle) { 'mon libelle' }
|
||||
let(:type_champ) { 'header_section' }
|
||||
let(:type_champ) { TypeDeChamp.type_champs.fetch(:header_section) }
|
||||
let(:description) { 'titi' }
|
||||
let(:order_place) { '' }
|
||||
let(:types_de_champ_id) { '' }
|
||||
|
@ -74,12 +74,12 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
subject { procedure.types_de_champ.first }
|
||||
|
||||
it { expect(subject.libelle).to eq('mon libelle') }
|
||||
it { expect(subject.type_champ).to eq('header_section') }
|
||||
it { expect(subject.type_champ).to eq(TypeDeChamp.type_champs.fetch(:header_section)) }
|
||||
it { expect(subject.description).to eq('titi') }
|
||||
end
|
||||
|
||||
context 'when type_champ is header_section and mandatory is true' do
|
||||
let(:type_champ) { 'header_section' }
|
||||
let(:type_champ) { TypeDeChamp.type_champs.fetch(:header_section) }
|
||||
let(:mandatory) { 'on' }
|
||||
|
||||
before do
|
||||
|
@ -98,7 +98,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
let(:type_de_champ) { procedure.types_de_champ.first }
|
||||
let(:types_de_champ_id) { type_de_champ.id }
|
||||
let(:libelle) { 'toto' }
|
||||
let(:type_champ) { 'header_section' }
|
||||
let(:type_champ) { TypeDeChamp.type_champs.fetch(:header_section) }
|
||||
let(:description) { 'citrouille' }
|
||||
let(:order_place) { '0' }
|
||||
let(:mandatory) { 'on' }
|
||||
|
@ -111,7 +111,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
subject { procedure.types_de_champ.first }
|
||||
|
||||
it { expect(subject.libelle).to eq('toto') }
|
||||
it { expect(subject.type_champ).to eq('header_section') }
|
||||
it { expect(subject.type_champ).to eq(TypeDeChamp.type_champs.fetch(:header_section)) }
|
||||
it { expect(subject.description).to eq('citrouille') }
|
||||
it { expect(subject.order_place).to eq(0) }
|
||||
it { expect(subject.order_place).to be_truthy }
|
||||
|
|
|
@ -32,7 +32,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
|
|||
|
||||
describe '#update' do
|
||||
let(:libelle) { 'mon libelle' }
|
||||
let(:type_champ) { 'text' }
|
||||
let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
|
||||
let(:description) { 'titi' }
|
||||
let(:order_place) { '' }
|
||||
let(:types_de_champ_id) { '' }
|
||||
|
@ -84,7 +84,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
|
|||
let(:type_de_champ) { procedure.types_de_champ_private.first }
|
||||
let(:types_de_champ_id) { type_de_champ.id }
|
||||
let(:libelle) { 'toto' }
|
||||
let(:type_champ) { 'text' }
|
||||
let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
|
||||
let(:description) { 'citrouille' }
|
||||
let(:order_place) { '0' }
|
||||
let(:mandatory) { 'on' }
|
||||
|
@ -94,7 +94,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
|
|||
end
|
||||
subject { procedure.types_de_champ_private.first }
|
||||
it { expect(subject.libelle).to eq('toto') }
|
||||
it { expect(subject.type_champ).to eq('text') }
|
||||
it { expect(subject.type_champ).to eq(TypeDeChamp.type_champs.fetch(:text)) }
|
||||
it { expect(subject.description).to eq('citrouille') }
|
||||
it { expect(subject.order_place).to eq(0) }
|
||||
it { expect(subject.order_place).to be_truthy }
|
||||
|
|
|
@ -56,7 +56,7 @@ FactoryBot.define do
|
|||
trait :with_dossier_link do
|
||||
after(:create) do |dossier, _evaluator|
|
||||
linked_dossier = create(:dossier)
|
||||
type_de_champ = dossier.procedure.types_de_champ.find { |t| t.type_champ == 'dossier_link' }
|
||||
type_de_champ = dossier.procedure.types_de_champ.find { |t| t.type_champ == TypeDeChamp.type_champs.fetch(:dossier_link) }
|
||||
champ = dossier.champs.find { |c| c.type_de_champ == type_de_champ }
|
||||
|
||||
champ.value = linked_dossier.id
|
||||
|
|
|
@ -3,84 +3,84 @@ FactoryBot.define do
|
|||
private false
|
||||
sequence(:libelle) { |n| "Libelle du champ #{n}" }
|
||||
sequence(:description) { |n| "description du champ #{n}" }
|
||||
type_champ 'text'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:text)
|
||||
order_place 1
|
||||
mandatory false
|
||||
|
||||
factory :type_de_champ_text, class: 'TypesDeChamp::TextTypeDeChamp' do
|
||||
type_champ 'text'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:text)
|
||||
end
|
||||
factory :type_de_champ_textarea, class: 'TypesDeChamp::TextareaTypeDeChamp' do
|
||||
type_champ 'textarea'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:textarea)
|
||||
end
|
||||
factory :type_de_champ_number, class: 'TypesDeChamp::NumberTypeDeChamp' do
|
||||
type_champ 'number'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:number)
|
||||
end
|
||||
factory :type_de_champ_checkbox, class: 'TypesDeChamp::CheckboxTypeDeChamp' do
|
||||
type_champ 'checkbox'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:checkbox)
|
||||
end
|
||||
factory :type_de_champ_civilite, class: 'TypesDeChamp::CiviliteTypeDeChamp' do
|
||||
type_champ 'civilite'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:civilite)
|
||||
end
|
||||
factory :type_de_champ_email, class: 'TypesDeChamp::EmailTypeDeChamp' do
|
||||
type_champ 'email'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:email)
|
||||
end
|
||||
factory :type_de_champ_phone, class: 'TypesDeChamp::PhoneTypeDeChamp' do
|
||||
type_champ 'phone'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:phone)
|
||||
end
|
||||
factory :type_de_champ_address, class: 'TypesDeChamp::AddressTypeDeChamp' do
|
||||
type_champ 'address'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:address)
|
||||
end
|
||||
factory :type_de_champ_yes_no, class: 'TypesDeChamp::YesNoTypeDeChamp' do
|
||||
libelle 'Yes/no'
|
||||
type_champ 'yes_no'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:yes_no)
|
||||
end
|
||||
factory :type_de_champ_date, class: 'TypesDeChamp::DateTypeDeChamp' do
|
||||
type_champ 'date'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:date)
|
||||
end
|
||||
factory :type_de_champ_datetime, class: 'TypesDeChamp::DatetimeTypeDeChamp' do
|
||||
type_champ 'datetime'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:datetime)
|
||||
end
|
||||
factory :type_de_champ_drop_down_list, class: 'TypesDeChamp::DropDownListTypeDeChamp' do
|
||||
libelle 'Menu déroulant'
|
||||
type_champ 'drop_down_list'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||
drop_down_list { create(:drop_down_list) }
|
||||
end
|
||||
factory :type_de_champ_multiple_drop_down_list, class: 'TypesDeChamp::MultipleDropDownListTypeDeChamp' do
|
||||
type_champ 'multiple_drop_down_list'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
||||
drop_down_list { create(:drop_down_list) }
|
||||
end
|
||||
factory :type_de_champ_linked_drop_down_list, class: 'TypesDeChamp::LinkedDropDownListTypeDeChamp' do
|
||||
type_champ 'linked_drop_down_list'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
||||
drop_down_list { create(:drop_down_list) }
|
||||
end
|
||||
factory :type_de_champ_pays, class: 'TypesDeChamp::PaysTypeDeChamp' do
|
||||
type_champ 'pays'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:pays)
|
||||
end
|
||||
factory :type_de_champ_regions, class: 'TypesDeChamp::RegionTypeDeChamp' do
|
||||
type_champ 'regions'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:regions)
|
||||
end
|
||||
factory :type_de_champ_departements, class: 'TypesDeChamp::DepartementTypeDeChamp' do
|
||||
type_champ 'departements'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:departements)
|
||||
end
|
||||
factory :type_de_champ_engagement, class: 'TypesDeChamp::EngagementTypeDeChamp' do
|
||||
type_champ 'engagement'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:engagement)
|
||||
end
|
||||
factory :type_de_champ_header_section, class: 'TypesDeChamp::HeaderSectionTypeDeChamp' do
|
||||
type_champ 'header_section'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:header_section)
|
||||
end
|
||||
factory :type_de_champ_explication, class: 'TypesDeChamp::ExplicationTypeDeChamp' do
|
||||
type_champ 'explication'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:explication)
|
||||
end
|
||||
factory :type_de_champ_dossier_link, class: 'TypesDeChamp::DossierLinkTypeDeChamp' do
|
||||
libelle 'Référence autre dossier'
|
||||
type_champ 'dossier_link'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:dossier_link)
|
||||
end
|
||||
factory :type_de_champ_piece_justificative, class: 'TypesDeChamp::PieceJustificativeTypeDeChamp' do
|
||||
type_champ 'piece_justificative'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:piece_justificative)
|
||||
end
|
||||
factory :type_de_champ_siret, class: 'TypesDeChamp::SiretTypeDeChamp' do
|
||||
type_champ 'siret'
|
||||
type_champ TypeDeChamp.type_champs.fetch(:siret)
|
||||
end
|
||||
|
||||
trait :private do
|
||||
|
|
|
@ -18,7 +18,7 @@ feature 'add a new type de champs', js: true do
|
|||
|
||||
context 'user fill a new type de champ', js: true do
|
||||
let(:libelle) { 'mon libelle' }
|
||||
let(:type_champ) { 'text' }
|
||||
let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
|
||||
let(:description) { 'ma super histoire' }
|
||||
before do
|
||||
page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set libelle
|
||||
|
@ -39,7 +39,7 @@ feature 'add a new type de champs', js: true do
|
|||
|
||||
context 'user fill another one' do
|
||||
let(:libelle) { 'coucou' }
|
||||
let(:type_champ_value) { 'textarea' }
|
||||
let(:type_champ_value) { TypeDeChamp.type_champs.fetch(:textarea) }
|
||||
let(:type_champ_label) { 'Zone de texte' }
|
||||
let(:description) { 'to be or not to be' }
|
||||
before do
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe TypeDeChampHelper, type: :helper do
|
||||
describe ".tdc_options" do
|
||||
let(:pj_option) { ["Pièce justificative", "piece_justificative"] }
|
||||
let(:pj_option) { ["Pièce justificative", TypeDeChamp.type_champs.fetch(:piece_justificative)] }
|
||||
|
||||
subject { tdc_options }
|
||||
|
||||
|
|
|
@ -160,8 +160,8 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
context 'when the procedure has 2 types de champ date and datetime' do
|
||||
let(:types_de_champ) do
|
||||
[
|
||||
create(:type_de_champ_date, libelle: 'date'),
|
||||
create(:type_de_champ_datetime, libelle: 'datetime')
|
||||
create(:type_de_champ_date, libelle: TypeDeChamp.type_champs.fetch(:date)),
|
||||
create(:type_de_champ_datetime, libelle: TypeDeChamp.type_champs.fetch(:datetime))
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -171,12 +171,12 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
context 'and its value in the dossier are not nil' do
|
||||
before do
|
||||
dossier.champs
|
||||
.select { |champ| champ.type_champ == 'date' }
|
||||
.select { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:date) }
|
||||
.first
|
||||
.update(value: '2017-04-15')
|
||||
|
||||
dossier.champs
|
||||
.select { |champ| champ.type_champ == 'datetime' }
|
||||
.select { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) }
|
||||
.first
|
||||
.update(value: '2017-09-13 09:00')
|
||||
end
|
||||
|
|
|
@ -659,10 +659,10 @@ describe Procedure do
|
|||
}
|
||||
|
||||
before do
|
||||
subject.types_de_champ[2].update_attribute(:type_champ, 'header_section')
|
||||
subject.types_de_champ[3].update_attribute(:type_champ, 'explication')
|
||||
subject.types_de_champ_private[2].update_attribute(:type_champ, 'header_section')
|
||||
subject.types_de_champ_private[3].update_attribute(:type_champ, 'explication')
|
||||
subject.types_de_champ[2].update_attribute(:type_champ,TypeDeChamp.type_champs.fetch(:header_section))
|
||||
subject.types_de_champ[3].update_attribute(:type_champ,TypeDeChamp.type_champs.fetch(:explication))
|
||||
subject.types_de_champ_private[2].update_attribute(:type_champ,TypeDeChamp.type_champs.fetch(:header_section))
|
||||
subject.types_de_champ_private[3].update_attribute(:type_champ,TypeDeChamp.type_champs.fetch(:explication))
|
||||
end
|
||||
|
||||
it { expect(subject.fields).to eq(expected) }
|
||||
|
|
|
@ -10,11 +10,11 @@ shared_examples 'type_de_champ_spec' do
|
|||
it { is_expected.not_to allow_value(nil).for(:type_champ) }
|
||||
it { is_expected.not_to allow_value('').for(:type_champ) }
|
||||
|
||||
it { is_expected.to allow_value('text').for(:type_champ) }
|
||||
it { is_expected.to allow_value('textarea').for(:type_champ) }
|
||||
it { is_expected.to allow_value('datetime').for(:type_champ) }
|
||||
it { is_expected.to allow_value('number').for(:type_champ) }
|
||||
it { is_expected.to allow_value('checkbox').for(:type_champ) }
|
||||
it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:text)).for(:type_champ) }
|
||||
it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:textarea)).for(:type_champ) }
|
||||
it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:datetime)).for(:type_champ) }
|
||||
it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:number)).for(:type_champ) }
|
||||
it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:checkbox)).for(:type_champ) }
|
||||
|
||||
it do
|
||||
TypeDeChamp.type_champs.each do |(type_champ, _)|
|
||||
|
@ -53,7 +53,7 @@ shared_examples 'type_de_champ_spec' do
|
|||
end
|
||||
|
||||
context 'when the target type_champ is not pj' do
|
||||
let(:target_type_champ) { 'text' }
|
||||
let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:text) }
|
||||
|
||||
context 'calls template.purge_later when a file is attached' do
|
||||
let(:attached) { true }
|
||||
|
@ -69,7 +69,7 @@ shared_examples 'type_de_champ_spec' do
|
|||
end
|
||||
|
||||
context 'when the target type_champ is pj' do
|
||||
let(:target_type_champ) { 'piece_justificative' }
|
||||
let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||
|
||||
context 'does not call template.purge_later when a file is attached' do
|
||||
let(:attached) { true }
|
||||
|
|
Loading…
Reference in a new issue