Replace open to active filter on admin legislation processes index

Now active filter show open processes and the next ones, processes with a start date greather than current date.
This commit is contained in:
decabeza
2019-02-14 16:11:37 +01:00
parent a9d96f7e23
commit 0d834744fd
5 changed files with 20 additions and 5 deletions

View File

@@ -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"

View File

@@ -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) }

View File

@@ -440,7 +440,7 @@ en:
delete: Delete
title: Legislation processes
filters:
open: Open
active: Active
all: All
new:
back: Back

View File

@@ -440,7 +440,7 @@ es:
delete: Borrar
title: Procesos de legislación colaborativa
filters:
open: Abiertos
active: Activos
all: Todos
new:
back: Volver

View File

@@ -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