From dcf56616c3b42a0f15418ed730954c65b97277c5 Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Tue, 29 Oct 2024 15:39:58 +0100 Subject: [PATCH] rename ProcedureLabel by Label part 2 --- .../labels_component.html.haml | 6 +-- ...els_controller.rb => labels_controller.rb} | 24 ++++++------ app/helpers/dossier_helper.rb | 2 +- app/models/label.rb | 2 +- .../_form.html.haml | 6 +-- .../edit.html.haml | 4 +- .../index.html.haml | 4 +- .../new.html.haml | 4 +- .../models/{procedure_label => label}/fr.yml | 4 +- config/routes.rb | 2 +- ...ller_spec.rb => labels_controller_spec.rb} | 38 +++++++++---------- .../{procedure_label.rb => label.rb} | 2 +- 12 files changed, 49 insertions(+), 49 deletions(-) rename app/controllers/administrateurs/{procedure_labels_controller.rb => labels_controller.rb} (57%) rename app/views/administrateurs/{procedure_labels => labels}/_form.html.haml (78%) rename app/views/administrateurs/{procedure_labels => labels}/edit.html.haml (90%) rename app/views/administrateurs/{procedure_labels => labels}/index.html.haml (93%) rename app/views/administrateurs/{procedure_labels => labels}/new.html.haml (90%) rename config/locales/models/{procedure_label => label}/fr.yml (87%) rename spec/controllers/administrateurs/{procedure_labels_controller_spec.rb => labels_controller_spec.rb} (73%) rename spec/factories/{procedure_label.rb => label.rb} (82%) diff --git a/app/components/procedure/card/labels_component/labels_component.html.haml b/app/components/procedure/card/labels_component/labels_component.html.haml index 78a7cb033..d18982afe 100644 --- a/app/components/procedure/card/labels_component/labels_component.html.haml +++ b/app/components/procedure/card/labels_component/labels_component.html.haml @@ -1,12 +1,12 @@ .fr-col-6.fr-col-md-4.fr-col-lg-3 - = link_to [:admin, @procedure, :procedure_labels], class: 'fr-tile fr-enlarge-link' do + = link_to [:admin, @procedure, :labels], class: 'fr-tile fr-enlarge-link' do .fr-tile__body.flex.column.align-center.justify-between - - if @procedure.procedure_labels.present? + - if @procedure.labels.present? %p.fr-badge.fr-badge--info Configuré %div .line-count.fr-my-1w - %p.fr-tag= @procedure.procedure_labels.size + %p.fr-tag= @procedure.labels.size - else %p.fr-badge Non configuré diff --git a/app/controllers/administrateurs/procedure_labels_controller.rb b/app/controllers/administrateurs/labels_controller.rb similarity index 57% rename from app/controllers/administrateurs/procedure_labels_controller.rb rename to app/controllers/administrateurs/labels_controller.rb index b20ddad6c..e5b987bc8 100644 --- a/app/controllers/administrateurs/procedure_labels_controller.rb +++ b/app/controllers/administrateurs/labels_controller.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true module Administrateurs - class ProcedureLabelsController < AdministrateurController + class LabelsController < AdministrateurController before_action :retrieve_procedure before_action :retrieve_label, only: [:edit, :update, :destroy] before_action :set_colors_collection, only: [:edit, :new, :create, :update] def index - @labels = @procedure.procedure_labels + @labels = @procedure.labels end def edit end def new - @label = ProcedureLabel.new + @label = Label.new end def create - @label = @procedure.procedure_labels.build(procedure_label_params) + @label = @procedure.labels.build(label_params) if @label.save flash.notice = 'Le label a bien été créé' - redirect_to [:admin, @procedure, :procedure_labels] + redirect_to [:admin, @procedure, :labels] else flash.alert = @label.errors.full_messages render :new @@ -30,9 +30,9 @@ module Administrateurs end def update - if @label.update(procedure_label_params) + if @label.update(label_params) flash.notice = 'Le label a bien été modifié' - redirect_to [:admin, @procedure, :procedure_labels] + redirect_to [:admin, @procedure, :labels] else flash.alert = @label.errors.full_messages render :edit @@ -42,21 +42,21 @@ module Administrateurs def destroy @label.destroy! flash.notice = 'Le label a bien été supprimé' - redirect_to [:admin, @procedure, :procedure_labels] + redirect_to [:admin, @procedure, :labels] end private - def procedure_label_params - params.require(:procedure_label).permit(:name, :color) + def label_params + params.require(:label).permit(:name, :color) end def retrieve_label - @label = @procedure.procedure_labels.find(params[:id]) + @label = @procedure.labels.find(params[:id]) end def set_colors_collection - @colors_collection = ProcedureLabel.colors.keys + @colors_collection = Label.colors.keys end end end diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb index 05d64e6f9..ab60b1222 100644 --- a/app/helpers/dossier_helper.rb +++ b/app/helpers/dossier_helper.rb @@ -130,7 +130,7 @@ module DossierHelper end def tag_label(name, color) - tag.span(name, class: "fr-tag fr-tag--sm fr-tag--#{ProcedureLabel.class_name(color)}") + tag.span(name, class: "fr-tag fr-tag--sm fr-tag--#{Label.class_name(color)}") end def demandeur_dossier(dossier) diff --git a/app/models/label.rb b/app/models/label.rb index ceaef10d1..aaeeebf0d 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -30,6 +30,6 @@ class Label < ApplicationRecord validates :name, length: { maximum: NAME_MAX_LENGTH } def self.class_name(color) - ProcedureLabel.colors.fetch(color.underscore) + Label.colors.fetch(color.underscore) end end diff --git a/app/views/administrateurs/procedure_labels/_form.html.haml b/app/views/administrateurs/labels/_form.html.haml similarity index 78% rename from app/views/administrateurs/procedure_labels/_form.html.haml rename to app/views/administrateurs/labels/_form.html.haml index bb8983f39..6742b1d35 100644 --- a/app/views/administrateurs/procedure_labels/_form.html.haml +++ b/app/views/administrateurs/labels/_form.html.haml @@ -1,15 +1,15 @@ = form_with model: label, url: [:admin, @procedure, @label], local: true do |f| - = render Dsfr::InputComponent.new(form: f, attribute: :name, input_type: :text_field, opts: { maxlength: ProcedureLabel::NAME_MAX_LENGTH}) + = render Dsfr::InputComponent.new(form: f, attribute: :name, input_type: :text_field, opts: { maxlength: Label::NAME_MAX_LENGTH}) %fieldset.fr-fieldset %legend.fr-fieldset__legend.fr-fieldset__legend--regular - = t('activerecord.attributes.procedure_label.color') + = t('activerecord.attributes.label.color') = asterisk - @colors_collection.each do |color| .fr-fieldset__element.fr-fieldset__element--inline .fr-radio-group = f.radio_button :color, color, checked: (label.color == color) - = f.label :color, t("activerecord.attributes.label/color.#{color}"), value: color, class: "fr-label fr-tag fr-tag--sm fr-tag--#{ProcedureLabel.class_name(color)}" + = f.label :color, t("activerecord.attributes.label/color.#{color}"), value: color, class: "fr-label fr-tag fr-tag--sm fr-tag--#{Label.class_name(color)}" = render Procedure::FixedFooterComponent.new(procedure: @procedure, form: f) diff --git a/app/views/administrateurs/procedure_labels/edit.html.haml b/app/views/administrateurs/labels/edit.html.haml similarity index 90% rename from app/views/administrateurs/procedure_labels/edit.html.haml rename to app/views/administrateurs/labels/edit.html.haml index 695ba74a0..8f3784ca4 100644 --- a/app/views/administrateurs/procedure_labels/edit.html.haml +++ b/app/views/administrateurs/labels/edit.html.haml @@ -3,14 +3,14 @@ = render partial: 'administrateurs/breadcrumbs', locals: { steps: [['Démarches', admin_procedures_path], [@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)], - ['gestion des labels', [:admin, @procedure, :procedure_labels]], + ['gestion des labels', [:admin, @procedure, :labels]], ['Modifier le label']] } .fr-container .fr-mb-3w = link_to "Liste de tous les labels", - [:admin, @procedure, :procedure_labels], + [:admin, @procedure, :labels], class: "fr-link fr-icon-arrow-left-line fr-link--icon-left" %h1.fr-h2 diff --git a/app/views/administrateurs/procedure_labels/index.html.haml b/app/views/administrateurs/labels/index.html.haml similarity index 93% rename from app/views/administrateurs/procedure_labels/index.html.haml rename to app/views/administrateurs/labels/index.html.haml index 7a124da3c..f0dc512f5 100644 --- a/app/views/administrateurs/procedure_labels/index.html.haml +++ b/app/views/administrateurs/labels/index.html.haml @@ -9,10 +9,10 @@ %h1.fr-h2 Labels = link_to "Nouveau label", - [:new, :admin, @procedure, :procedure_label], + [:new, :admin, @procedure, :label], class: "fr-btn fr-btn--primary fr-btn--icon-left fr-icon-add-circle-line mb-3" - - if @procedure.procedure_labels.present? + - if @procedure.labels.present? .fr-table.fr-table--layout-fixed.fr-table--bordered %table %caption Liste des labels diff --git a/app/views/administrateurs/procedure_labels/new.html.haml b/app/views/administrateurs/labels/new.html.haml similarity index 90% rename from app/views/administrateurs/procedure_labels/new.html.haml rename to app/views/administrateurs/labels/new.html.haml index 46e9c11d0..fc4713cd3 100644 --- a/app/views/administrateurs/procedure_labels/new.html.haml +++ b/app/views/administrateurs/labels/new.html.haml @@ -3,14 +3,14 @@ = render partial: 'administrateurs/breadcrumbs', locals: { steps: [['Démarches', admin_procedures_path], [@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)], - ['gestion des labels', [:admin, @procedure, :procedure_labels]], + ['gestion des labels', [:admin, @procedure, :labels]], ['Nouveau label']] } .fr-container .fr-mb-3w = link_to "Liste de tous les labels", - [:admin, @procedure, :procedure_labels], + [:admin, @procedure, :labels], class: "fr-link fr-icon-arrow-left-line fr-link--icon-left" %h1.fr-h2 diff --git a/config/locales/models/procedure_label/fr.yml b/config/locales/models/label/fr.yml similarity index 87% rename from config/locales/models/procedure_label/fr.yml rename to config/locales/models/label/fr.yml index 23e1ac877..ca20608be 100644 --- a/config/locales/models/procedure_label/fr.yml +++ b/config/locales/models/label/fr.yml @@ -1,10 +1,10 @@ fr: activerecord: attributes: - procedure_label: + label: color: Couleur name: Nom - procedure_label/color: &color + label/color: &color green_tilleul_verveine: 'tilleul' green_bourgeon: 'bourgeon' green_emeraude: 'émeraude' diff --git a/config/routes.rb b/config/routes.rb index 0bf0c4602..ed06d5b7b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -708,7 +708,7 @@ Rails.application.routes.draw do get 'preview', on: :member end - resources :procedure_labels, controller: 'procedure_labels' + resources :labels, controller: 'labels' resource :attestation_template, only: [:show, :edit, :update, :create] do get 'preview', on: :member diff --git a/spec/controllers/administrateurs/procedure_labels_controller_spec.rb b/spec/controllers/administrateurs/labels_controller_spec.rb similarity index 73% rename from spec/controllers/administrateurs/procedure_labels_controller_spec.rb rename to spec/controllers/administrateurs/labels_controller_spec.rb index 4d93b4271..55b68a9f3 100644 --- a/spec/controllers/administrateurs/procedure_labels_controller_spec.rb +++ b/spec/controllers/administrateurs/labels_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe Administrateurs::ProcedureLabelsController, type: :controller do +describe Administrateurs::LabelsController, type: :controller do let(:admin) { administrateurs(:default_admin) } let(:procedure) { create(:procedure, administrateur: admin) } let(:admin_2) { create(:administrateur) } @@ -8,9 +8,9 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do describe '#index' do render_views - let!(:label_1) { create(:procedure_label, procedure:) } - let!(:label_2) { create(:procedure_label, procedure:) } - let!(:label_3) { create(:procedure_label, procedure:) } + let!(:label_1) { create(:label, procedure:) } + let!(:label_2) { create(:label, procedure:) } + let!(:label_3) { create(:label, procedure:) } before do sign_in(admin.user) @@ -36,7 +36,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do context 'when submitting a new label' do let(:params) do { - procedure_label: { + label: { name: 'Nouveau label', color: 'green-bourgeon' }, @@ -44,22 +44,22 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do } end - it { expect { subject }.to change { ProcedureLabel.count } .by(1) } + it { expect { subject }.to change { Label.count } .by(1) } it 'creates a new label' do subject expect(flash.alert).to be_nil expect(flash.notice).to eq('Le label a bien été créé') - expect(ProcedureLabel.last.name).to eq('Nouveau label') - expect(ProcedureLabel.last.color).to eq('green_bourgeon') - expect(procedure.procedure_labels.last).to eq(ProcedureLabel.last) + expect(Label.last.name).to eq('Nouveau label') + expect(Label.last.color).to eq('green_bourgeon') + expect(procedure.labels.last).to eq(Label.last) end end context 'when submitting an invalid label' do - let(:params) { { procedure_label: { name: 'Nouveau label' }, procedure_id: procedure.id } } + let(:params) { { label: { name: 'Nouveau label' }, procedure_id: procedure.id } } - it { expect { subject }.not_to change { ProcedureLabel.count } } + it { expect { subject }.not_to change { Label.count } } it 'does not create a new label' do subject @@ -72,7 +72,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do context 'when submitting a label for a not own procedure' do let(:params) do { - procedure_label: { + label: { name: 'Nouveau label', color: 'green-bourgeon' }, @@ -80,7 +80,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do } end - it { expect { subject }.not_to change { ProcedureLabel.count } } + it { expect { subject }.not_to change { Label.count } } it 'does not create a new label' do subject @@ -91,9 +91,9 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do end describe '#update' do - let!(:label) { create(:procedure_label, procedure:) } + let!(:label) { create(:label, procedure:) } let(:label_params) { { name: 'Nouveau nom' } } - let(:params) { { id: label.id, procedure_label: label_params, procedure_id: procedure.id } } + let(:params) { { id: label.id, label: label_params, procedure_id: procedure.id } } before do sign_in(admin.user) @@ -109,7 +109,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do expect(label.reload.name).to eq('Nouveau nom') expect(label.reload.color).to eq('green_bourgeon') expect(label.reload.updated_at).not_to eq(label.reload.created_at) - expect(response).to redirect_to(admin_procedure_procedure_labels_path(procedure_id: procedure.id)) + expect(response).to redirect_to(admin_procedure_labels_path(procedure_id: procedure.id)) end end @@ -125,7 +125,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do end context 'when updating a label for a not own procedure' do - let(:params) { { id: label.id, procedure_label: label_params, procedure_id: procedure_2.id } } + let(:params) { { id: label.id, label: label_params, procedure_id: procedure_2.id } } it 'does not update' do subject @@ -135,7 +135,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do end describe '#destroy' do - let(:label) { create(:procedure_label, procedure:) } + let(:label) { create(:label, procedure:) } before do sign_in(admin.user) @@ -150,7 +150,7 @@ describe Administrateurs::ProcedureLabelsController, type: :controller do subject expect { label.reload }.to raise_error(ActiveRecord::RecordNotFound) expect(flash.notice).to eq('Le label a bien été supprimé') - expect(response).to redirect_to((admin_procedure_procedure_labels_path(procedure_id: procedure.id))) + expect(response).to redirect_to(admin_procedure_labels_path(procedure_id: procedure.id)) end end diff --git a/spec/factories/procedure_label.rb b/spec/factories/label.rb similarity index 82% rename from spec/factories/procedure_label.rb rename to spec/factories/label.rb index fbc907b14..feeae49d1 100644 --- a/spec/factories/procedure_label.rb +++ b/spec/factories/label.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :procedure_label do + factory :label do name { 'Un label' } color { 'green-bourgeon' } association :procedure