Use enum to the fullest with TypeDeChamp.type_champs

This commit is contained in:
gregoirenovel 2018-08-28 16:22:34 +02:00
parent 16a719922b
commit 2d3b553e4d
21 changed files with 94 additions and 94 deletions

View file

@ -26,11 +26,11 @@ class RootController < ApplicationController
.map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) } .map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) }
all_champs 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' } .each { |champ| champ.type_de_champ.libelle = 'un super titre de section' }
all_champs 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| .each do |champ|
champ.type_de_champ.drop_down_list = DropDownList.new(type_de_champ: champ.type_de_champ) champ.type_de_champ.drop_down_list = DropDownList.new(type_de_champ: champ.type_de_champ)
champ.drop_down_list.value = champ.drop_down_list.value =
@ -42,9 +42,9 @@ class RootController < ApplicationController
end end
type_champ_values = { type_champ_values = {
'date': '2016-07-26', TypeDeChamp.type_champs.fetch(:date) => '2016-07-26',
'datetime': '26/07/2016 07:35', TypeDeChamp.type_champs.fetch(:datetime) => '26/07/2016 07:35',
'textarea': 'Une description de mon projet' TypeDeChamp.type_champs.fetch(:textarea) => 'Une description de mon projet'
} }
type_champ_values.each do |(type_champ, value)| type_champ_values.each do |(type_champ, value)|

View file

@ -2,17 +2,17 @@ class ChampDecorator < Draper::Decorator
delegate_all delegate_all
def value 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") 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' object.value == 'on' ? 'Oui' : 'Non'
elsif type_champ == 'yes_no' elsif type_champ == TypeDeChamp.type_champs.fetch(:yes_no)
if object.value == 'true' if object.value == 'true'
'Oui' 'Oui'
elsif object.value == 'false' elsif object.value == 'false'
'Non' 'Non'
end 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(', ') JSON.parse(object.value).join(', ')
else else
object.value object.value
@ -21,9 +21,9 @@ class ChampDecorator < Draper::Decorator
def date_for_input def date_for_input
if object.value.present? if object.value.present?
if type_champ == "date" if type_champ == TypeDeChamp.type_champs.fetch(:date)
object.value 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") DateTime.parse(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d")
end end
end end

View file

@ -1,6 +1,6 @@
module ChampHelper module ChampHelper
def has_label?(champ) 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) !types_without_label.include?(champ.type_champ)
end end
end end

View file

@ -1,8 +1,8 @@
module TypeDeChampHelper module TypeDeChampHelper
TOGGLES = { TOGGLES = {
'piece_justificative' => :champ_pj?, TypeDeChamp.type_champs.fetch(:piece_justificative) => :champ_pj?,
'siret' => :champ_siret?, TypeDeChamp.type_champs.fetch(:siret) => :champ_siret?,
'linked_drop_down_list' => :champ_linked_dropdown? TypeDeChamp.type_champs.fetch(:linked_drop_down_list) => :champ_linked_dropdown?
} }
def tdc_options def tdc_options

View file

@ -19,7 +19,7 @@ class FindDubiousProceduresJob < ApplicationJob
forbidden_tdcs = TypeDeChamp forbidden_tdcs = TypeDeChamp
.joins(:procedure) .joins(:procedure)
.where("unaccent(types_de_champ.libelle) ~* unaccent(?)", forbidden_regexp) .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 }) .where(procedures: { archived_at: nil, whitelisted_at: nil })
dubious_procedures_and_tdcs = forbidden_tdcs dubious_procedures_and_tdcs = forbidden_tdcs

View file

@ -19,6 +19,6 @@ class DropDownList < ApplicationRecord
end end
def multiple 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
end end

View file

@ -323,14 +323,14 @@ class Procedure < ApplicationRecord
end end
types_de_champ 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| .each do |type_de_champ|
fields << field_hash(type_de_champ.libelle, 'type_de_champ', type_de_champ.id.to_s) fields << field_hash(type_de_champ.libelle, 'type_de_champ', type_de_champ.id.to_s)
end end
types_de_champ_private 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| .each do |type_de_champ|
fields << field_hash(type_de_champ.libelle, 'type_de_champ_private', type_de_champ.id.to_s) fields << field_hash(type_de_champ.libelle, 'type_de_champ_private', type_de_champ.id.to_s)

