Merge pull request #1652 from consul/feature/1588#legislative_process_active_dates

Legislation Process Date display & Enabling/Disabling
This commit is contained in:
Raimond Garcia
2017-06-14 11:41:18 +02:00
committed by GitHub
15 changed files with 117 additions and 51 deletions

View File

@@ -45,7 +45,11 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
:draft_publication_date,
:allegations_start_date,
:allegations_end_date,
:result_publication_date
:result_publication_date,
:debate_phase_enabled,
:allegations_phase_enabled,
:draft_publication_enabled,
:result_publication_enabled
)
end
end

View File

@@ -2,6 +2,8 @@ class Legislation::Process < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase draft_publication result_publication).freeze
has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id', dependent: :destroy
has_one :final_draft_version, -> { where final_version: true, status: 'published' }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id'
has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id', dependent: :destroy
@@ -20,19 +22,23 @@ class Legislation::Process < ActiveRecord::Base
scope :past, -> { where("end_date < ?", Date.current).order('id DESC') }
def debate_phase
Legislation::Process::Phase.new(debate_start_date, debate_end_date)
Legislation::Process::Phase.new(debate_start_date, debate_end_date, debate_phase_enabled)
end
def allegations_phase
Legislation::Process::Phase.new(allegations_start_date, allegations_end_date)
Legislation::Process::Phase.new(allegations_start_date, allegations_end_date, allegations_phase_enabled)
end
def draft_publication
Legislation::Process::Publication.new(draft_publication_date)
Legislation::Process::Publication.new(draft_publication_date, draft_publication_enabled)
end
def result_publication
Legislation::Process::Publication.new(result_publication_date)
Legislation::Process::Publication.new(result_publication_date, result_publication_enabled)
end
def enabled_phases_and_publications_count
PHASES_AND_PUBLICATIONS.count { |process| send(process).enabled? }
end
def total_comments

View File

@@ -2,13 +2,14 @@
class Legislation::Process::Phase
def initialize(start_date, end_date)
def initialize(start_date, end_date, enabled)
@start_date = start_date
@end_date = end_date
@enabled = enabled
end
def enabled?
@start_date.present? && @end_date.present?
@enabled
end
def started?

View File

@@ -2,12 +2,13 @@
class Legislation::Process::Publication
def initialize(publication_date)
def initialize(publication_date, enabled)
@publication_date = publication_date
@enabled = enabled
end
def enabled?
@publication_date.present?
@enabled
end
def started?

View File

@@ -70,8 +70,7 @@
id: "debate_end_date" %>
</div>
<div class="small-12 medium-2 column">
<%= check_box_tag :debate_phase_active, @process.debate_phase.enabled?, @process.new_record? || @process.debate_phase.enabled?, data: {disable_date: "debate"} %>
<%= label_tag :debate_phase_active, t('admin.legislation.processes.form.active') %>
<%= f.check_box :debate_phase_enabled, checked: @process.debate_phase.enabled?, label: t('admin.legislation.processes.form.enabled') %>
</div>
<div class="small-12 column">
@@ -104,8 +103,7 @@
id: "allegations_end_date" %>
</div>
<div class="small-12 medium-2 column">
<%= check_box_tag :allegations_phase_active, @process.allegations_phase.enabled?, @process.new_record? || @process.allegations_phase.enabled?, data: {disable_date: "allegations"} %>
<%= label_tag :allegations_phase_active, t('admin.legislation.processes.form.active') %>
<%= f.check_box :allegations_phase_enabled, checked: @process.allegations_phase.enabled?, label: t('admin.legislation.processes.form.enabled') %>
</div>
<div class="small-12 column">
@@ -125,8 +123,7 @@
id: "draft_publication_date" %>
</div>
<div class="small-12 medium-2 column">
<%= check_box_tag :draft_publication_phase_active, @process.draft_publication.enabled?, @process.new_record? || @process.draft_publication.enabled?, data: {disable_date: "draft_publication"} %>
<%= label_tag :draft_publication_phase_active, t('admin.legislation.processes.form.active') %>
<%= f.check_box :draft_publication_enabled, checked: @process.draft_publication.enabled?, label: t('admin.legislation.processes.form.enabled') %>
</div>
<div class="small-12 column">
<hr>
@@ -145,8 +142,7 @@
id: "result_publication_date" %>
</div>
<div class="small-12 medium-2 column">
<%= check_box_tag :result_publication_phase_active, @process.result_publication.enabled?, @process.new_record? || @process.result_publication.enabled?, data: {disable_date: "final_publication"} %>
<%= label_tag :result_publication_phase_active, t('admin.legislation.processes.form.active') %>
<%= f.check_box :result_publication_enabled, checked: @process.result_publication.enabled?, label: t('admin.legislation.processes.form.enabled') %>
</div>
<div class="small-12 column">
<hr>

