chore: rename dossier_resolution => dossier_correction

This commit is contained in:
Colin Darie 2023-04-03 17:05:54 +02:00
parent b14a70abf7
commit 5ab44fc7a9
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
13 changed files with 64 additions and 64 deletions

View file

@ -1,13 +1,13 @@
module DossierResolvableConcern module DossierCorrectableConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
has_many :resolutions, class_name: 'DossierResolution', dependent: :destroy has_many :corrections, class_name: 'DossierCorrection', dependent: :destroy
def flag_as_pending_correction!(commentaire) def flag_as_pending_correction!(commentaire)
return unless may_flag_as_pending_correction? return unless may_flag_as_pending_correction?
resolutions.create(commentaire:) corrections.create(commentaire:)
return if en_construction? return if en_construction?
@ -15,16 +15,16 @@ module DossierResolvableConcern
end end
def may_flag_as_pending_correction? def may_flag_as_pending_correction?
return false if resolutions.pending.exists? return false if corrections.pending.exists?
en_construction? || may_repasser_en_construction? en_construction? || may_repasser_en_construction?
end end
def pending_resolution? def pending_correction?
# We don't want to show any alert if user is not allowed to modify the dossier # We don't want to show any alert if user is not allowed to modify the dossier
return false unless en_construction? return false unless en_construction?
resolutions.pending.exists? corrections.pending.exists?
end end
end end
end end

View file

@ -47,13 +47,13 @@
# user_id :integer # user_id :integer
# #
class Dossier < ApplicationRecord class Dossier < ApplicationRecord
include DossierCloneConcern
include DossierCorrectableConcern
include DossierFilteringConcern include DossierFilteringConcern
include DossierPrefillableConcern include DossierPrefillableConcern
include DossierRebaseConcern include DossierRebaseConcern
include DossierResolvableConcern
include DossierSearchableConcern include DossierSearchableConcern
include DossierSectionsConcern include DossierSectionsConcern
include DossierCloneConcern
enum state: { enum state: {
brouillon: 'brouillon', brouillon: 'brouillon',

View file

@ -1,6 +1,6 @@
# == Schema Information # == Schema Information
# #
# Table name: dossier_resolutions # Table name: dossier_corrections
# #
# id :bigint not null, primary key # id :bigint not null, primary key
# resolved_at :datetime # resolved_at :datetime
@ -9,7 +9,7 @@
# commentaire_id :bigint # commentaire_id :bigint
# dossier_id :bigint not null # dossier_id :bigint not null
# #
class DossierResolution < ApplicationRecord class DossierCorrection < ApplicationRecord
belongs_to :dossier belongs_to :dossier
belongs_to :commentaire belongs_to :commentaire

View file

@ -184,7 +184,7 @@ class ProcedurePresentation < ApplicationRecord
dossiers.filter_by_datetimes(column, dates) dossiers.filter_by_datetimes(column, dates)
elsif field['column'] == "state" && values.include?("pending_correction") elsif field['column'] == "state" && values.include?("pending_correction")
dossiers.joins(:resolutions).where(resolutions: DossierResolution.pending) dossiers.joins(:corrections).where(corrections: DossierCorrection.pending)
else else
dossiers.where("dossiers.#{column} IN (?)", values) dossiers.where("dossiers.#{column} IN (?)", values)
end end

View file

@ -1,9 +1,9 @@
class DossierProjectionService 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? 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 end
end end
@ -29,8 +29,8 @@ class DossierProjectionService
batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' } batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' }
hidden_by_user_at_field = { TABLE => 'self', COLUMN => 'hidden_by_user_at' } hidden_by_user_at_field = { TABLE => 'self', COLUMN => 'hidden_by_user_at' }
hidden_by_administration_at_field = { TABLE => 'self', COLUMN => 'hidden_by_administration_at' } hidden_by_administration_at_field = { TABLE => 'self', COLUMN => 'hidden_by_administration_at' }
dossier_resolutions = { TABLE => 'dossier_resolutions', COLUMN => 'resolved_at' } 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_resolutions] + fields) # the view needs state and archived dossier attributes ([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] = {} } .each { |f| f[:id_value_h] = {} }
.group_by { |f| f[TABLE] } # one query per table .group_by { |f| f[TABLE] } # one query per table
.each do |table, fields| .each do |table, fields|
@ -83,13 +83,13 @@ class DossierProjectionService
.where(id: dossiers_ids) .where(id: dossiers_ids)
.pluck('dossiers.id, groupe_instructeurs.label') .pluck('dossiers.id, groupe_instructeurs.label')
.to_h .to_h
when 'dossier_resolutions' when 'dossier_corrections'
columns = fields.map { _1[COLUMN].to_sym } 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) .pluck(:dossier_id, *columns)
.group_by(&:first) # group resolutions by dossier_id .group_by(&:first) # group corrections by dossier_id
.transform_values do |values| # build each resolution has an hash column => value .transform_values do |values| # build each correction has an hash column => value
values.map { Hash[columns.zip(_1[1..-1])] } values.map { Hash[columns.zip(_1[1..-1])] }
end end
@ -130,7 +130,7 @@ class DossierProjectionService
hidden_by_user_at_field[:id_value_h][dossier_id], hidden_by_user_at_field[:id_value_h][dossier_id],
hidden_by_administration_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], 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] } fields.map { |f| f[:id_value_h][dossier_id] }
) )
end end