View file

@ -72,7 +72,7 @@ class TypeDeChamp < ApplicationRecord
end end
def non_fillable? def non_fillable?
type_champ.in?(['header_section', 'explication']) type_champ.in?([TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)])
end end
def public? def public?
@ -86,7 +86,7 @@ class TypeDeChamp < ApplicationRecord
private private
def remove_piece_justificative_template 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 piece_justificative_template.purge_later
end end
end end

View file

@ -13,17 +13,17 @@ class ChampsService
def check_piece_justificative_files(champs) def check_piece_justificative_files(champs)
champs.select do |champ| 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.map { |c| c.piece_justificative_file_errors }.flatten
end end
private private
def fill_champs(champs, h) 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| 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}'"]) c.piece_justificative_file.attach(h["champs"]["'#{c.id}'"])
else else
c.value = h[:champs]["'#{c.id}'"] c.value = h[:champs]["'#{c.id}'"]

View file

@ -1,7 +1,7 @@
= f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff| = f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff|
- type_champ = ff.object.object.type_champ - 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 .form-group.libelle
%h4 Libellé %h4 Libellé
= ff.text_field :libelle, class: 'form-control libelle', placeholder: '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.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 = 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 %h4 Modèle
- if type_champ == 'piece_justificative' - if type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)
- template = ff.object.object.piece_justificative_template - template = ff.object.object.piece_justificative_template
- if !template.attached? - if !template.attached?
@ -38,7 +38,7 @@
= ff.file_field :piece_justificative_template, = ff.file_field :piece_justificative_template,
direct_upload: true 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 } .form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil }
%h4 Obligatoire ? %h4 Obligatoire ?
.center .center

View file

@ -25,8 +25,8 @@
- if @facade.champs.present? - if @facade.champs.present?
- @facade.champs.each do |champ| - @facade.champs.each do |champ|
- next if champ.type_champ == 'explication' - next if champ.type_champ == TypeDeChamp.type_champs.fetch(:explication)
- if champ.type_champ == 'header_section' - if champ.type_champ == TypeDeChamp.type_champs.fetch(:header_section)
.row.title-row.margin-top-40 .row.title-row.margin-top-40
.col-xs-3.split-hr .col-xs-3.split-hr
.col-xs-6.dossier-title= champ.libelle .col-xs-6.dossier-title= champ.libelle
@ -38,7 +38,7 @@
= "-" = "-"
.col-xs-5.depositaire-info{ id: "champ-#{champ.id}-value" } .col-xs-5.depositaire-info{ id: "champ-#{champ.id}-value" }
- if champ.decorate.value.present? || champ.piece_justificative_file.attached? - 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) - dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value)
- if dossier - if dossier
= link_to("Dossier #{dossier.id}", modifier_dossier_path(dossier), target: '_blank') = link_to("Dossier #{dossier.id}", modifier_dossier_path(dossier), target: '_blank')
@ -46,11 +46,11 @@
= sanitize(dossier.text_summary) = sanitize(dossier.text_summary)
- else - else
Pas de dossier associé 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 } = 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) = 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 = champ.for_display
- else - else
= sanitize(champ.decorate.value) = sanitize(champ.decorate.value)

View file

@ -1,12 +1,12 @@
%table.table.vertical.dossier-champs %table.table.vertical.dossier-champs
%tbody %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 %tr
- case c.type_champ - case c.type_champ
- when "header_section" - when TypeDeChamp.type_champs.fetch(:header_section)
%th.header-section{ colspan: 3 } %th.header-section{ colspan: 3 }
= c.libelle = c.libelle
- when "multiple_drop_down_list" - when TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
%th.libelle %th.libelle
= "#{c.libelle} :" = "#{c.libelle} :"
%td.rich-text %td.rich-text
@ -15,11 +15,11 @@
- c.value.split(", ").each do |item| - c.value.split(", ").each do |item|
%li %li
= item = item
- when "linked_drop_down_list" - when TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
%th.libelle %th.libelle
= "#{c.libelle} :" = "#{c.libelle} :"
%td= c.for_display %td= c.for_display
- when "dossier_link" - when TypeDeChamp.type_champs.fetch(:dossier_link)
%th.libelle %th.libelle
= "#{c.libelle} :" = "#{c.libelle} :"
%td.rich-text %td.rich-text
@ -34,7 +34,7 @@
= sanitize(dossier.text_summary) = sanitize(dossier.text_summary)
- else - else
Pas de dossier associé Pas de dossier associé
- when "piece_justificative" - when TypeDeChamp.type_champs.fetch(:piece_justificative)
%th.libelle %th.libelle
= "#{c.libelle} :" = "#{c.libelle} :"
%td.rich-text %td.rich-text
@ -43,13 +43,13 @@
= render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: c, user_can_upload: false } = render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: c, user_can_upload: false }
- else - else
Pièce justificative non fournie Pièce justificative non fournie
- when "textarea" - when TypeDeChamp.type_champs.fetch(:textarea)
%th.libelle %th.libelle
= "#{c.libelle} :" = "#{c.libelle} :"
%td.rich-text %td.rich-text
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
= simple_format(c.value) = simple_format(c.value)
- when "siret" - when TypeDeChamp.type_champs.fetch(:siret)
%th.libelle %th.libelle
= "#{c.libelle} :" = "#{c.libelle} :"
%td.rich-text %td.rich-text
@ -62,7 +62,7 @@
%td.rich-text %td.rich-text
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
= sanitize(c.value) = sanitize(c.value)
- if c.type_champ != "header_section" - if c.type_champ != TypeDeChamp.type_champs.fetch(:header_section)
%td.updated-at %td.updated-at
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
modifié le modifié le

View file

@ -32,7 +32,7 @@ describe Admin::TypesDeChampController, type: :controller do
describe '#update' do describe '#update' do
let(:libelle) { 'mon libelle' } let(:libelle) { 'mon libelle' }
let(:type_champ) { 'header_section' } let(:type_champ) { TypeDeChamp.type_champs.fetch(:header_section) }
let(:description) { 'titi' } let(:description) { 'titi' }
let(:order_place) { '' } let(:order_place) { '' }
let(:types_de_champ_id) { '' } let(:types_de_champ_id) { '' }
@ -74,12 +74,12 @@ describe Admin::TypesDeChampController, type: :controller do
subject { procedure.types_de_champ.first } subject { procedure.types_de_champ.first }
it { expect(subject.libelle).to eq('mon libelle') } 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') } it { expect(subject.description).to eq('titi') }
end end
context 'when type_champ is header_section and mandatory is true' do 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' } let(:mandatory) { 'on' }
before do before do
@ -98,7 +98,7 @@ describe Admin::TypesDeChampController, type: :controller do
let(:type_de_champ) { procedure.types_de_champ.first } let(:type_de_champ) { procedure.types_de_champ.first }
let(:types_de_champ_id) { type_de_champ.id } let(:types_de_champ_id) { type_de_champ.id }
let(:libelle) { 'toto' } let(:libelle) { 'toto' }
let(:type_champ) { 'header_section' } let(:type_champ) { TypeDeChamp.type_champs.fetch(:header_section) }
let(:description) { 'citrouille' } let(:description) { 'citrouille' }
let(:order_place) { '0' } let(:order_place) { '0' }
let(:mandatory) { 'on' } let(:mandatory) { 'on' }
@ -111,7 +111,7 @@ describe Admin::TypesDeChampController, type: :controller do
subject { procedure.types_de_champ.first } subject { procedure.types_de_champ.first }
it { expect(subject.libelle).to eq('toto') } 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.description).to eq('citrouille') }
it { expect(subject.order_place).to eq(0) } it { expect(subject.order_place).to eq(0) }
it { expect(subject.order_place).to be_truthy } it { expect(subject.order_place).to be_truthy }

View file

