exclude dossiers with pending correction when instructeur filters on 'en_construction'

This commit is contained in:
Lisa Durand 2023-09-26 16:36:39 +02:00
parent da62a5ec79
commit 129230af88
2 changed files with 17 additions and 0 deletions

View file

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

View file

@ -565,6 +565,21 @@ describe ProcedurePresentation do
is_expected.to contain_exactly(kept_dossier.id, other_kept_dossier.id)
end
end
context 'with en_construction state filters' do
let(:filter) do
[
{ 'table' => 'self', 'column' => 'state', 'value' => 'en_construction' }
]
end
let!(:en_construction) { create(:dossier, :en_construction, procedure: procedure) }
let!(:en_construction_with_correction) { create(:dossier, :en_construction, procedure: procedure) }
let!(:correction) { create(:dossier_correction, dossier: en_construction_with_correction) }
it 'excludes dossier en construction with pending correction' do
is_expected.to contain_exactly(en_construction.id)
end
end
end
context 'for type_de_champ table' do