View file

@ -5,7 +5,7 @@
= "Dossier nº #{dossier.id}" = "Dossier nº #{dossier.id}"
= status_badge(dossier.state, 'super') = 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" = link_to dossier.procedure.libelle.truncate_words(10), instructeur_procedure_path(dossier.procedure), title: dossier.procedure.libelle, class: "fr-link"
= procedure_badge(dossier.procedure) = procedure_badge(dossier.procedure)

View file

@ -3,7 +3,7 @@
%h1 %h1
= dossier.procedure.libelle = dossier.procedure.libelle
= status_badge(dossier.state, 'super') = status_badge(dossier.state, 'super')
= pending_correction_badge(:for_user) if dossier.pending_resolution? = pending_correction_badge(:for_user) if dossier.pending_correction?
%h2 %h2
= t('views.users.dossiers.show.header.dossier_number', dossier_id: dossier.id) = t('views.users.dossiers.show.header.dossier_number', dossier_id: dossier.id)
- if dossier.depose_at.present? - if dossier.depose_at.present?

View file

@ -524,12 +524,12 @@ describe Instructeurs::DossiersController, type: :controller do
expect(DossierMailer).to have_received(:notify_pending_correction).with(dossier) expect(DossierMailer).to have_received(:notify_pending_correction).with(dossier)
end 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).to have_http_status(:ok)
expect(response.body).to include('en attente de modifications') expect(response.body).to include('en attente de modifications')
expect(dossier.reload).to be_en_construction expect(dossier.reload).to be_en_construction
expect(dossier).to be_pending_resolution expect(dossier).to be_pending_correction
end end
it 'create a comment with text body' do it 'create a comment with text body' do
@ -549,7 +549,7 @@ describe Instructeurs::DossiersController, type: :controller do
let(:message) { '' } let(:message) { '' }
it 'requires a message' do 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(dossier.commentaires.count).to eq(0)
expect(response.body).to include('Vous devez préciser') expect(response.body).to include('Vous devez préciser')
end end
@ -557,11 +557,11 @@ describe Instructeurs::DossiersController, type: :controller do
context 'dossier already having pending corrections' do context 'dossier already having pending corrections' do
before do before do
create(:dossier_resolution, dossier:) create(:dossier_correction, dossier:)
end end
it 'does not create an new pending resolution' do it 'does not create an new pending correction' do
expect { subject }.not_to change { DossierResolution.count } expect { subject }.not_to change { DossierCorrection.count }
end end
it 'shows a flash alert' do it 'shows a flash alert' do
@ -573,9 +573,9 @@ describe Instructeurs::DossiersController, type: :controller do
end end
context 'dossier en_construction' do context 'dossier en_construction' do
it 'can create a pending resolution' do it 'can create a pending correction' do
subject subject
expect(dossier.reload).to be_pending_resolution expect(dossier.reload).to be_pending_correction
expect(dossier.commentaires.last).to be_flagged_pending_corrections expect(dossier.commentaires.last).to be_flagged_pending_corrections
end end
end end
@ -583,8 +583,8 @@ describe Instructeurs::DossiersController, type: :controller do
context 'dossier is termine' do context 'dossier is termine' do
let(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure) } let(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure) }
it 'does not create a pending resolution' do it 'does not create a pending correction' do
expect { subject }.not_to change { DossierResolution.count } expect { subject }.not_to change { DossierCorrection.count }
expect(response.body).to include('Impossible') expect(response.body).to include('Impossible')
end end
end end

View file

@ -1,5 +1,5 @@
FactoryBot.define do FactoryBot.define do
factory :dossier_resolution do factory :dossier_correction do
dossier dossier
commentaire commentaire
resolved_at { nil } resolved_at { nil }