@ -32,7 +32,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
describe '#update' do describe '#update' do
let(:libelle) { 'mon libelle' } let(:libelle) { 'mon libelle' }
let(:type_champ) { 'text' } let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
let(:description) { 'titi' } let(:description) { 'titi' }
let(:order_place) { '' } let(:order_place) { '' }
let(:types_de_champ_id) { '' } 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(:type_de_champ) { procedure.types_de_champ_private.first }
let(:types_de_champ_id) { type_de_champ.id } let(:types_de_champ_id) { type_de_champ.id }
let(:libelle) { 'toto' } let(:libelle) { 'toto' }
let(:type_champ) { 'text' } let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
let(:description) { 'citrouille' } let(:description) { 'citrouille' }
let(:order_place) { '0' } let(:order_place) { '0' }
let(:mandatory) { 'on' } let(:mandatory) { 'on' }
@ -94,7 +94,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
end end
subject { procedure.types_de_champ_private.first } subject { procedure.types_de_champ_private.first }
it { expect(subject.libelle).to eq('toto') } 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.description).to eq('citrouille') }
it { expect(subject.order_place).to eq(0) } it { expect(subject.order_place).to eq(0) }
it { expect(subject.order_place).to be_truthy } it { expect(subject.order_place).to be_truthy }

View file

@ -56,7 +56,7 @@ FactoryBot.define do
trait :with_dossier_link do trait :with_dossier_link do
after(:create) do |dossier, _evaluator| after(:create) do |dossier, _evaluator|
linked_dossier = create(:dossier) 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 = dossier.champs.find { |c| c.type_de_champ == type_de_champ }
champ.value = linked_dossier.id champ.value = linked_dossier.id

View file

