diff --git a/Gemfile b/Gemfile index a278dcf11..04e55b3b9 100644 --- a/Gemfile +++ b/Gemfile @@ -35,9 +35,6 @@ gem 'active_link_to' # Pagination gem 'kaminari' -# Decorators -gem 'draper' - # Gestion des comptes utilisateurs gem 'devise' gem 'devise-async' diff --git a/Gemfile.lock b/Gemfile.lock index 51aa0b745..96db332ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,10 +58,6 @@ GEM globalid (>= 0.3.6) activemodel (5.2.2) activesupport (= 5.2.2) - activemodel-serializers-xml (1.0.2) - activemodel (> 5.x) - activesupport (> 5.x) - builder (~> 3.1) activerecord (5.2.2) activemodel (= 5.2.2) activesupport (= 5.2.2) @@ -194,12 +190,6 @@ GEM dotenv-rails (2.5.0) dotenv (= 2.5.0) railties (>= 3.2, < 6.0) - draper (3.0.1) - actionpack (~> 5.0) - activemodel (~> 5.0) - activemodel-serializers-xml (~> 1.0) - activesupport (~> 5.0) - request_store (~> 1.0) em-websocket (0.5.1) eventmachine (>= 0.12.9) http_parser.rb (~> 0.6.0) @@ -696,7 +686,6 @@ DEPENDENCIES devise devise-async dotenv-rails - draper factory_bot flipflop fog-openstack diff --git a/app/decorators/champ_decorator.rb b/app/decorators/champ_decorator.rb deleted file mode 100644 index ef50412f2..000000000 --- a/app/decorators/champ_decorator.rb +++ /dev/null @@ -1,21 +0,0 @@ -class ChampDecorator < Draper::Decorator - delegate_all - - def value - if type_champ == TypeDeChamp.type_champs.fetch(:date) && object.value.present? - Date.parse(object.value).strftime("%d/%m/%Y") - elsif type_champ.in? [TypeDeChamp.type_champs.fetch(:checkbox), TypeDeChamp.type_champs.fetch(:engagement)] - object.value == 'on' ? 'Oui' : 'Non' - elsif type_champ == TypeDeChamp.type_champs.fetch(:yes_no) - if object.value == 'true' - 'Oui' - elsif object.value == 'false' - 'Non' - end - elsif type_champ == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) && object.value.present? - JSON.parse(object.value).join(', ') - else - object.value - end - end -end diff --git a/app/decorators/dossier_decorator.rb b/app/decorators/dossier_decorator.rb deleted file mode 100644 index 4f283e3c5..000000000 --- a/app/decorators/dossier_decorator.rb +++ /dev/null @@ -1,12 +0,0 @@ -class DossierDecorator < Draper::Decorator - delegate :current_page, :limit_value, :total_pages - delegate_all - - def first_creation - created_at.strftime('%d/%m/%Y %H:%M') - end - - def last_update - updated_at.strftime('%d/%m/%Y %H:%M') - end -end diff --git a/app/decorators/dossiers_decorator.rb b/app/decorators/dossiers_decorator.rb deleted file mode 100644 index 98a24e2bd..000000000 --- a/app/decorators/dossiers_decorator.rb +++ /dev/null @@ -1,3 +0,0 @@ -class DossiersDecorator < Draper::CollectionDecorator - delegate :current_page, :limit_value, :total_pages -end diff --git a/app/decorators/france_connect_information_decorator.rb b/app/decorators/france_connect_information_decorator.rb deleted file mode 100644 index 503caee5b..000000000 --- a/app/decorators/france_connect_information_decorator.rb +++ /dev/null @@ -1,7 +0,0 @@ -class FranceConnectInformationDecorator < Draper::Decorator - delegate_all - - def gender_fr - gender == 'female' ? 'Mme' : 'M.' - end -end diff --git a/app/decorators/procedure_decorator.rb b/app/decorators/procedure_decorator.rb deleted file mode 100644 index e4933fbea..000000000 --- a/app/decorators/procedure_decorator.rb +++ /dev/null @@ -1,25 +0,0 @@ -class ProcedureDecorator < Draper::Decorator - delegate_all - - def created_at_fr - created_at.strftime('%d/%m/%Y %H:%M') - end - - def published_at_fr - if published_at.present? - published_at.strftime('%d/%m/%Y %H:%M') - end - end - - def logo_img - if logo.blank? - h.image_url("marianne.svg") - else - if Flipflop.remote_storage? - (RemoteDownloader.new logo.filename).url - else - (LocalDownloader.new logo.path, 'logo').url - end - end - end -end diff --git a/app/decorators/procedures_decorator.rb b/app/decorators/procedures_decorator.rb deleted file mode 100644 index c31731230..000000000 --- a/app/decorators/procedures_decorator.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ProceduresDecorator < Draper::CollectionDecorator - delegate :current_page, :limit_value, :total_pages -end diff --git a/app/decorators/type_de_champ_decorator.rb b/app/decorators/type_de_champ_decorator.rb deleted file mode 100644 index 8e3bc8118..000000000 --- a/app/decorators/type_de_champ_decorator.rb +++ /dev/null @@ -1,49 +0,0 @@ -class TypeDeChampDecorator < Draper::Decorator - delegate_all - - def button_up(params) - h.link_to '', params[:url], class: up_classes, - id: "btn_up_#{params[:index]}", - remote: true, - method: :post, - style: display_up_button?(params[:index], params[:private]) ? '' : 'visibility: hidden;' - end - - def button_down(params) - h.link_to '', params[:url], class: down_classes, - id: "btn_down_#{params[:index]}", - remote: true, - method: :post, - style: display_down_button?(params[:index], params[:private]) ? '' : 'visibility: hidden;' - end - - private - - def up_classes - base_classes << 'fa-chevron-up' - end - - def down_classes - base_classes << 'fa-chevron-down' - end - - def base_classes - ['btn', 'btn-default', 'form-control', 'fa'] - end - - def display_up_button?(index, private) - !(index == 0 || count_type_de_champ(private) < 2) - end - - def display_down_button?(index, private) - (index + 1) < count_type_de_champ(private) - end - - def count_type_de_champ(private) - if private - @count_type_de_champ ||= procedure.types_de_champ_private.count - else - @count_type_de_champ ||= procedure.types_de_champ.count - end - end -end diff --git a/app/decorators/type_de_piece_justificative_decorator.rb b/app/decorators/type_de_piece_justificative_decorator.rb deleted file mode 100644 index 906e61864..000000000 --- a/app/decorators/type_de_piece_justificative_decorator.rb +++ /dev/null @@ -1,40 +0,0 @@ -class TypeDePieceJustificativeDecorator < Draper::Decorator - delegate_all - def button_up(params) - if display_up_button?(params[:index]) - h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post - end - end - - def button_down(params) - if display_down_button?(params[:index]) - h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post - end - end - - private - - def up_classes - base_classes << 'fa-chevron-up' - end - - def down_classes - base_classes << 'fa-chevron-down' - end - - def base_classes - ['btn', 'btn-default', 'form-control', 'fa'] - end - - def display_up_button?(index) - !(index == 0 || count_type_de_piece_justificative < 2) - end - - def display_down_button?(index) - (index + 1) < count_type_de_piece_justificative - end - - def count_type_de_piece_justificative - @count_type_de_piece_justificative ||= procedure.types_de_piece_justificative.count - end -end diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb deleted file mode 100644 index 2ec79a39a..000000000 --- a/app/decorators/user_decorator.rb +++ /dev/null @@ -1,12 +0,0 @@ -class UserDecorator < Draper::Decorator - delegate_all - - def gender_fr - case gender - when 'male' - 'M.' - when 'female' - 'Mme' - end - end -end diff --git a/app/helpers/admin_formulaire_helper.rb b/app/helpers/admin_formulaire_helper.rb new file mode 100644 index 000000000..1b0dd9a53 --- /dev/null +++ b/app/helpers/admin_formulaire_helper.rb @@ -0,0 +1,55 @@ +module AdminFormulaireHelper + BASE_CLASSES = ['btn', 'btn-default', 'form-control', 'fa'] + + def button_up(procedure, kind, index, url) + if display_up_button?(index, procedure, kind) + button(up_classes, "btn_up_#{index}", url) + end + end + + def button_down(procedure, kind, index, url) + if display_down_button?(index, procedure, kind) + button(down_classes, "btn_down_#{index}", url) + end + end + + private + + def button(classes, id, url) + link_to( + '', + url, + class: classes, + id: id, + remote: true, + method: :post + ) + end + + def up_classes + BASE_CLASSES + ['fa-chevron-up'] + end + + def down_classes + BASE_CLASSES + ['fa-chevron-down'] + end + + def display_up_button?(index, procedure, kind) + index != 0 && count_type_de_champ(procedure, kind) > 1 + end + + def display_down_button?(index, procedure, kind) + (index + 1) < count_type_de_champ(procedure, kind) + end + + def count_type_de_champ(procedure, kind) + case kind + when "public" + @count_type_de_champ_public ||= procedure.types_de_champ.count + when "private" + @count_type_de_champ_private ||= procedure.types_de_champ_private.count + when "piece_justificative" + @count_type_de_piece_justificative ||= procedure.types_de_piece_justificative.count + end + end +end diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index 573a8defe..693eb8bc3 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -9,4 +9,25 @@ module ChampHelper raw(champ.to_render_data.to_json) # rubocop:enable Rails/OutputSafety end + + def formatted_value(champ) + value = champ.value + type = champ.type_champ + + if type == TypeDeChamp.type_champs.fetch(:date) && value.present? + Date.parse(value).strftime("%d/%m/%Y") + elsif type.in? [TypeDeChamp.type_champs.fetch(:checkbox), TypeDeChamp.type_champs.fetch(:engagement)] + value == 'on' ? 'Oui' : 'Non' + elsif type == TypeDeChamp.type_champs.fetch(:yes_no) + if value == 'true' + 'Oui' + elsif value == 'false' + 'Non' + end + elsif type == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) && value.present? + JSON.parse(value).join(', ') + else + value + end + end end diff --git a/app/helpers/procedure_helper.rb b/app/helpers/procedure_helper.rb index 4305b05e5..62ff0f9ee 100644 --- a/app/helpers/procedure_helper.rb +++ b/app/helpers/procedure_helper.rb @@ -19,4 +19,18 @@ module ProcedureHelper action = procedure.archivee? ? :reopen : :publish t(action, scope: [:modal, :publish, key]) end + + def logo_img(procedure) + logo = procedure.logo + + if logo.blank? + ActionController::Base.helpers.image_url("marianne.svg") + else + if Flipflop.remote_storage? + RemoteDownloader.new(logo.filename).url + else + LocalDownloader.new(logo.path, 'logo').url + end + end + end end diff --git a/app/models/drop_down_list.rb b/app/models/drop_down_list.rb index b9b4e9a20..5c3f2757c 100644 --- a/app/models/drop_down_list.rb +++ b/app/models/drop_down_list.rb @@ -10,10 +10,6 @@ class DropDownList < ApplicationRecord options.select { |v| (v =~ /^--.*--$/).present? } end - def selected_options(champ) - champ.object.value.blank? ? [] : multiple ? JSON.parse(champ.object.value) : [champ.object.value] - end - def selected_options_without_decorator(champ) champ.value.blank? ? [] : multiple ? JSON.parse(champ.value) : [champ.value] end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index d1458181f..0205654a6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -176,6 +176,7 @@ class Procedure < ApplicationRecord else list[index_of_first_element].update(order_place: index_of_first_element + 1) list[index_of_first_element + 1].update(order_place: index_of_first_element) + reload true end diff --git a/app/services/types_de_champ_service.rb b/app/services/types_de_champ_service.rb index afc531349..288e30f59 100644 --- a/app/services/types_de_champ_service.rb +++ b/app/services/types_de_champ_service.rb @@ -36,11 +36,11 @@ class TypesDeChampService end def types_de_champ - private? ? @procedure.types_de_champ_private.decorate : @procedure.types_de_champ.decorate + private? ? @procedure.types_de_champ_private : @procedure.types_de_champ end def new_type_de_champ - TypeDeChamp.new(private: private?).decorate + TypeDeChamp.new(private: private?) end def fields_for_var diff --git a/app/views/admin/pieces_justificatives/_fields.html.haml b/app/views/admin/pieces_justificatives/_fields.html.haml index 27294bbf2..8343e84af 100644 --- a/app/views/admin/pieces_justificatives/_fields.html.haml +++ b/app/views/admin/pieces_justificatives/_fields.html.haml @@ -20,8 +20,8 @@ - if ff.object.id.present? .form-group %br   - = ff.object.button_up(index: ff.index, url: move_up_admin_procedure_pieces_justificatives_path(@procedure, ff.index)) - = ff.object.button_down(index: ff.index, url: move_down_admin_procedure_pieces_justificatives_path(@procedure, ff.index)) + = button_up(@procedure, "piece_justificative", ff.index, move_up_admin_procedure_pieces_justificatives_path(@procedure, ff.index)) + = button_down(@procedure, "piece_justificative", ff.index, move_down_admin_procedure_pieces_justificatives_path(@procedure, ff.index)) .form-group %h4 Obligatoire ? diff --git a/app/views/admin/pieces_justificatives/_form.html.haml b/app/views/admin/pieces_justificatives/_form.html.haml index 2499b7cad..e48f4077d 100644 --- a/app/views/admin/pieces_justificatives/_form.html.haml +++ b/app/views/admin/pieces_justificatives/_form.html.haml @@ -1,7 +1,7 @@ = form_for [:admin, @procedure], url: admin_procedure_pieces_justificatives_path(@procedure), remote: true do |f| #liste_piece_justificative - = render partial: 'fields', locals: { types_de_piece_justificative: @procedure.types_de_piece_justificative.decorate, f: f } + = render partial: 'fields', locals: { types_de_piece_justificative: @procedure.types_de_piece_justificative, f: f } = f.submit "Enregistrer", class: 'btn btn-success', id: :save %hr #new_type_de_piece_justificative - = render partial: 'fields', locals: { types_de_piece_justificative: TypeDePieceJustificative.new.decorate, f: f } + = render partial: 'fields', locals: { types_de_piece_justificative: TypeDePieceJustificative.new, f: f } diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index bad8e62ed..460f04211 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -101,7 +101,7 @@ .col-md-6 %h4 Logo de la démarche - if @procedure.logo.present? - = image_tag @procedure.decorate.logo_img, { style: 'height: 40px; display: inline; margin-right: 6px;', id: 'preview_procedure_logo' } + = image_tag logo_img(@procedure), { style: 'height: 40px; display: inline; margin-right: 6px;', id: 'preview_procedure_logo' } \- - if @procedure.persisted? diff --git a/app/views/admin/procedures/_list.html.haml b/app/views/admin/procedures/_list.html.haml index d1691b639..8fcb04aee 100644 --- a/app/views/admin/procedures/_list.html.haml +++ b/app/views/admin/procedures/_list.html.haml @@ -12,7 +12,7 @@ %th Actions - @procedures.each do |procedure| - - procedure = procedure.decorate + - procedure = procedure - admin_procedure_href = admin_procedure_path(procedure) %tr{ id: "tr_dossier_#{procedure.id}", data: { href: admin_procedure_href } } %td= link_to(procedure.id, admin_procedure_href) @@ -20,9 +20,9 @@ - if procedure.publiee? %td.procedure-lien= link_to(procedure_lien(procedure), procedure_lien(procedure)) - if procedure.publiee_ou_archivee? - %td= link_to(procedure.published_at_fr, admin_procedure_href) + %td= link_to(procedure.published_at.present? ? procedure.published_at.strftime('%d/%m/%Y %H:%M') : "", admin_procedure_href) - else - %td= link_to(procedure.created_at_fr, admin_procedure_href) + %td= link_to(procedure.created_at.strftime('%d/%m/%Y %H:%M'), admin_procedure_href) %td = link_to('Cloner', admin_procedure_clone_path(procedure.id), data: { method: :put }, class: 'btn-sm btn-primary clone-btn') - if !procedure.publiee_ou_archivee? diff --git a/app/views/admin/types_de_champ/_fields.html.haml b/app/views/admin/types_de_champ/_fields.html.haml index 9acfa02a2..8d6ca418a 100644 --- a/app/views/admin/types_de_champ/_fields.html.haml +++ b/app/views/admin/types_de_champ/_fields.html.haml @@ -1,5 +1,5 @@ = f.fields_for type_de_champ_service.fields_for_var, types_de_champ, remote: true do |ff| - - type_champ = ff.object.object.type_champ + - type_champ = ff.object.type_champ .form-inline{ class: (type_champ == TypeDeChamp.type_champs.fetch(:header_section) ? 'header-section' : nil) } .form-group.libelle @@ -16,14 +16,14 @@ .form-group.drop-down-list{ class: (%w(drop_down_list multiple_drop_down_list linked_drop_down_list).include?(type_champ) ? 'show-inline' : nil), style: 'margin-right: 5px;' } %h4 Liste déroulante - = ff.fields_for :drop_down_list_attributes, ff.object.object.drop_down_list do |fff| + = ff.fields_for :drop_down_list_attributes, ff.object.drop_down_list do |fff| ~ 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 == TypeDeChamp.type_champs.fetch(:piece_justificative)) ? 'show-inline' : nil } %h4 Modèle - if type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) - - template = ff.object.object.piece_justificative_template + - template = ff.object.piece_justificative_template - if !template.attached? = ff.file_field :piece_justificative_template, @@ -52,7 +52,7 @@ = ff.check_box :parcelles_agricoles Parcelles Agricoles - - hide_mandatory = (ff.object.object.private? || type_champ == TypeDeChamp.type_champs.fetch(:explication)) + - hide_mandatory = (ff.object.private? || type_champ == TypeDeChamp.type_champs.fetch(:explication)) .form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil } %h4 Obligatoire ? .center @@ -65,8 +65,9 @@ - if ff.object.id.present? .form-group %br   - = ff.object.button_up(index: ff.index, url: type_de_champ_service.move_up_url(ff), private: type_de_champ_service.private?) - = ff.object.button_down(index: ff.index, url: type_de_champ_service.move_down_url(ff), private: type_de_champ_service.private?) + - kind = type_de_champ_service.private? ? "private" : "public" + = button_up(@procedure, kind, ff.index, type_de_champ_service.move_up_url(ff)) + = button_down(@procedure, kind, ff.index, type_de_champ_service.move_down_url(ff)) .form-group %h4 position diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml index 560f960b9..25dd50bed 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml @@ -1,7 +1,7 @@ #first-block .en-cours - if @procedure.logo.present? - = image_tag @procedure.decorate.logo_img, style: 'width: 30px;' + = image_tag logo_img(@procedure), style: 'width: 30px;' %b = @procedure.libelle diff --git a/app/views/new_gestionnaire/dossiers/print.html.haml b/app/views/new_gestionnaire/dossiers/print.html.haml index 052b569c3..b35489857 100644 --- a/app/views/new_gestionnaire/dossiers/print.html.haml +++ b/app/views/new_gestionnaire/dossiers/print.html.haml @@ -13,7 +13,7 @@ %h2 Formulaire -- champs = @dossier.champs.decorate +- champs = @dossier.champs - if champs.any? = render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' } diff --git a/app/views/new_user/dossiers/_demarche_overview.html.haml b/app/views/new_user/dossiers/_demarche_overview.html.haml index e0a451247..548bdf757 100644 --- a/app/views/new_user/dossiers/_demarche_overview.html.haml +++ b/app/views/new_user/dossiers/_demarche_overview.html.haml @@ -1,5 +1,5 @@ .procedure-logos - = image_tag procedure.decorate.logo_img + = image_tag logo_img(procedure) - if procedure.euro_flag = image_tag "flag_of_europe.svg" diff --git a/app/views/shared/dossiers/_champs.html.haml b/app/views/shared/dossiers/_champs.html.haml index 928efe27c..bab7a4e51 100644 --- a/app/views/shared/dossiers/_champs.html.haml +++ b/app/views/shared/dossiers/_champs.html.haml @@ -2,6 +2,7 @@ %tbody - champs.reject(&:exclude_from_view?).each do |c| %tr + - value = formatted_value(c) - case c.type_champ - when TypeDeChamp.type_champs.fetch(:header_section) %th.header-section{ colspan: 3 } @@ -10,9 +11,9 @@ %th.libelle = "#{c.libelle} :" %td.rich-text - - if c.value.present? + - if value.present? %ul - - c.value.split(", ").each do |item| + - value.split(", ").each do |item| %li = item - when TypeDeChamp.type_champs.fetch(:linked_drop_down_list) @@ -23,7 +24,7 @@ %th.libelle = "#{c.libelle} :" %td.rich-text - - dossier = Dossier.includes(:procedure).find_by(id: c.value) + - dossier = Dossier.includes(:procedure).find_by(id: value) - if dossier - path = dossier_linked_path(current_gestionnaire, dossier) - if path.present? @@ -48,7 +49,7 @@ = "#{c.libelle} :" %td.rich-text %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } - = simple_format(c.value) + = simple_format(value) - when TypeDeChamp.type_champs.fetch(:siret) %th.libelle = "#{c.libelle} :" @@ -61,14 +62,14 @@ = "#{c.libelle} :" %td.rich-text %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } - - if c.value.present? + - if value.present? = render partial: "shared/champs/carte/show", locals: { champ: c } - else %th.libelle = "#{c.libelle} :" %td.rich-text %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } - = sanitize(c.value) + = sanitize(value) - 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) } diff --git a/app/views/shared/dossiers/_demande.html.haml b/app/views/shared/dossiers/_demande.html.haml index 140c5c27b..3d9ba3de8 100644 --- a/app/views/shared/dossiers/_demande.html.haml +++ b/app/views/shared/dossiers/_demande.html.haml @@ -10,7 +10,7 @@ = render partial: "shared/dossiers/identite_individual", locals: { individual: dossier.individual } .tab-title Formulaire - - champs = dossier.champs.includes(:type_de_champ).decorate + - champs = dossier.champs.includes(:type_de_champ) - if champs.any? .card = render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at, profile: profile } diff --git a/app/views/users/sessions/_resume_procedure.html.haml b/app/views/users/sessions/_resume_procedure.html.haml index 9df51d63b..895730eef 100644 --- a/app/views/users/sessions/_resume_procedure.html.haml +++ b/app/views/users/sessions/_resume_procedure.html.haml @@ -8,7 +8,7 @@ = image_tag('drapeau_europe.png') #logo_procedure.flag - = image_tag( @dossier.procedure.decorate.logo_img ) + = image_tag(logo_img(dossier.procedure)) %h2#titre-procedure.text-info = @dossier.procedure.libelle diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index d231b6ac9..f58a19f6c 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -13,7 +13,7 @@ .text-right = link_to "Fermer", users_no_procedure_url, class: "link close-procedure" .procedure-logos - = image_tag @dossier.procedure.decorate.logo_img + = image_tag logo_img(@dossier.procedure) - if @dossier.procedure.euro_flag = image_tag "flag_of_europe.svg" diff --git a/spec/decorators/dossier_decorator_spec.rb b/spec/decorators/dossier_decorator_spec.rb deleted file mode 100644 index 3c8f4fe96..000000000 --- a/spec/decorators/dossier_decorator_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe DossierDecorator do - let(:dossier) do - dossier = create(:dossier, created_at: Time.zone.local(2015, 12, 24, 14, 10)) - dossier.update_column('updated_at', Time.zone.local(2015, 12, 24, 14, 10)) - dossier - end - - subject { dossier.decorate } - - describe 'first_creation' do - subject { super().first_creation } - it { is_expected.to eq('24/12/2015 14:10') } - end - - describe 'last_update' do - subject { super().last_update } - it { is_expected.to eq('24/12/2015 14:10') } - end -end diff --git a/spec/decorators/france_connect_inforation_decorator_spec.rb b/spec/decorators/france_connect_inforation_decorator_spec.rb deleted file mode 100644 index d6d642fc3..000000000 --- a/spec/decorators/france_connect_inforation_decorator_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe FranceConnectInformationDecorator do - let(:gender) { 'female' } - let(:france_connect_information) { create :france_connect_information, gender: gender } - - subject { france_connect_information.decorate.gender_fr } - - context 'when france connect user is a male' do - let(:gender) { 'male' } - it { is_expected.to eq 'M.' } - end - - context 'when france connect user is a female' do - it { is_expected.to eq 'Mme' } - end -end diff --git a/spec/decorators/procedure_decorator_spec.rb b/spec/decorators/procedure_decorator_spec.rb deleted file mode 100644 index 2c7972076..000000000 --- a/spec/decorators/procedure_decorator_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'spec_helper' - -describe ProcedureDecorator do - let(:published_at) { Time.zone.local(2017, 12, 24, 14, 12) } - let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.zone.local(2015, 12, 24, 14, 10)) } - - subject { procedure.decorate } - - describe 'created_at_fr' do - subject { super().created_at_fr } - it { is_expected.to eq('24/12/2015 14:10') } - end - - describe 'published_at_fr' do - subject { super().published_at_fr } - it { is_expected.to eq('24/12/2017 14:12') } - - context 'published_at is nil' do - let(:published_at) { nil } - it { is_expected.to eq(nil) } - end - end - - describe 'logo_img' do - subject { super().logo_img } - it { is_expected.to match(/http.*#{ActionController::Base.helpers.image_url("marianne.svg")}/) } - end -end diff --git a/spec/decorators/procedures_decorator_spec.rb b/spec/decorators/procedures_decorator_spec.rb deleted file mode 100644 index 92f63c91e..000000000 --- a/spec/decorators/procedures_decorator_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'spec_helper' - -describe ProceduresDecorator do - before do - create(:procedure, :published, created_at: Time.zone.local(2015, 12, 24, 14, 10)) - create(:procedure, :published, created_at: Time.zone.local(2015, 12, 24, 14, 10)) - create(:procedure, :published, created_at: Time.zone.local(2015, 12, 24, 14, 10)) - end - - let(:procedure) { Procedure.all.page(1) } - - subject { procedure.decorate } - - it { expect(subject.current_page).not_to be_nil } - it { expect(subject.limit_value).not_to be_nil } - it { expect(subject.count).to eq(3) } - it { expect(subject.total_pages).not_to be_nil } -end diff --git a/spec/decorators/type_de_champ_decorator_spec.rb b/spec/decorators/type_de_champ_decorator_spec.rb deleted file mode 100644 index 7a490aefc..000000000 --- a/spec/decorators/type_de_champ_decorator_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'spec_helper' - -describe TypeDeChampDecorator do - let(:procedure) { create(:procedure) } - let(:url) { 'http://localhost' } - let(:params) { { url: url, index: index } } - let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } - let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } - let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } - - describe '#button_up' do - describe 'with first piece justificative' do - let(:index) { 0 } - subject { type_de_champ_0.decorate } - let(:button_up) { type_de_champ_.decorate } - - it 'hide a button up' do - expect(subject.button_up(params)).to include('visibility: hidden') - end - it 'returns a button down' do - expect(subject.button_down(params)).to match(/fa-chevron-down/) - end - end - - describe 'with second out of three piece justificative' do - let(:index) { 1 } - subject { type_de_champ_1.decorate } - let(:button_up) { type_de_champ_1.decorate } - - it 'returns a button up' do - expect(subject.button_up(params)).to match(/fa-chevron-up/) - end - it 'returns a button down' do - expect(subject.button_down(params)).to match(/fa-chevron-down/) - end - end - - describe 'with last piece justificative' do - let(:index) { 2 } - subject { type_de_champ_2.decorate } - let(:button_up) { type_de_champ_1.decorate } - - it 'returns a button up' do - expect(subject.button_up(params)).to match(/fa-chevron-up/) - end - - it 'hide a button down' do - expect(subject.button_down(params)).to include('visibility: hidden') - end - end - end -end diff --git a/spec/decorators/type_de_piece_justificative_decorator_spec.rb b/spec/helpers/admin_formulaire_helper.rb similarity index 51% rename from spec/decorators/type_de_piece_justificative_decorator_spec.rb rename to spec/helpers/admin_formulaire_helper.rb index 5503b68a0..7f0804497 100644 --- a/spec/decorators/type_de_piece_justificative_decorator_spec.rb +++ b/spec/helpers/admin_formulaire_helper.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require 'rails_helper' -describe TypeDePieceJustificativeDecorator do +RSpec.describe AdminFormulaireHelper, type: :helper do let(:procedure) { create(:procedure) } + let(:kind) { 'piece_justificative' } let(:url) { 'http://localhost' } - let(:params) { { url: url, index: index } } let!(:type_de_piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) } let!(:type_de_piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) } let!(:type_de_piece_justificative_2) { create(:type_de_piece_justificative, procedure: procedure, order_place: 2) } @@ -11,40 +11,51 @@ describe TypeDePieceJustificativeDecorator do describe '#button_up' do describe 'with first piece justificative' do let(:index) { 0 } - subject { type_de_piece_justificative_0.decorate } - let(:button_up) { type_de_piece_justificative_.decorate } it 'returns a button up' do - expect(subject.button_up(params)).to be(nil) - end - it 'returns a button down' do - expect(subject.button_down(params)).to match(/fa-chevron-down/) + expect(button_up(procedure, kind, index, url)).to be(nil) end end describe 'with second out of three piece justificative' do let(:index) { 1 } - subject { type_de_piece_justificative_1.decorate } - let(:button_up) { type_de_piece_justificative_1.decorate } it 'returns a button up' do - expect(subject.button_up(params)).to match(/fa-chevron-up/) - end - it 'returns a button down' do - expect(subject.button_down(params)).to match(/fa-chevron-down/) + expect(button_up(procedure, kind, index, url)).to match(/fa-chevron-up/) end end describe 'with last piece justificative' do let(:index) { 2 } - subject { type_de_piece_justificative_2.decorate } - let(:button_up) { type_de_piece_justificative_1.decorate } it 'returns a button up' do - expect(subject.button_up(params)).to match(/fa-chevron-up/) + expect(button_up(procedure, kind, index, url)).to match(/fa-chevron-up/) end + end + end + + describe '#button_down' do + describe 'with first piece justificative' do + let(:index) { 0 } + it 'returns a button down' do - expect(subject.button_down(params)).to be(nil) + expect(button_down(procedure, kind, index, url)).to match(/fa-chevron-down/) + end + end + + describe 'with second out of three piece justificative' do + let(:index) { 1 } + + it 'returns a button down' do + expect(button_down(procedure, kind, index, url)).to match(/fa-chevron-down/) + end + end + + describe 'with last piece justificative' do + let(:index) { 2 } + + it 'returns nil' do + expect(button_down(procedure, kind, index, url)).to be(nil) end end end diff --git a/spec/decorators/champ_decorator_spec.rb b/spec/helpers/champ_helper_spec.rb similarity index 91% rename from spec/decorators/champ_decorator_spec.rb rename to spec/helpers/champ_helper_spec.rb index 9d9fde006..9f61990f9 100644 --- a/spec/decorators/champ_decorator_spec.rb +++ b/spec/helpers/champ_helper_spec.rb @@ -1,12 +1,11 @@ -require 'spec_helper' +require 'rails_helper' -describe ChampDecorator do +RSpec.describe ChampHelper, type: :helper do let(:type_de_champ) { create(:type_de_champ) } let(:champ) { type_de_champ.champ.create } - let(:decorator) { champ.decorate } - describe 'value' do - subject { decorator.value } + describe '.formatted_value' do + subject { formatted_value(champ) } describe 'for a checkbox' do let(:type_de_champ) { create(:type_de_champ_checkbox) } diff --git a/spec/helpers/procedure_helper_spec.rb b/spec/helpers/procedure_helper_spec.rb new file mode 100644 index 000000000..838e05e1f --- /dev/null +++ b/spec/helpers/procedure_helper_spec.rb @@ -0,0 +1,9 @@ +RSpec.describe ProcedureHelper, type: :helper do + let(:procedure) { create(:procedure) } + + describe ".logo_img" do + subject { logo_img(procedure) } + + it { is_expected.to match(/#{ActionController::Base.helpers.image_url("marianne.svg")}/) } + end +end diff --git a/spec/models/drop_down_list_spec.rb b/spec/models/drop_down_list_spec.rb index e4ce2adf2..7af28b927 100644 --- a/spec/models/drop_down_list_spec.rb +++ b/spec/models/drop_down_list_spec.rb @@ -40,24 +40,4 @@ describe DropDownList do it { expect(dropdownlist.disabled_options).to match(['--top--', '--troupt--']) } end - - describe 'selected_options' do - let(:dropdownlist) do - create(:drop_down_list, type_de_champ: type_de_champ) - end - - context 'when multiple' do - let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list) } - let(:champ) { type_de_champ.champ.build(value: '["1","2"]').decorate } - - it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) } - end - - context 'when simple' do - let(:type_de_champ) { build(:type_de_champ_drop_down_list) } - let(:champ) { type_de_champ.champ.build(value: '1').decorate } - - it { expect(dropdownlist.selected_options(champ)).to match(['1']) } - end - end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 355aa27e7..bc3b90b39 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -264,26 +264,32 @@ describe Procedure do describe '#switch_types_de_champ' do let(:procedure) { create(:procedure) } let(:index) { 0 } - subject { procedure.switch_types_de_champ index } + subject { procedure.switch_types_de_champ(index) } - context 'when procedure have no types_de_champ' do + context 'when procedure has no types_de_champ' do it { expect(subject).to eq(false) } end - context 'when procedure have 2 types de champ' do + context 'when procedure has 3 types de champ' do let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } + let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } context 'when index is not the last element' do it { expect(subject).to eq(true) } - it 'switch order place' do - procedure.switch_types_de_champ index - type_de_champ_0.reload - type_de_champ_1.reload - expect(type_de_champ_0.order_place).to eq(1) - expect(type_de_champ_1.order_place).to eq(0) + it 'switches the position of the champ N and N+1' do + subject + expect(procedure.types_de_champ[0]).to eq(type_de_champ_1) + expect(procedure.types_de_champ[0].order_place).to eq(0) + expect(procedure.types_de_champ[1]).to eq(type_de_champ_0) + expect(procedure.types_de_champ[1].order_place).to eq(1) + end + it 'doesn’t move other types de champ' do + subject + expect(procedure.types_de_champ[2]).to eq(type_de_champ_2) + expect(procedure.types_de_champ[2].order_place).to eq(2) end end context 'when index is the last element' do - let(:index) { 1 } + let(:index) { 2 } it { expect(subject).to eq(false) } end end diff --git a/spec/views/admin/types_de_champ/show.html.haml_spec.rb b/spec/views/admin/types_de_champ/show.html.haml_spec.rb index 9cb1e32c9..ad15d570f 100644 --- a/spec/views/admin/types_de_champ/show.html.haml_spec.rb +++ b/spec/views/admin/types_de_champ/show.html.haml_spec.rb @@ -36,18 +36,18 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do end context 'when there is only one field in database' do let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } - it { expect(subject).to have_css('#btn_down_0[style*="visibility: hidden"]') } - it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } + it { expect(subject).not_to have_css('#btn_down_0') } + it { expect(subject).not_to have_css('#btn_up_0') } it { expect(subject).not_to have_css('#btn_up_1') } it { expect(subject).not_to have_css('#btn_down_1') } end context 'when there are 2 fields in database' do let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } + it { expect(subject).not_to have_css('#btn_up_0') } it { expect(subject).to have_css('#btn_down_0') } - it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).to have_css('#btn_up_1') } - it { expect(subject).to have_css('#btn_down_1[style*="visibility: hidden"]') } + it { expect(subject).not_to have_css('#btn_down_1') } end end end diff --git a/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb b/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb index 074cd31b7..8f80aa9c6 100644 --- a/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb +++ b/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb @@ -44,8 +44,8 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do end context 'when there is only one field in database' do let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } - it { expect(subject).to have_css('#btn_down_0[style*="visibility: hidden"]') } - it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } + it { expect(subject).not_to have_css('#btn_down_0') } + it { expect(subject).not_to have_css('#btn_up_0') } it { expect(subject).not_to have_css('#btn_up_1') } it { expect(subject).not_to have_css('#btn_down_1') } end @@ -53,9 +53,9 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do let!(:type_de_champ_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) } it { expect(subject).to have_css('#btn_down_0') } - it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } + it { expect(subject).not_to have_css('#btn_up_0') } it { expect(subject).to have_css('#btn_up_1') } - it { expect(subject).to have_css('#btn_down_1[style*="visibility: hidden"]') } + it { expect(subject).not_to have_css('#btn_down_1') } end end end