diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index bf02dc7b6..c3f2bcc1a 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -1,7 +1,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseController include Translatable - has_filters %w[open all], only: :index + has_filters %w[active all], only: :index load_and_authorize_resource :process, class: "Legislation::Process" diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index c4101bc87..462ad677c 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -50,6 +50,7 @@ class Legislation::Process < ActiveRecord::Base validates :font_color, format: { allow_blank: true, with: CSS_HEX_COLOR } scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current) } + scope :active, -> { where("end_date >= ?", Date.current) } scope :past, -> { where("end_date < ?", Date.current) } scope :published, -> { where(published: true) } diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 98b1c4ff5..56f614850 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -440,7 +440,7 @@ en: delete: Delete title: Legislation processes filters: - open: Open + active: Active all: All new: back: Back diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index fd265b345..29a7b1827 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -440,7 +440,7 @@ es: delete: Borrar title: Procesos de legislación colaborativa filters: - open: Abiertos + active: Activos all: Todos new: back: Volver diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index dde769291..038a365bd 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -29,10 +29,24 @@ feature "Admin legislation processes" do context "Index" do scenario "Displaying legislation processes" do - process = create(:legislation_process) + process_1 = create(:legislation_process, title: "Process open") + process_2 = create(:legislation_process, title: "Process for the future", + start_date: Date.current + 5.days) + process_3 = create(:legislation_process, title: "Process closed", + start_date: Date.current - 10.days, + end_date: Date.current - 6.days) + + visit admin_legislation_processes_path(filter: "active") + + expect(page).to have_content(process_1.title) + expect(page).to have_content(process_2.title) + expect(page).not_to have_content(process_3.title) + visit admin_legislation_processes_path(filter: "all") - expect(page).to have_content(process.title) + expect(page).to have_content(process_1.title) + expect(page).to have_content(process_2.title) + expect(page).to have_content(process_3.title) end scenario "Processes are sorted by descending start date" do