@ -3,84 +3,84 @@ FactoryBot.define do
private false private false
sequence(:libelle) { |n| "Libelle du champ #{n}" } sequence(:libelle) { |n| "Libelle du champ #{n}" }
sequence(:description) { |n| "description du champ #{n}" } sequence(:description) { |n| "description du champ #{n}" }
type_champ 'text' type_champ TypeDeChamp.type_champs.fetch(:text)
order_place 1 order_place 1
mandatory false mandatory false
factory :type_de_champ_text, class: 'TypesDeChamp::TextTypeDeChamp' do factory :type_de_champ_text, class: 'TypesDeChamp::TextTypeDeChamp' do
type_champ 'text' type_champ TypeDeChamp.type_champs.fetch(:text)
end end
factory :type_de_champ_textarea, class: 'TypesDeChamp::TextareaTypeDeChamp' do factory :type_de_champ_textarea, class: 'TypesDeChamp::TextareaTypeDeChamp' do
type_champ 'textarea' type_champ TypeDeChamp.type_champs.fetch(:textarea)
end end
factory :type_de_champ_number, class: 'TypesDeChamp::NumberTypeDeChamp' do factory :type_de_champ_number, class: 'TypesDeChamp::NumberTypeDeChamp' do
type_champ 'number' type_champ TypeDeChamp.type_champs.fetch(:number)
end end
factory :type_de_champ_checkbox, class: 'TypesDeChamp::CheckboxTypeDeChamp' do factory :type_de_champ_checkbox, class: 'TypesDeChamp::CheckboxTypeDeChamp' do
type_champ 'checkbox' type_champ TypeDeChamp.type_champs.fetch(:checkbox)
end end
factory :type_de_champ_civilite, class: 'TypesDeChamp::CiviliteTypeDeChamp' do factory :type_de_champ_civilite, class: 'TypesDeChamp::CiviliteTypeDeChamp' do
type_champ 'civilite' type_champ TypeDeChamp.type_champs.fetch(:civilite)
end end
factory :type_de_champ_email, class: 'TypesDeChamp::EmailTypeDeChamp' do factory :type_de_champ_email, class: 'TypesDeChamp::EmailTypeDeChamp' do
type_champ 'email' type_champ TypeDeChamp.type_champs.fetch(:email)
end end
factory :type_de_champ_phone, class: 'TypesDeChamp::PhoneTypeDeChamp' do factory :type_de_champ_phone, class: 'TypesDeChamp::PhoneTypeDeChamp' do
type_champ 'phone' type_champ TypeDeChamp.type_champs.fetch(:phone)
end end
factory :type_de_champ_address, class: 'TypesDeChamp::AddressTypeDeChamp' do factory :type_de_champ_address, class: 'TypesDeChamp::AddressTypeDeChamp' do
type_champ 'address' type_champ TypeDeChamp.type_champs.fetch(:address)
end end
factory :type_de_champ_yes_no, class: 'TypesDeChamp::YesNoTypeDeChamp' do factory :type_de_champ_yes_no, class: 'TypesDeChamp::YesNoTypeDeChamp' do
libelle 'Yes/no' libelle 'Yes/no'
type_champ 'yes_no' type_champ TypeDeChamp.type_champs.fetch(:yes_no)
end end
factory :type_de_champ_date, class: 'TypesDeChamp::DateTypeDeChamp' do factory :type_de_champ_date, class: 'TypesDeChamp::DateTypeDeChamp' do
type_champ 'date' type_champ TypeDeChamp.type_champs.fetch(:date)
end end
factory :type_de_champ_datetime, class: 'TypesDeChamp::DatetimeTypeDeChamp' do factory :type_de_champ_datetime, class: 'TypesDeChamp::DatetimeTypeDeChamp' do
type_champ 'datetime' type_champ TypeDeChamp.type_champs.fetch(:datetime)
end end
factory :type_de_champ_drop_down_list, class: 'TypesDeChamp::DropDownListTypeDeChamp' do factory :type_de_champ_drop_down_list, class: 'TypesDeChamp::DropDownListTypeDeChamp' do
libelle 'Menu déroulant' 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) } drop_down_list { create(:drop_down_list) }
end end
factory :type_de_champ_multiple_drop_down_list, class: 'TypesDeChamp::MultipleDropDownListTypeDeChamp' do 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) } drop_down_list { create(:drop_down_list) }
end end
factory :type_de_champ_linked_drop_down_list, class: 'TypesDeChamp::LinkedDropDownListTypeDeChamp' do 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) } drop_down_list { create(:drop_down_list) }
end end
factory :type_de_champ_pays, class: 'TypesDeChamp::PaysTypeDeChamp' do factory :type_de_champ_pays, class: 'TypesDeChamp::PaysTypeDeChamp' do
type_champ 'pays' type_champ TypeDeChamp.type_champs.fetch(:pays)
end end
factory :type_de_champ_regions, class: 'TypesDeChamp::RegionTypeDeChamp' do factory :type_de_champ_regions, class: 'TypesDeChamp::RegionTypeDeChamp' do
type_champ 'regions' type_champ TypeDeChamp.type_champs.fetch(:regions)
end end
factory :type_de_champ_departements, class: 'TypesDeChamp::DepartementTypeDeChamp' do factory :type_de_champ_departements, class: 'TypesDeChamp::DepartementTypeDeChamp' do
type_champ 'departements' type_champ TypeDeChamp.type_champs.fetch(:departements)
end end
factory :type_de_champ_engagement, class: 'TypesDeChamp::EngagementTypeDeChamp' do factory :type_de_champ_engagement, class: 'TypesDeChamp::EngagementTypeDeChamp' do
type_champ 'engagement' type_champ TypeDeChamp.type_champs.fetch(:engagement)
end end
factory :type_de_champ_header_section, class: 'TypesDeChamp::HeaderSectionTypeDeChamp' do factory :type_de_champ_header_section, class: 'TypesDeChamp::HeaderSectionTypeDeChamp' do
type_champ 'header_section' type_champ TypeDeChamp.type_champs.fetch(:header_section)
end end
factory :type_de_champ_explication, class: 'TypesDeChamp::ExplicationTypeDeChamp' do factory :type_de_champ_explication, class: 'TypesDeChamp::ExplicationTypeDeChamp' do
type_champ 'explication' type_champ TypeDeChamp.type_champs.fetch(:explication)
end end
factory :type_de_champ_dossier_link, class: 'TypesDeChamp::DossierLinkTypeDeChamp' do factory :type_de_champ_dossier_link, class: 'TypesDeChamp::DossierLinkTypeDeChamp' do
libelle 'Référence autre dossier' libelle 'Référence autre dossier'
type_champ 'dossier_link' type_champ TypeDeChamp.type_champs.fetch(:dossier_link)
end end
factory :type_de_champ_piece_justificative, class: 'TypesDeChamp::PieceJustificativeTypeDeChamp' do factory :type_de_champ_piece_justificative, class: 'TypesDeChamp::PieceJustificativeTypeDeChamp' do
type_champ 'piece_justificative' type_champ TypeDeChamp.type_champs.fetch(:piece_justificative)
end end
factory :type_de_champ_siret, class: 'TypesDeChamp::SiretTypeDeChamp' do factory :type_de_champ_siret, class: 'TypesDeChamp::SiretTypeDeChamp' do
type_champ 'siret' type_champ TypeDeChamp.type_champs.fetch(:siret)
end end
trait :private do trait :private do

