chore: rename dossier_resolution => dossier_correction
This commit is contained in:
parent
b14a70abf7
commit
5ab44fc7a9
13 changed files with 64 additions and 64 deletions
|
@ -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
|
|
@ -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',
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
FactoryBot.define do
|
||||
factory :dossier_resolution do
|
||||
factory :dossier_correction do
|
||||
dossier
|
||||
commentaire
|
||||
resolved_at { nil }
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue