From 5ab44fc7a9b3678e6f80877d4b14f07d74d558f1 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 3 Apr 2023 17:05:54 +0200 Subject: [PATCH] chore: rename dossier_resolution => dossier_correction --- ...cern.rb => dossier_correctable_concern.rb} | 12 ++--- app/models/dossier.rb | 4 +- ...er_resolution.rb => dossier_correction.rb} | 4 +- app/models/procedure_presentation.rb | 2 +- app/services/dossier_projection_service.rb | 20 +++---- .../dossiers/_header_top.html.haml | 2 +- .../users/dossiers/show/_header.html.haml | 2 +- ...30228134859_create_dossier_corrections.rb} | 0 .../instructeurs/dossiers_controller_spec.rb | 20 +++---- ..._resolutions.rb => dossier_corrections.rb} | 2 +- ...rb => dossier_correctable_concern_spec.rb} | 52 +++++++++---------- ...ion_spec.rb => dossier_correction_spec.rb} | 2 +- .../dossier_projection_service_spec.rb | 6 +-- 13 files changed, 64 insertions(+), 64 deletions(-) rename app/models/concerns/{dossier_resolvable_concern.rb => dossier_correctable_concern.rb} (68%) rename app/models/{dossier_resolution.rb => dossier_correction.rb} (82%) rename db/migrate/{20230228134859_create_dossier_resolutions.rb => 20230228134859_create_dossier_corrections.rb} (100%) rename spec/factories/{dossier_resolutions.rb => dossier_corrections.rb} (82%) rename spec/models/concern/{dossier_resolvable_concern_spec.rb => dossier_correctable_concern_spec.rb} (52%) rename spec/models/{dossier_resolution_spec.rb => dossier_correction_spec.rb} (62%) diff --git a/app/models/concerns/dossier_resolvable_concern.rb b/app/models/concerns/dossier_correctable_concern.rb similarity index 68% rename from app/models/concerns/dossier_resolvable_concern.rb rename to app/models/concerns/dossier_correctable_concern.rb index f4d827b56..cc9c9bce3 100644 --- a/app/models/concerns/dossier_resolvable_concern.rb +++ b/app/models/concerns/dossier_correctable_concern.rb @@ -1,13 +1,13 @@ -module DossierResolvableConcern +module DossierCorrectableConcern extend ActiveSupport::Concern included do - has_many :resolutions, class_name: 'DossierResolution', dependent: :destroy + has_many :corrections, class_name: 'DossierCorrection', dependent: :destroy def flag_as_pending_correction!(commentaire) return unless may_flag_as_pending_correction? - resolutions.create(commentaire:) + corrections.create(commentaire:) return if en_construction? @@ -15,16 +15,16 @@ module DossierResolvableConcern end def may_flag_as_pending_correction? - return false if resolutions.pending.exists? + return false if corrections.pending.exists? en_construction? || may_repasser_en_construction? end - def pending_resolution? + def pending_correction? # We don't want to show any alert if user is not allowed to modify the dossier return false unless en_construction? - resolutions.pending.exists? + corrections.pending.exists? end end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 2e48629d5..8b2054d3b 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -47,13 +47,13 @@ # user_id :integer # class Dossier < ApplicationRecord + include DossierCloneConcern + include DossierCorrectableConcern include DossierFilteringConcern include DossierPrefillableConcern include DossierRebaseConcern - include DossierResolvableConcern include DossierSearchableConcern include DossierSectionsConcern - include DossierCloneConcern enum state: { brouillon: 'brouillon', diff --git a/app/models/dossier_resolution.rb b/app/models/dossier_correction.rb similarity index 82% rename from app/models/dossier_resolution.rb rename to app/models/dossier_correction.rb index 706d65367..95d16bce6 100644 --- a/app/models/dossier_resolution.rb +++ b/app/models/dossier_correction.rb @@ -1,6 +1,6 @@ # == Schema Information # -# Table name: dossier_resolutions +# Table name: dossier_corrections # # id :bigint not null, primary key # resolved_at :datetime @@ -9,7 +9,7 @@ # commentaire_id :bigint # dossier_id :bigint not null # -class DossierResolution < ApplicationRecord +class DossierCorrection < ApplicationRecord belongs_to :dossier belongs_to :commentaire diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index b86606dbf..42e47398d 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -184,7 +184,7 @@ class ProcedurePresentation < ApplicationRecord dossiers.filter_by_datetimes(column, dates) elsif field['column'] == "state" && values.include?("pending_correction") - dossiers.joins(:resolutions).where(resolutions: DossierResolution.pending) + dossiers.joins(:corrections).where(corrections: DossierCorrection.pending) else dossiers.where("dossiers.#{column} IN (?)", values) end diff --git a/app/services/dossier_projection_service.rb b/app/services/dossier_projection_service.rb index c7f97a3da..a5e348ad6 100644 --- a/app/services/dossier_projection_service.rb +++ b/app/services/dossier_projection_service.rb @@ -1,9 +1,9 @@ class DossierProjectionService - class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :batch_operation_id, :resolutions, :columns) do + class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :batch_operation_id, :corrections, :columns) do def pending_correction? - return false if resolutions.blank? + return false if corrections.blank? - resolutions.any? { _1[:resolved_at].nil? } + corrections.any? { _1[:resolved_at].nil? } end end end @@ -29,8 +29,8 @@ class DossierProjectionService batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' } hidden_by_user_at_field = { TABLE => 'self', COLUMN => 'hidden_by_user_at' } hidden_by_administration_at_field = { TABLE => 'self', COLUMN => 'hidden_by_administration_at' } - dossier_resolutions = { TABLE => 'dossier_resolutions', COLUMN => 'resolved_at' } - ([state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, batch_operation_field, dossier_resolutions] + fields) # the view needs state and archived dossier attributes + dossier_corrections = { TABLE => 'dossier_corrections', COLUMN => 'resolved_at' } + ([state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, batch_operation_field, dossier_corrections] + fields) # the view needs state and archived dossier attributes .each { |f| f[:id_value_h] = {} } .group_by { |f| f[TABLE] } # one query per table .each do |table, fields| @@ -83,13 +83,13 @@ class DossierProjectionService .where(id: dossiers_ids) .pluck('dossiers.id, groupe_instructeurs.label') .to_h - when 'dossier_resolutions' + when 'dossier_corrections' columns = fields.map { _1[COLUMN].to_sym } - id_value_h = DossierResolution.where(dossier_id: dossiers_ids) + id_value_h = DossierCorrection.where(dossier_id: dossiers_ids) .pluck(:dossier_id, *columns) - .group_by(&:first) # group resolutions by dossier_id - .transform_values do |values| # build each resolution has an hash column => value + .group_by(&:first) # group corrections by dossier_id + .transform_values do |values| # build each correction has an hash column => value values.map { Hash[columns.zip(_1[1..-1])] } end @@ -130,7 +130,7 @@ class DossierProjectionService hidden_by_user_at_field[:id_value_h][dossier_id], hidden_by_administration_at_field[:id_value_h][dossier_id], batch_operation_field[:id_value_h][dossier_id], - dossier_resolutions[:id_value_h][dossier_id], + dossier_corrections[:id_value_h][dossier_id], fields.map { |f| f[:id_value_h][dossier_id] } ) end diff --git a/app/views/instructeurs/dossiers/_header_top.html.haml b/app/views/instructeurs/dossiers/_header_top.html.haml index 6889e0ed4..4537515f2 100644 --- a/app/views/instructeurs/dossiers/_header_top.html.haml +++ b/app/views/instructeurs/dossiers/_header_top.html.haml @@ -5,7 +5,7 @@ = "Dossier nº #{dossier.id}" = status_badge(dossier.state, 'super') - = pending_correction_badge(:for_instructeur) if dossier.pending_resolution? + = pending_correction_badge(:for_instructeur) if dossier.pending_correction? = link_to dossier.procedure.libelle.truncate_words(10), instructeur_procedure_path(dossier.procedure), title: dossier.procedure.libelle, class: "fr-link" = procedure_badge(dossier.procedure) diff --git a/app/views/users/dossiers/show/_header.html.haml b/app/views/users/dossiers/show/_header.html.haml index 485d93ed8..e5544c01a 100644 --- a/app/views/users/dossiers/show/_header.html.haml +++ b/app/views/users/dossiers/show/_header.html.haml @@ -3,7 +3,7 @@ %h1 = dossier.procedure.libelle = status_badge(dossier.state, 'super') - = pending_correction_badge(:for_user) if dossier.pending_resolution? + = pending_correction_badge(:for_user) if dossier.pending_correction? %h2 = t('views.users.dossiers.show.header.dossier_number', dossier_id: dossier.id) - if dossier.depose_at.present? diff --git a/db/migrate/20230228134859_create_dossier_resolutions.rb b/db/migrate/20230228134859_create_dossier_corrections.rb similarity index 100% rename from db/migrate/20230228134859_create_dossier_resolutions.rb rename to db/migrate/20230228134859_create_dossier_corrections.rb diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index fd25ce681..74eb24daa 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -524,12 +524,12 @@ describe Instructeurs::DossiersController, type: :controller do expect(DossierMailer).to have_received(:notify_pending_correction).with(dossier) end - it 'pass en_construction and create a pending resolution' do + it 'pass en_construction and create a pending correction' do expect(response).to have_http_status(:ok) expect(response.body).to include('en attente de modifications') expect(dossier.reload).to be_en_construction - expect(dossier).to be_pending_resolution + expect(dossier).to be_pending_correction end it 'create a comment with text body' do @@ -549,7 +549,7 @@ describe Instructeurs::DossiersController, type: :controller do let(:message) { '' } it 'requires a message' do - expect(dossier.reload).not_to be_pending_resolution + expect(dossier.reload).not_to be_pending_correction expect(dossier.commentaires.count).to eq(0) expect(response.body).to include('Vous devez préciser') end @@ -557,11 +557,11 @@ describe Instructeurs::DossiersController, type: :controller do context 'dossier already having pending corrections' do before do - create(:dossier_resolution, dossier:) + create(:dossier_correction, dossier:) end - it 'does not create an new pending resolution' do - expect { subject }.not_to change { DossierResolution.count } + it 'does not create an new pending correction' do + expect { subject }.not_to change { DossierCorrection.count } end it 'shows a flash alert' do @@ -573,9 +573,9 @@ describe Instructeurs::DossiersController, type: :controller do end context 'dossier en_construction' do - it 'can create a pending resolution' do + it 'can create a pending correction' do subject - expect(dossier.reload).to be_pending_resolution + expect(dossier.reload).to be_pending_correction expect(dossier.commentaires.last).to be_flagged_pending_corrections end end @@ -583,8 +583,8 @@ describe Instructeurs::DossiersController, type: :controller do context 'dossier is termine' do let(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure) } - it 'does not create a pending resolution' do - expect { subject }.not_to change { DossierResolution.count } + it 'does not create a pending correction' do + expect { subject }.not_to change { DossierCorrection.count } expect(response.body).to include('Impossible') end end diff --git a/spec/factories/dossier_resolutions.rb b/spec/factories/dossier_corrections.rb similarity index 82% rename from spec/factories/dossier_resolutions.rb rename to spec/factories/dossier_corrections.rb index 0bc95ec54..a3f88a9f5 100644 --- a/spec/factories/dossier_resolutions.rb +++ b/spec/factories/dossier_corrections.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :dossier_resolution do + factory :dossier_correction do dossier commentaire resolved_at { nil } diff --git a/spec/models/concern/dossier_resolvable_concern_spec.rb b/spec/models/concern/dossier_correctable_concern_spec.rb similarity index 52% rename from spec/models/concern/dossier_resolvable_concern_spec.rb rename to spec/models/concern/dossier_correctable_concern_spec.rb index d02b0b539..15e6df6ab 100644 --- a/spec/models/concern/dossier_resolvable_concern_spec.rb +++ b/spec/models/concern/dossier_correctable_concern_spec.rb @@ -1,28 +1,28 @@ -describe DossierResolvableConcern do - describe "#pending_resolution?" do +describe DossierCorrectableConcern do + describe "#pending_correction?" do let(:dossier) { create(:dossier, :en_construction) } - context "when dossier has no resolution" do - it { expect(dossier.pending_resolution?).to be_falsey } + context "when dossier has no correction" do + it { expect(dossier.pending_correction?).to be_falsey } end - context "when dossier has a pending resolution" do - before { create(:dossier_resolution, dossier:) } + context "when dossier has a pending correction" do + before { create(:dossier_correction, dossier:) } - it { expect(dossier.pending_resolution?).to be_truthy } + it { expect(dossier.pending_correction?).to be_truthy } end - context "when dossier has a resolved resolution" do - before { create(:dossier_resolution, :resolved, dossier:) } + context "when dossier has a resolved correction" do + before { create(:dossier_correction, :resolved, dossier:) } - it { expect(dossier.pending_resolution?).to be_falsey } + it { expect(dossier.pending_correction?).to be_falsey } end context "when dossier is not en_construction" do let(:dossier) { create(:dossier, :en_instruction) } - before { create(:dossier_resolution, dossier:) } + before { create(:dossier_correction, dossier:) } - it { expect(dossier.pending_resolution?).to be_falsey } + it { expect(dossier.pending_correction?).to be_falsey } end end @@ -32,8 +32,8 @@ describe DossierResolvableConcern do let(:commentaire) { create(:commentaire, dossier:, instructeur:) } context 'when dossier is en_construction' do - it 'creates a resolution' do - expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.resolutions.pending.count }.by(1) + it 'creates a correction' do + expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.corrections.pending.count }.by(1) end it 'does not change dossier state' do @@ -44,8 +44,8 @@ describe DossierResolvableConcern do context 'when dossier is not en_instruction' do let(:dossier) { create(:dossier, :en_instruction) } - it 'creates a resolution' do - expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.resolutions.pending.count }.by(1) + it 'creates a correction' do + expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.corrections.pending.count }.by(1) end it 'repasse dossier en_construction' do @@ -53,27 +53,27 @@ describe DossierResolvableConcern do end end - context 'when dossier has already a pending resolution' do - before { create(:dossier_resolution, dossier:) } + context 'when dossier has already a pending correction' do + before { create(:dossier_correction, dossier:) } - it 'does not create a resolution' do - expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.resolutions.pending.count } + it 'does not create a correction' do + expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.corrections.pending.count } end end - context 'when dossier has already a resolved resolution' do - before { create(:dossier_resolution, :resolved, dossier:) } + context 'when dossier has already a resolved correction' do + before { create(:dossier_correction, :resolved, dossier:) } - it 'creates a resolution' do - expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.resolutions.pending.count }.by(1) + it 'creates a correction' do + expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.corrections.pending.count }.by(1) end end context 'when dossier is not en_construction and may not be repassed en_construction' do let(:dossier) { create(:dossier, :accepte) } - it 'does not create a resolution' do - expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.resolutions.pending.count } + it 'does not create a correction' do + expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.corrections.pending.count } end end end diff --git a/spec/models/dossier_resolution_spec.rb b/spec/models/dossier_correction_spec.rb similarity index 62% rename from spec/models/dossier_resolution_spec.rb rename to spec/models/dossier_correction_spec.rb index 8acd68e8e..42dac10e8 100644 --- a/spec/models/dossier_resolution_spec.rb +++ b/spec/models/dossier_correction_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe DossierResolution, type: :model do +RSpec.describe DossierCorrection, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/services/dossier_projection_service_spec.rb b/spec/services/dossier_projection_service_spec.rb index cf11a1363..c61c12f73 100644 --- a/spec/services/dossier_projection_service_spec.rb +++ b/spec/services/dossier_projection_service_spec.rb @@ -250,19 +250,19 @@ describe DossierProjectionService do end context 'for dossier reolutions table' do - let(:table) { 'dossier_resolutions' } + let(:table) { 'dossier_corrections' } let(:column) { 'resolved_at' } let(:dossier) { create(:dossier, :en_construction) } subject { described_class.project(dossiers_ids, fields)[0] } context "when dossier has pending correction" do - before { create(:dossier_resolution, dossier:) } + before { create(:dossier_correction, dossier:) } it { expect(subject.pending_correction?).to be(true) } end context "when dossier has a resolved correction" do - before { create(:dossier_resolution, :resolved, dossier:) } + before { create(:dossier_correction, :resolved, dossier:) } it { expect(subject.pending_correction?).to eq(false) } end