From 58e393cd0de2141f2f85f92f867a0d28eedb704c Mon Sep 17 00:00:00 2001 From: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:41:35 +0100 Subject: [PATCH] feat: Apply new sort on assembly pps --- .../assemblies/assemblies_controller.rb | 6 +++- .../controllers/assemblies_controller_spec.rb | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/controllers/decidim/assemblies/assemblies_controller.rb b/app/controllers/decidim/assemblies/assemblies_controller.rb index e2309a19..8288eded 100644 --- a/app/controllers/decidim/assemblies/assemblies_controller.rb +++ b/app/controllers/decidim/assemblies/assemblies_controller.rb @@ -85,7 +85,11 @@ def stats end def assembly_participatory_processes - @assembly_participatory_processes ||= @current_participatory_space.linked_participatory_space_resources(:participatory_processes, "included_participatory_processes") + assembly_participatory_processes = @current_participatory_space.linked_participatory_space_resources(:participatory_processes, "included_participatory_processes") + sorted_by_end_date = assembly_participatory_processes.active_spaces.order(end_date: :asc) + sorted_by_end_date += assembly_participatory_processes.past_spaces.order(end_date: :desc) + + @assembly_participatory_processes ||= sorted_by_end_date end def current_assemblies_settings diff --git a/spec/controllers/assemblies_controller_spec.rb b/spec/controllers/assemblies_controller_spec.rb index 5c4434bf..fb2f156c 100644 --- a/spec/controllers/assemblies_controller_spec.rb +++ b/spec/controllers/assemblies_controller_spec.rb @@ -95,6 +95,34 @@ module Assemblies end end + + describe "assembly_participatory_processes" do + let!(:participatory_processes) do + 5.times.map do + create( + :participatory_process, + :published, + organization: organization, + start_date: Time.zone.now - rand(1..3).days, + end_date: Time.zone.now + rand(1..3).days + ) + end + end + + before do + published.link_participatory_space_resources(participatory_processes, "included_participatory_processes") + current_participatory_space = published + controller.instance_variable_set(:@current_participatory_space, current_participatory_space) + end + + it "includes only participatory processes related to the assembly, first those which are active by end_date :asc, then inactive ones by end_date :desc" do + sorted_participatory_processes = participatory_processes.select(&:active?).sort_by(&:end_date) + sorted_participatory_processes += participatory_processes.select(&:past?).sort_by(&:end_date).reverse + + expect(controller.helpers.assembly_participatory_processes.map(&:id)).to eq(sorted_participatory_processes.map(&:id)) + end + end + describe "GET show" do context "when the assembly is unpublished" do it "redirects to sign in path" do