From 1d6c2fd7eb1dc222750ad2a76c78f03e7be21502 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 24 Feb 2023 17:27:28 +0100 Subject: [PATCH] display procedures without zones --- .../administrateurs/procedures_controller.rb | 2 +- .../administrateurs/procedures_controller_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index 3a0baef4f..62718fc3d 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -410,7 +410,7 @@ module Administrateurs private def filter_procedures(filter) - procedures_result = Procedure.select(:id).joins(:procedures_zones).distinct.publiees_ou_closes + procedures_result = Procedure.select(:id).left_joins(:procedures_zones).distinct.publiees_ou_closes procedures_result = procedures_result.where(procedures_zones: { zone_id: filter.zone_ids }) if filter.zone_ids.present? procedures_result = procedures_result.where(aasm_state: filter.statuses) if filter.statuses.present? procedures_result = procedures_result.where("? = ANY(tags)", filter.tag) if filter.tag.present? diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index 23a598d84..b1f09c6da 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -132,6 +132,16 @@ describe Administrateurs::ProceduresController, type: :controller do expect(assigns(:procedures).any? { |p| p.id == procedure2.id }).to be_truthy expect(assigns(:procedures).any? { |p| p.id == procedure1.id }).to be_falsey end + + context "without zones" do + let!(:procedure) { create(:procedure, :published, zones: []) } + subject { get :all } + + it 'displays procedures without zones' do + subject + expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy + end + end end context 'for specific status' do