Skip to content

Commit

Permalink
test: update test with process without end date
Browse files Browse the repository at this point in the history
  • Loading branch information
Stef-Rousset committed Nov 12, 2024
1 parent 6ba2ed8 commit 77478a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions spec/controllers/assemblies_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/participatory_processes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 77478a5

Please sign in to comment.