View file

@ -1,28 +1,28 @@
describe DossierResolvableConcern do describe DossierCorrectableConcern do
describe "#pending_resolution?" do describe "#pending_correction?" do
let(:dossier) { create(:dossier, :en_construction) } let(:dossier) { create(:dossier, :en_construction) }
context "when dossier has no resolution" do context "when dossier has no correction" do
it { expect(dossier.pending_resolution?).to be_falsey } it { expect(dossier.pending_correction?).to be_falsey }
end end
context "when dossier has a pending resolution" do context "when dossier has a pending correction" do
before { create(:dossier_resolution, dossier:) } before { create(:dossier_correction, dossier:) }
it { expect(dossier.pending_resolution?).to be_truthy } it { expect(dossier.pending_correction?).to be_truthy }
end end
context "when dossier has a resolved resolution" do context "when dossier has a resolved correction" do
before { create(:dossier_resolution, :resolved, dossier:) } before { create(:dossier_correction, :resolved, dossier:) }
it { expect(dossier.pending_resolution?).to be_falsey } it { expect(dossier.pending_correction?).to be_falsey }
end end
context "when dossier is not en_construction" do context "when dossier is not en_construction" do
let(:dossier) { create(:dossier, :en_instruction) } 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
end end
@ -32,8 +32,8 @@ describe DossierResolvableConcern do
let(:commentaire) { create(:commentaire, dossier:, instructeur:) } let(:commentaire) { create(:commentaire, dossier:, instructeur:) }
context 'when dossier is en_construction' do context 'when dossier is en_construction' do
it 'creates a resolution' do it 'creates a correction' do
expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.resolutions.pending.count }.by(1) expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.corrections.pending.count }.by(1)
end end
it 'does not change dossier state' do it 'does not change dossier state' do
@ -44,8 +44,8 @@ describe DossierResolvableConcern do
context 'when dossier is not en_instruction' do context 'when dossier is not en_instruction' do
let(:dossier) { create(:dossier, :en_instruction) } let(:dossier) { create(:dossier, :en_instruction) }
it 'creates a resolution' do it 'creates a correction' do
expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.resolutions.pending.count }.by(1) expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.corrections.pending.count }.by(1)
end end
it 'repasse dossier en_construction' do it 'repasse dossier en_construction' do
@ -53,27 +53,27 @@ describe DossierResolvableConcern do
end end
end end
context 'when dossier has already a pending resolution' do context 'when dossier has already a pending correction' do
before { create(:dossier_resolution, dossier:) } before { create(:dossier_correction, dossier:) }
it 'does not create a resolution' do it 'does not create a correction' do
expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.resolutions.pending.count } expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.corrections.pending.count }
end end
end end
context 'when dossier has already a resolved resolution' do context 'when dossier has already a resolved correction' do
before { create(:dossier_resolution, :resolved, dossier:) } before { create(:dossier_correction, :resolved, dossier:) }
it 'creates a resolution' do it 'creates a correction' do
expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.resolutions.pending.count }.by(1) expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.corrections.pending.count }.by(1)
end end
end end
context 'when dossier is not en_construction and may not be repassed en_construction' do context 'when dossier is not en_construction and may not be repassed en_construction' do
let(:dossier) { create(:dossier, :accepte) } let(:dossier) { create(:dossier, :accepte) }
it 'does not create a resolution' do it 'does not create a correction' do
expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.resolutions.pending.count } expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.corrections.pending.count }
end end
end end
end end

View file

@ -1,5 +1,5 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe DossierResolution, type: :model do RSpec.describe DossierCorrection, type: :model do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"
end end

View file

@ -250,19 +250,19 @@ describe DossierProjectionService do
end end
context 'for dossier reolutions table' do context 'for dossier reolutions table' do
let(:table) { 'dossier_resolutions' } let(:table) { 'dossier_corrections' }
let(:column) { 'resolved_at' } let(:column) { 'resolved_at' }
let(:dossier) { create(:dossier, :en_construction) } let(:dossier) { create(:dossier, :en_construction) }
subject { described_class.project(dossiers_ids, fields)[0] } subject { described_class.project(dossiers_ids, fields)[0] }
context "when dossier has pending correction" do 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) } it { expect(subject.pending_correction?).to be(true) }
end end
context "when dossier has a resolved correction" do 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) } it { expect(subject.pending_correction?).to eq(false) }
end end