diff --git a/spec/controllers/assemblies_controller_spec.rb b/spec/controllers/assemblies_controller_spec.rb index f28fd0e2c6..94d2a9fc7e 100644 --- a/spec/controllers/assemblies_controller_spec.rb +++ b/spec/controllers/assemblies_controller_spec.rb @@ -146,11 +146,12 @@ module Assemblies context "when sort_by_date variable is true" do before do allow(Rails.application.secrets).to receive(:dig).with(:decidim, :participatory_processes, :sort_by_date).and_return(true) + active_processes.first.update(end_date: nil) end - it "includes only participatory processes related to the assembly, actives one by end_date then upcoming ones by start_date then past ones by end_date reversed" do + it "includes only participatory processes related to the assembly, actives one by end_date with end_date nil last, then upcoming ones by start_date then past ones by end_date reversed" do sorted_participatory_processes = { - active: participatory_processes.select(&:active?).sort_by(&:end_date), + active: participatory_processes.reject { |process| process.end_date.nil? }.select(&:active?).sort_by(&:end_date) + participatory_processes.select { |process| process.end_date.nil? && process.active? }, future: participatory_processes.select(&:upcoming?).sort_by(&:start_date), past: participatory_processes.select(&:past?).sort_by(&:end_date).reverse } diff --git a/spec/controllers/participatory_processes_controller_spec.rb b/spec/controllers/participatory_processes_controller_spec.rb index 52d34d206b..977ccc12b6 100644 --- a/spec/controllers/participatory_processes_controller_spec.rb +++ b/spec/controllers/participatory_processes_controller_spec.rb @@ -137,11 +137,12 @@ module ParticipatoryProcesses context "and sort_by_date is true" do before do allow(Rails.application.secrets).to receive(:dig).with(:decidim, :participatory_processes, :sort_by_date).and_return(true) + active_processes.first.update(end_date: nil) end # search.with_date will default to "active" it "orders active processes by end date" do - expect(controller.helpers.participatory_processes).to eq(active_processes.sort_by(&:end_date)) + expect(controller.helpers.participatory_processes).to eq(active_processes.reject { |process| process.end_date.nil? }.sort_by(&:end_date) + active_processes.select { |process| process.end_date.nil? }) end end end