fix order by label name

This commit is contained in:
Lisa Durand 2024-11-07 11:39:32 +01:00
parent 27f14954b6
commit a0bd85f247
No known key found for this signature in database
GPG key ID: 0DF91F2CA1E8B816
2 changed files with 13 additions and 8 deletions

View file

@ -57,8 +57,8 @@ class DossierFilterService
.pluck(:id) .pluck(:id)
.uniq .uniq
when 'dossier_labels' when 'dossier_labels'
dossiers.includes(table) dossiers.includes(:labels)
.order("#{sanitized_column(table, column)} #{order}") .order("labels.name #{order}")
.pluck(:id) .pluck(:id)
.uniq .uniq
when 'self', 'user', 'individual', 'etablissement', 'groupe_instructeur' when 'self', 'user', 'individual', 'etablissement', 'groupe_instructeur'

View file

@ -275,19 +275,24 @@ describe DossierFilterService do
context 'for labels table' do context 'for labels table' do
let(:column) { procedure.find_column(label: 'Labels') } let(:column) { procedure.find_column(label: 'Labels') }
let(:order) { 'asc' }
let(:label_a) { Label.create(name: "a", color: 'green-bourgeon', procedure:) } let(:label_a) { Label.create(name: "a", color: 'green-bourgeon', procedure:) }
let(:label_z) { Label.create(name: "z", color: 'green-bourgeon', procedure:) } let(:label_z) { Label.create(name: "z", color: 'green-bourgeon', procedure:) }
let!(:dossier_a) { create(:dossier, procedure:) }
let!(:dossier_z) { create(:dossier, procedure:) } let!(:dossier_z) { create(:dossier, procedure:) }
let(:dossier_label_a) { DossierLabel.create(dossier: dossier_a, label: label_a) } let!(:dossier_a) { create(:dossier, procedure:) }
let(:dossier_label_z) { DossierLabel.create(dossier: dossier_z, label: label_z) } let!(:dossier_no_label) { create(:dossier, procedure:) }
let!(:dossier_label_a) { DossierLabel.create(dossier: dossier_a, label: label_a) }
let!(:dossier_label_z) { DossierLabel.create(dossier: dossier_z, label: label_z) }
before do context 'asc' do
let(:order) { 'asc' }
it { is_expected.to eq([dossier_a, dossier_z, dossier_no_label].map(&:id)) }
end end
it { is_expected.to eq([dossier_a, dossier_z].map(&:id)) } context 'desc' do
let(:order) { 'desc' }
it { is_expected.to eq([dossier_no_label, dossier_z, dossier_a].map(&:id)) }
end
end end
context 'for other tables' do context 'for other tables' do