Show creation date and status in admin list

This commit is contained in:
Fernando Blat
2017-01-05 10:22:40 +01:00
parent fba4c79d2a
commit 814cf9df56
5 changed files with 44 additions and 17 deletions

View File

@@ -59,6 +59,18 @@ class Legislation::Process < ActiveRecord::Base
questions.map(&:comments_count).sum
end
def status
today = Date.current
if today < start_date
:planned
elsif end_date < today
:closed
else
:open
end
end
private
def valid_date_ranges

View File

@@ -20,6 +20,8 @@
<thead>
<tr>
<th><%= t("admin.legislation.processes.process.title") %></th>
<th><%= t("admin.legislation.processes.process.status") %></th>
<th><%= t("admin.legislation.processes.process.creation_date") %></th>
<th><%= t("admin.legislation.processes.process.comments") %></th>
<th></th>
</tr>
@@ -30,6 +32,8 @@
<td class="small-12 medium-8">
<%= link_to process.title, edit_admin_legislation_process_path(process) %>
</td>
<td><%= t("admin.legislation.processes.process.status_#{process.status}") %></td>
<td><%= I18n.l process.created_at.to_date %></td>
<td><%= process.total_comments %></td>
<td>
<%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_path(process),

View File

@@ -113,6 +113,11 @@ en:
process:
title: Process
comments: Comments
status: Status
creation_date: Creation date
status_open: Open
status_closed: Closed
status_planned: Planned
subnav:
info: Information
draft_texts: Text

View File

@@ -111,6 +111,11 @@ es:
process:
title: Proceso
comments: Comentarios
status: Estado
creation_date: Fecha creación
status_open: Abierto
status_closed: Cerrado
status_planned: Próximamente
subnav:
info: Información
draft_texts: Texto

View File

@@ -1,10 +1,10 @@
require 'rails_helper'
RSpec.describe Legislation::Process, type: :model do
let(:legislation_process) { build(:legislation_process) }
let(:process) { create(:legislation_process) }
it "should be valid" do
expect(legislation_process).to be_valid
expect(process).to be_valid
end
describe "date ranges validations" do
@@ -76,8 +76,6 @@ RSpec.describe Legislation::Process, type: :model do
describe "#open_phase?" do
it "checks debate phase" do
process = create(:legislation_process)
# future
process.update_attributes(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days)
expect(process.open_phase?(:debate)).to be false
@@ -96,7 +94,6 @@ RSpec.describe Legislation::Process, type: :model do
end
it "checks allegations phase" do
process = create(:legislation_process)
# future
process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days)
@@ -116,8 +113,6 @@ RSpec.describe Legislation::Process, type: :model do
end
it "checks draft publication phase" do
process = create(:legislation_process)
# future
process.update_attributes(draft_publication_date: Date.current + 2.days)
expect(process.open_phase?(:draft_publication)).to be false
@@ -132,8 +127,6 @@ RSpec.describe Legislation::Process, type: :model do
end
it "checks final version publication phase" do
process = create(:legislation_process)
# future
process.update_attributes(final_publication_date: Date.current + 2.days)
expect(process.open_phase?(:final_version_publication)).to be false
@@ -150,8 +143,6 @@ RSpec.describe Legislation::Process, type: :model do
describe "#show_phase?" do
it "checks debate phase" do
process = create(:legislation_process)
# future
process.update_attributes(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days)
expect(process.show_phase?(:debate)).to be false
@@ -170,8 +161,6 @@ RSpec.describe Legislation::Process, type: :model do
end
it "checks allegations phase" do
process = create(:legislation_process)
# future
process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days)
expect(process.show_phase?(:allegations)).to be false
@@ -190,8 +179,6 @@ RSpec.describe Legislation::Process, type: :model do
end
it "checks draft publication phase" do
process = create(:legislation_process)
# future
process.update_attributes(draft_publication_date: Date.current + 2.days)
expect(process.show_phase?(:draft_publication)).to be false
@@ -206,8 +193,6 @@ RSpec.describe Legislation::Process, type: :model do
end
it "checks final version publication phase" do
process = create(:legislation_process)
# future
process.update_attributes(final_publication_date: Date.current + 2.days)
expect(process.show_phase?(:final_version_publication)).to be false
@@ -221,4 +206,20 @@ RSpec.describe Legislation::Process, type: :model do
expect(process.show_phase?(:final_version_publication)).to be true
end
end
describe "#status" do
it "should detect planned phase" do
process.update_attributes(start_date: Date.current + 2.days)
expect(process.status).to eq(:planned)
end
it "should detect closed phase" do
process.update_attributes(end_date: Date.current - 2.days)
expect(process.status).to eq(:closed)
end
it "should detect open phase" do
expect(process.status).to eq(:open)
end
end
end