Skip to content

Commit

Permalink
feat: Apply new sort on assembly pps
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Feb 20, 2024
1 parent a6e3bcd commit 58e393c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/decidim/assemblies/assemblies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions spec/controllers/assemblies_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58e393c

Please sign in to comment.