View File

@@ -17,28 +17,42 @@
</div>
</div>
<div class="column row">
<div class="small-12 column legislation-calendar-info">
<p><%= t('legislation.processes.shared.key_dates') %></p>
<% if process.enabled_phases_and_publications_count.positive? %>
<% column_width = 12 / process.enabled_phases_and_publications_count %>
<div class="column row">
<div class="small-12 column legislation-calendar-info">
<p><%= t('legislation.processes.shared.key_dates') %></p>
</div>
</div>
</div>
<div class="column row small-collapse medium-uncollapse legislation-calendar">
<div class="small-6 medium-3 column">
<h5><%= t('legislation.processes.shared.debate_dates') %></h5>
<p><%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %></p>
<div class="column row small-collapse medium-uncollapse legislation-calendar">
<% if process.debate_phase.enabled? %>
<div class="small-6 medium-<%= column_width %> column">
<h5><%= t('legislation.processes.shared.debate_dates') %></h5>
<p><%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %></p>
</div>
<% end %>
<% if process.draft_publication.enabled? %>
<div class="small-6 medium-<%= column_width %> column">
<h5><%= t('legislation.processes.shared.draft_publication_date') %></h5>
<p><%= format_date(process.draft_publication_date) %></p>
</div>
<% end %>
<% if process.allegations_phase.enabled? %>
<div class="small-6 medium-<%= column_width %> column">
<h5><%= t('legislation.processes.shared.allegations_dates') %></h5>
<p><%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %></p>
</div>
<% end %>
<% if process.result_publication.enabled? %>
<div class="small-6 medium-<%= column_width %> column">
<h5><%= t('legislation.processes.shared.result_publication_date') %></h5>
<p><%= format_date(process.result_publication_date) %></p>
</div>
<% end %>
</div>
<div class="small-6 medium-3 column">
<h5><%= t('legislation.processes.shared.draft_publication_date') %></h5>
<p><%= format_date(process.draft_publication_date) %></p>
</div>
<div class="small-6 medium-3 column">
<h5><%= t('legislation.processes.shared.allegations_dates') %></h5>
<p><%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %></p>
</div>
<div class="small-6 medium-3 column">
<h5><%= t('legislation.processes.shared.result_publication_date') %></h5>
<p><%= format_date(process.result_publication_date) %></p>
</div>
</div>
<% end %>
</div>

View File

@@ -211,7 +211,7 @@ en:
form:
error: Error
form:
active: Active
enabled: Enabled
process: Process
debate_phase: Debate phase
allegations_phase: Allegations phase

View File

@@ -211,7 +211,7 @@ es:
form:
error: Error
form:
active: Activa
enabled: Habilitado
process: Proceso
debate_phase: Fase previa
allegations_phase: Fase de alegaciones

View File

@@ -643,7 +643,11 @@ print "Creating legislation processes"
draft_publication_date: Date.current + 1.day,
allegations_start_date: Date.current + 2.days,
allegations_end_date: Date.current + 3.days,
result_publication_date: Date.current + 4.days
result_publication_date: Date.current + 4.days,
debate_phase_enabled: true,
allegations_phase_enabled: true,
draft_publication_enabled: true,
result_publication_enabled: true
)
end

View File