View file

@ -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 context 'user fill a new type de champ', js: true do
let(:libelle) { 'mon libelle' } let(:libelle) { 'mon libelle' }
let(:type_champ) { 'text' } let(:type_champ) { TypeDeChamp.type_champs.fetch(:text) }
let(:description) { 'ma super histoire' } let(:description) { 'ma super histoire' }
before do before do
page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set libelle 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 context 'user fill another one' do
let(:libelle) { 'coucou' } 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(:type_champ_label) { 'Zone de texte' }
let(:description) { 'to be or not to be' } let(:description) { 'to be or not to be' }
before do before do

View file

@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe TypeDeChampHelper, type: :helper do RSpec.describe TypeDeChampHelper, type: :helper do
describe ".tdc_options" 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 } subject { tdc_options }

View file

@ -160,8 +160,8 @@ describe TagsSubstitutionConcern, type: :model do
context 'when the procedure has 2 types de champ date and datetime' do context 'when the procedure has 2 types de champ date and datetime' do
let(:types_de_champ) do let(:types_de_champ) do
[ [
create(:type_de_champ_date, libelle: 'date'), create(:type_de_champ_date, libelle: TypeDeChamp.type_champs.fetch(:date)),
create(:type_de_champ_datetime, libelle: 'datetime') create(:type_de_champ_datetime, libelle: TypeDeChamp.type_champs.fetch(:datetime))
] ]
end end
@ -171,12 +171,12 @@ describe TagsSubstitutionConcern, type: :model do
context 'and its value in the dossier are not nil' do context 'and its value in the dossier are not nil' do
before do before do
dossier.champs dossier.champs
.select { |champ| champ.type_champ == 'date' } .select { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:date) }
.first .first
.update(value: '2017-04-15') .update(value: '2017-04-15')
dossier.champs dossier.champs
.select { |champ| champ.type_champ == 'datetime' } .select { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) }
.first .first
.update(value: '2017-09-13 09:00') .update(value: '2017-09-13 09:00')
end end

View file

@ -659,10 +659,10 @@ describe Procedure do
} }
before do before do
subject.types_de_champ[2].update_attribute(:type_champ, 'header_section') subject.types_de_champ[2].update_attribute(:type_champ,TypeDeChamp.type_champs.fetch(:header_section))
subject.types_de_champ[3].update_attribute(:type_champ, 'explication') subject.types_de_champ[3].update_attribute(:type_champ,TypeDeChamp.type_champs.fetch(:explication))
subject.types_de_champ_private[2].update_attribute(:type_champ, 'header_section') 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, 'explication') subject.types_de_champ_private[3].update_attribute(:type_champ,TypeDeChamp.type_champs.fetch(:explication))
end end
it { expect(subject.fields).to eq(expected) } it { expect(subject.fields).to eq(expected) }

View file

@ -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(nil).for(:type_champ) }
it { is_expected.not_to allow_value('').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(TypeDeChamp.type_champs.fetch(:text)).for(:type_champ) }
it { is_expected.to allow_value('textarea').for(:type_champ) } it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:textarea)).for(:type_champ) }
it { is_expected.to allow_value('datetime').for(:type_champ) } it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:datetime)).for(:type_champ) }
it { is_expected.to allow_value('number').for(:type_champ) } it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:number)).for(:type_champ) }
it { is_expected.to allow_value('checkbox').for(:type_champ) } it { is_expected.to allow_value(TypeDeChamp.type_champs.fetch(:checkbox)).for(:type_champ) }
it do it do
TypeDeChamp.type_champs.each do |(type_champ, _)| TypeDeChamp.type_champs.each do |(type_champ, _)|
@ -53,7 +53,7 @@ shared_examples 'type_de_champ_spec' do
end end
context 'when the target type_champ is not pj' do 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 context 'calls template.purge_later when a file is attached' do
let(:attached) { true } let(:attached) { true }
@ -69,7 +69,7 @@ shared_examples 'type_de_champ_spec' do
end end
context 'when the target type_champ is pj' do 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 context 'does not call template.purge_later when a file is attached' do
let(:attached) { true } let(:attached) { true }