Skip to content

Commit

Permalink
Backport 'Fix the active filter for process groups' to v0.26 (#11129)
Browse files Browse the repository at this point in the history
* Fix the active filter for process groups

* Fix the active filter for process groups

* Fetch the processes through scopes

* Add a spec to test if the end date is not set

* Add omitted value in keyword argument

* Bump actions/setup-node version to fix timmeout on CI

---------

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
  • Loading branch information
andreslucena and ahukkanen committed Jul 6, 2023
1 parent 21bf66c commit d60c148
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/actions/module-rspec/action.yml
Expand Up @@ -27,7 +27,7 @@ runs:
with:
ruby-version: ${{ inputs.ruby-version }}
bundler-cache: true
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
- name: Get npm cache directory path
Expand Down
Expand Up @@ -15,9 +15,11 @@ def query

processes = case @filter
when "past"
processes.where("decidim_participatory_processes.end_date <= ?", Date.current)
processes.past
when "upcoming"
processes.where("decidim_participatory_processes.start_date > ?", Date.current)
processes.upcoming
when "active"
processes.active
else
processes
end
Expand Down
@@ -0,0 +1,85 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim::ParticipatoryProcesses
describe FilteredParticipatoryProcessGroups do
subject { query }

let(:query) { described_class.new(filter) }

let(:organization) { create(:organization) }

# Active
let(:active_group) { create(:participatory_process_group, organization: organization) }
let!(:active_participatory_process) { create(:participatory_process, start_date: Date.current, end_date: 2.months.from_now, participatory_process_group: active_group, organization: organization) }

# Past
let(:past_group) { create(:participatory_process_group, organization: organization) }
let!(:past_participatory_process) { create(:participatory_process, start_date: 2.months.ago, end_date: 1.day.ago, participatory_process_group: past_group, organization: organization) }

# Upcoming
let(:upcoming_group) { create(:participatory_process_group, organization: organization) }
let!(:upcoming_participatory_process) { create(:participatory_process, start_date: 1.day.from_now, end_date: 2.months.from_now, participatory_process_group: upcoming_group, organization: organization) }

describe "#query" do
subject { query.query }

context "with active filter" do
let(:filter) { "active" }

it "returns only the active group" do
expect(subject.count).to eq(1)
expect(subject.first).to eq(active_group)
end

context "when the end date is the current date" do
let!(:active_participatory_process) { create(:participatory_process, start_date: 2.months.ago, end_date: Date.current, participatory_process_group: active_group, organization: organization) }

it "returns only the active group" do
expect(subject.count).to eq(1)
expect(subject.first).to eq(active_group)
end
end

context "when end date is not set" do
let!(:active_participatory_process) { create(:participatory_process, start_date: 2.months.ago, end_date: nil, participatory_process_group: active_group, organization: organization) }

it "returns only the active group" do
expect(subject.count).to eq(1)
expect(subject.first).to eq(active_group)
end
end
end

context "with past filter" do
let(:filter) { "past" }

it "returns only the past group" do
expect(subject.count).to eq(1)
expect(subject.first).to eq(past_group)
end
end

context "with upcoming filter" do
let(:filter) { "upcoming" }

it "returns only the upcoming group" do
expect(subject.count).to eq(1)
expect(subject.first).to eq(upcoming_group)
end
end

context "with all filter" do
let(:filter) { "all" }

it "returns all groups" do
expect(subject.count).to eq(3)
expect(subject).to include(active_group)
expect(subject).to include(past_group)
expect(subject).to include(upcoming_group)
end
end
end
end
end

0 comments on commit d60c148

Please sign in to comment.