@@ -0,0 +1,8 @@
class AddPhasePubEnabledStatusToLegislativeProcess < ActiveRecord::Migration
def change
add_column :legislation_processes, :debate_phase_enabled, :boolean, default: false
add_column :legislation_processes, :allegations_phase_enabled, :boolean, default: false
add_column :legislation_processes, :draft_publication_enabled, :boolean, default: false
add_column :legislation_processes, :result_publication_enabled, :boolean, default: false
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170613174317) do
ActiveRecord::Schema.define(version: 20170613203256) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -417,6 +417,10 @@ ActiveRecord::Schema.define(version: 20170613174317) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "summary"
t.boolean "debate_phase_enabled", default: false
t.boolean "allegations_phase_enabled", default: false
t.boolean "draft_publication_enabled", default: false
t.boolean "result_publication_enabled", default: false
end
add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree

View File

@@ -612,6 +612,10 @@ FactoryGirl.define do
allegations_start_date Date.current
allegations_end_date Date.current + 3.days
result_publication_date Date.current + 5.days
debate_phase_enabled true
allegations_phase_enabled true
draft_publication_enabled true
result_publication_enabled true
trait :next do
start_date Date.current + 2.days

View File

@@ -73,7 +73,7 @@ feature 'Admin legislation processes' do
end
context 'Update' do
scenario 'Deactivate debate phase', js: true do
scenario 'Remove summary text', js: true do
process = create(:legislation_process,
title: 'An example legislation process',
summary: 'Summarizing the process',
@@ -87,19 +87,43 @@ feature 'Admin legislation processes' do
click_link "An example legislation process"
expect(page).to have_selector("h2", text: "An example legislation process")
expect(find("#debate_phase_active")).to be_checked
expect(find("#legislation_process_debate_phase_enabled")).to be_checked
uncheck "debate_phase_active"
fill_in 'legislation_process_summary', with: ''
click_button "Save changes"
expect(page).to have_content "Process updated successfully"
expect(find("#debate_start_date").value).to be_blank
expect(find("#debate_end_date").value).to be_blank
visit legislation_processes_path
expect(page).not_to have_content 'Summarizing the process'
expect(page).to have_content 'Description of the process'
end
scenario 'Deactivate draft publication', js: true do
process = create(:legislation_process,
title: 'An example legislation process',
summary: 'Summarizing the process',
description: 'Description of the process')
visit admin_root_path
within('#side_menu') do
click_link "Collaborative Legislation"
end
click_link "An example legislation process"
expect(find("#legislation_process_draft_publication_enabled")).to be_checked
uncheck "legislation_process_draft_publication_enabled"
click_button "Save changes"
expect(page).to have_content "Process updated successfully"
expect(find("#debate_start_date").value).not_to be_blank
expect(find("#debate_end_date").value).not_to be_blank
click_link 'Click to visit'
expect(page).not_to have_content 'Draft publication'
end
end
end

View File

@@ -7,14 +7,14 @@ RSpec.describe Legislation::Process::Phase, type: :model do
it "checks debate phase" do
expect(process.debate_phase.enabled?).to be true
process.update_attributes(debate_start_date: nil, debate_end_date: nil)
process.update_attributes(debate_phase_enabled: false)
expect(process.debate_phase.enabled?).to be false
end
it "checks allegations phase" do
expect(process.allegations_phase.enabled?).to be true
process.update_attributes(allegations_start_date: nil, allegations_end_date: nil)
process.update_attributes(allegations_phase_enabled: false)
expect(process.allegations_phase.enabled?).to be false
end
end

View File

@@ -7,14 +7,14 @@ RSpec.describe Legislation::Process::Publication, type: :model do
it "checks draft publication" do
expect(process.draft_publication.enabled?).to be true
process.update_attributes(draft_publication_date: nil)
process.update_attributes(draft_publication_enabled: false)
expect(process.draft_publication.enabled?).to be false
end
it "checks result publication" do
expect(process.result_publication.enabled?).to be true
process.update_attributes(result_publication_date: nil)
process.update_attributes(result_publication_enabled: false)
expect(process.result_publication.enabled?).to be false
end
end