Collaborative legislation summary
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -57,6 +57,8 @@ gem "whenever", "~> 0.10.0", require: false
|
||||
gem "recipient_interceptor", "~> 0.2.0"
|
||||
gem "wkhtmltopdf-binary", "~> 0.12.4"
|
||||
gem "wicked_pdf", "~> 1.1.0"
|
||||
gem "axlsx", "~> 3.0.0.pre"
|
||||
gem "axlsx_rails", "~> 0.5.2"
|
||||
|
||||
source "https://rails-assets.org" do
|
||||
gem "rails-assets-leaflet"
|
||||
|
||||
10
Gemfile.lock
10
Gemfile.lock
@@ -74,6 +74,14 @@ GEM
|
||||
ast (2.4.0)
|
||||
autoprefixer-rails (8.2.0)
|
||||
execjs
|
||||
axlsx (3.0.0.pre)
|
||||
htmlentities (~> 4.3, >= 4.3.4)
|
||||
mimemagic (~> 0.3)
|
||||
nokogiri (~> 1.8, >= 1.8.2)
|
||||
rubyzip (~> 1.2, >= 1.2.1)
|
||||
axlsx_rails (0.5.2)
|
||||
actionpack (>= 3.1)
|
||||
axlsx (>= 2.0.1)
|
||||
babel-source (5.8.35)
|
||||
babel-transpiler (0.7.0)
|
||||
babel-source (>= 4.0, < 6)
|
||||
@@ -531,6 +539,8 @@ DEPENDENCIES
|
||||
ahoy_matey (~> 1.6.0)
|
||||
ancestry (~> 3.0.2)
|
||||
autoprefixer-rails (~> 8.2.0)
|
||||
axlsx (~> 3.0.0.pre)
|
||||
axlsx_rails (~> 0.5.2)
|
||||
browser (~> 2.5.3)
|
||||
bullet (~> 5.7.0)
|
||||
byebug (~> 10.0.0)
|
||||
|
||||
@@ -1006,3 +1006,39 @@
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
// 10. Legislation resumes
|
||||
// -------------------------
|
||||
.resume_title {
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.panel_resume {
|
||||
margin-left: rem-calc(16);
|
||||
}
|
||||
|
||||
.question_title {
|
||||
margin-bottom: 1.5%;
|
||||
}
|
||||
|
||||
.comment_box {
|
||||
border-radius: rem-calc(10);
|
||||
padding: 1.5%;
|
||||
background-color: rgba(217, 216, 243, 0.2);
|
||||
margin-bottom: 1%;
|
||||
}
|
||||
|
||||
.centered_votes {
|
||||
padding: rem-calc(10);
|
||||
}
|
||||
|
||||
.annotation_text {
|
||||
border: 1px solid $black;
|
||||
padding: rem-calc(10);
|
||||
}
|
||||
|
||||
.download-button {
|
||||
position: absolute;
|
||||
margin-top: rem-calc(25);
|
||||
margin-left: 85%;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ class Legislation::ProcessesController < Legislation::BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_random_seed, only: :proposals
|
||||
before_action :check_past, only: :resume
|
||||
|
||||
|
||||
def index
|
||||
@current_filter ||= "open"
|
||||
@@ -97,6 +99,21 @@ class Legislation::ProcessesController < Legislation::BaseController
|
||||
@phase = :milestones
|
||||
end
|
||||
|
||||
def resume
|
||||
@phase = :resume
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xlsx {render xlsx: "resume_to_xlsx", filename: ("resume-" + Date.today.to_s + ".xlsx")}
|
||||
end
|
||||
end
|
||||
|
||||
def check_past
|
||||
set_process
|
||||
if !@process.past?
|
||||
redirect_to legislation_process_path
|
||||
end
|
||||
end
|
||||
|
||||
def proposals
|
||||
set_process
|
||||
@phase = :proposals_phase
|
||||
|
||||
@@ -25,6 +25,9 @@ module Abilities
|
||||
can :new, DirectMessage
|
||||
can [:read, :debate, :draft_publication, :allegations, :result_publication,
|
||||
:proposals, :milestones], Legislation::Process, published: true
|
||||
can :resume, Legislation::Process do |process|
|
||||
process.past?
|
||||
end
|
||||
can [:read, :changes, :go_to_version], Legislation::DraftVersion
|
||||
can [:read], Legislation::Question
|
||||
can [:read, :map, :share], Legislation::Proposal
|
||||
|
||||
@@ -58,6 +58,10 @@ class Legislation::Process < ApplicationRecord
|
||||
draft_end_date IS NOT NULL and (draft_start_date > ? or
|
||||
draft_end_date < ?))", Date.current, Date.current) }
|
||||
|
||||
def past?
|
||||
end_date < Date.current
|
||||
end
|
||||
|
||||
def homepage_phase
|
||||
Legislation::Process::Phase.new(start_date, end_date, homepage_enabled)
|
||||
end
|
||||
@@ -112,6 +116,20 @@ class Legislation::Process < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def get_last_draft_version
|
||||
Legislation::DraftVersion.where(process: self, status: "published").last
|
||||
end
|
||||
|
||||
def get_annotations_from_draft
|
||||
Legislation::Annotation.where(legislation_draft_version_id: get_last_draft_version)
|
||||
end
|
||||
|
||||
def get_best_annotation_comments
|
||||
Comment.where(commentable_id: get_annotations_from_draft,
|
||||
commentable_type: "Legislation::Annotation", ancestry: nil)
|
||||
.order("cached_votes_up - cached_votes_down DESC")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_date_ranges
|
||||
@@ -129,5 +147,4 @@ class Legislation::Process < ApplicationRecord
|
||||
errors.add(:allegations_end_date, :invalid_date_range)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -44,4 +44,11 @@ class Legislation::Question < ApplicationRecord
|
||||
def comments_open?
|
||||
process.debate_phase.open?
|
||||
end
|
||||
|
||||
def best_comments(number)
|
||||
Comment.where(commentable_id: id)
|
||||
.where(commentable_type: "Legislation::Question")
|
||||
.order("cached_votes_up - cached_votes_down DESC")
|
||||
.take(number)
|
||||
end
|
||||
end
|
||||
|
||||
23
app/views/legislation/processes/_debate_phase.html.erb
Normal file
23
app/views/legislation/processes/_debate_phase.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<div class="row">
|
||||
<div class="debate-chooser">
|
||||
<div class="resume_title small-12 medium-9 column">
|
||||
<h3><%= t("legislation.summary.debates_phase") %></h3>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<h3><%= t("legislation.questions.question.total", count: @process.questions.count) %></h3>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-11 column">
|
||||
<div class="debate-list">
|
||||
<% if @process.questions.empty? %>
|
||||
<div class="callout primary">
|
||||
<p><%= t("legislation.processes.debate.empty_questions") %></p>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= render "resume_questions", process: @process %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -52,6 +52,15 @@
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if process.result_publication.enabled? && process.end_date <= Date.today %>
|
||||
<li <%= "class=is-active" if phase == :resume %>>
|
||||
<%= link_to resume_legislation_process_path(process) do %>
|
||||
<h4><%= t("legislation.summary.title") %></h4>
|
||||
<span><%= format_date(process.result_publication_date) %></span>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
23
app/views/legislation/processes/_proposal_phase.html.erb
Normal file
23
app/views/legislation/processes/_proposal_phase.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<div class="row">
|
||||
<div class="debate-chooser">
|
||||
<div class="resume_title small-12 medium-9 column">
|
||||
<h3><%= t("legislation.summary.proposal_phase") %></h3>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<h3><%= t("legislation.proposals.total", count: Legislation::Proposal.where(legislation_process_id: @process).where(selected: true).count) %></h3>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-11 column">
|
||||
<div class="debate-list">
|
||||
<% if Legislation::Proposal.where(legislation_process_id: @process).where(selected: true).empty? %>
|
||||
<div class="callout primary">
|
||||
<p><%= t("legislation.processes.proposals.empty_proposals") %></p>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= render "resume_proposal", process: @process %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
17
app/views/legislation/processes/_resume_proposal.html.erb
Normal file
17
app/views/legislation/processes/_resume_proposal.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<% Legislation::Proposal.where(legislation_process_id: @process)
|
||||
.where(selected: true).order('cached_votes_score desc').each do |proposal| %>
|
||||
<div class="row">
|
||||
<div class="proposal">
|
||||
<div class="panel panel_resume" style="min-height: 5rem;">
|
||||
<div class="small-12 medium-9 column">
|
||||
<h3>
|
||||
<%= link_to proposal.title, legislation_process_proposal_path(proposal.legislation_process_id, proposal) %>
|
||||
</h3>
|
||||
</div>
|
||||
<div id="<%= dom_id(proposal) %>_votes" class="small-12 medium-3 column">
|
||||
<p class="centered_votes"> <%= proposal.cached_votes_total - proposal.cached_votes_down %> <%= t("legislation.summary.votes") %> </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
34
app/views/legislation/processes/_resume_questions.html.erb
Normal file
34
app/views/legislation/processes/_resume_questions.html.erb
Normal file
@@ -0,0 +1,34 @@
|
||||
<% @process.questions.each do |question| %>
|
||||
<div class="row">
|
||||
<div class="proposal">
|
||||
<div class="panel panel_resume" style="min-height: 5rem;">
|
||||
<div class="row question_title">
|
||||
<div class="small-12 medium-9 column">
|
||||
<div>
|
||||
<h4><%= link_to question.title, legislation_process_question_path(question.process, question) %></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div id="<%= dom_id(question) %>_votes" class="small-12 medium-3 column">
|
||||
<span class="icon-comments" aria-hidden="true"></span>
|
||||
<span class="debate-comments">
|
||||
<%= link_to t("legislation.summary.comments", count: question.comments.count), legislation_process_question_path(question.process, question) %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% if question.comments.count > 0 %>
|
||||
<span><%= t("legislation.summary.most_voted_comments") %> </span>
|
||||
<% end %>
|
||||
<div class="row">
|
||||
<% question.best_comments(3).each do |comment| %>
|
||||
<div class="small-12 medium-9 column">
|
||||
<p class="comment_box"> <%= link_to comment.body, comment_path(comment) %></p>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<p class="centered_votes"> <%= comment.cached_votes_up - comment.cached_votes_down %> <%= t("legislation.summary.votes") %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
29
app/views/legislation/processes/_resume_text.html.erb
Normal file
29
app/views/legislation/processes/_resume_text.html.erb
Normal file
@@ -0,0 +1,29 @@
|
||||
<% @process.get_best_annotation_comments.take(10).each do |comment| %>
|
||||
<div class="row">
|
||||
<div class="proposal">
|
||||
<div class="panel panel_resume" style="min-height: 5rem;">
|
||||
<div class="row">
|
||||
<div class="small-12 medium-9 column">
|
||||
<span><%= t("legislation.annotations.index.comment_about") %> </span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row question_title">
|
||||
<div class="small-12 medium-9 column">
|
||||
<div class="annotation_text question_title">
|
||||
<span> "<%= Legislation::Annotation.find_by(id: comment.commentable_id).quote %>" </span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<span> <%= comment.cached_votes_up - comment.cached_votes_down %> <%= t("legislation.summary.votes") %> </span>
|
||||
</div>
|
||||
</div>
|
||||
<span><%= t("legislation.annotations.show.title") %>:</span>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-9 column">
|
||||
<p class="comment_box"> <%= link_to comment.body, comment_path(comment) %></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
32
app/views/legislation/processes/_text_comment_phase.html.erb
Normal file
32
app/views/legislation/processes/_text_comment_phase.html.erb
Normal file
@@ -0,0 +1,32 @@
|
||||
<div class="row">
|
||||
<div class="debate-chooser">
|
||||
<div class="small-12 medium-9 column resume_title">
|
||||
<h3><%= t("legislation.summary.comments_phase") %>
|
||||
<% if !@process.get_last_draft_version.nil? %>
|
||||
(<%= t("legislation.summary.version") %> <%= @process.get_last_draft_version.title %>)</h3>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<h3><%= t("legislation.annotations.index.comments_count", count: @process.get_best_annotation_comments.count) %></h3>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-11 column">
|
||||
<div class="debate-list">
|
||||
<% if !@process.get_last_draft_version.nil? %>
|
||||
<% if @process.get_last_draft_version.annotations.empty? %>
|
||||
<div class="callout primary">
|
||||
<p><%= t("legislation.summary.no_allegation") %></p>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= render "resume_text", process: @process %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="callout primary">
|
||||
<p><%= t("legislation.summary.no_allegation") %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
28
app/views/legislation/processes/resume.html.erb
Normal file
28
app/views/legislation/processes/resume.html.erb
Normal file
@@ -0,0 +1,28 @@
|
||||
<% provide(:title) {@process.title} %>
|
||||
|
||||
<%= render "legislation/processes/header", process: @process, header: :full %>
|
||||
|
||||
<%= render "key_dates", process: @process, phase: @phase %>
|
||||
|
||||
<% if !@process.debate_phase.enabled? && !@process.proposals_phase.enabled? && !@process.allegations_phase.enabled? %>
|
||||
<div class="callout primary">
|
||||
<p><%= t("legislation.summary.process_empty") %></p>
|
||||
</div>
|
||||
<% else %>
|
||||
<button class="button hollow download-button">
|
||||
<%= link_to 'Download', resume_legislation_process_path(format: :xlsx) %>
|
||||
</button>
|
||||
|
||||
<% if @process.debate_phase.enabled? %>
|
||||
<%= render "debate_phase", process: @process %>
|
||||
<% end %>
|
||||
|
||||
<% if @process.proposals_phase.enabled? %>
|
||||
<%= render "proposal_phase", process: @process %>
|
||||
<% end %>
|
||||
|
||||
<% if @process.allegations_phase.enabled? %>
|
||||
<%= render "text_comment_phase", process: @process %>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
37
app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx
Normal file
37
app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx
Normal file
@@ -0,0 +1,37 @@
|
||||
wb = xlsx_package.workbook
|
||||
space = " "
|
||||
wb.add_worksheet(name: "Resume") do |sheet|
|
||||
if @process.debate_phase.enabled? && !@process.questions.empty?
|
||||
sheet.add_row [t("legislation.summary.debates_phase"), t("legislation.questions.question.total", count: @process.questions.count)]
|
||||
@process.questions.each do |question|
|
||||
sheet.add_row [question.title, t("legislation.summary.comments", count: question.comments.count)]
|
||||
sheet.add_hyperlink :location => legislation_process_question_url(question.process, question), :ref => sheet.rows.last.cells.first
|
||||
question.best_comments(3).each do |comment|
|
||||
sheet.add_row [comment.body, (comment.cached_votes_up - comment.cached_votes_down).to_s + space +t("legislation.summary.votes")]
|
||||
sheet.add_hyperlink :location => comment_url(comment), :ref => sheet.rows.last.cells.first
|
||||
end
|
||||
sheet.add_row ["",""]
|
||||
end
|
||||
end
|
||||
|
||||
if @process.proposals_phase.enabled? && !Legislation::Proposal.where(legislation_process_id: @process).where(selected: true).empty?
|
||||
sheet.add_row [t("legislation.summary.proposal_phase"), t("legislation.proposals.total", count: Legislation::Proposal.where(legislation_process_id: @process).where(selected: true).count)]
|
||||
Legislation::Proposal.where(legislation_process_id: @process).where(selected: true).order('cached_votes_score desc').each do |proposal|
|
||||
sheet.add_row [proposal.title,
|
||||
(proposal.cached_votes_total - proposal.cached_votes_down).to_s + space + t("legislation.summary.votes")]
|
||||
sheet.add_hyperlink :location => legislation_process_proposal_url(proposal.legislation_process_id, proposal), :ref => sheet.rows.last.cells.first
|
||||
end
|
||||
sheet.add_row ["",""]
|
||||
end
|
||||
|
||||
if @process.allegations_phase.enabled? && !@process.get_last_draft_version.nil? && !@process.get_last_draft_version.annotations.empty?
|
||||
sheet.add_row [t("legislation.summary.comments_phase")+" ("+t("legislation.summary.version")+@process.get_last_draft_version.title+")",
|
||||
t("legislation.annotations.index.comments_count", count: @process.get_best_annotation_comments.count)]
|
||||
@process.get_best_annotation_comments.take(10).each do |comment|
|
||||
sheet.add_row [Legislation::Annotation.find_by(id: comment.commentable_id).quote,""]
|
||||
sheet.add_row [comment.body, (comment.cached_votes_up - comment.cached_votes_down).to_s + space + t("legislation.summary.votes")]
|
||||
sheet.add_hyperlink :location => comment_url(comment), :ref => sheet.rows.last.cells.first
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -20,8 +20,10 @@ en:
|
||||
index:
|
||||
title: Comments
|
||||
comments_about: Comments about
|
||||
comment_about: "Comment about:"
|
||||
see_in_context: See in context
|
||||
comments_count:
|
||||
zero: No comments
|
||||
one: "%{count} comment"
|
||||
other: "%{count} comments"
|
||||
show:
|
||||
@@ -96,6 +98,10 @@ en:
|
||||
form:
|
||||
leave_comment: Leave your answer
|
||||
question:
|
||||
total:
|
||||
zero: No debates
|
||||
one: "%{count} debate"
|
||||
other: "%{count} debates"
|
||||
comments:
|
||||
zero: No comments
|
||||
one: "%{count} comment"
|
||||
@@ -124,3 +130,21 @@ en:
|
||||
tags_label: "Categories"
|
||||
not_verified: "For vote proposals %{verify_account}."
|
||||
process_title: Collaborative legislation process
|
||||
total:
|
||||
zero: No proposals
|
||||
one: "%{count} proposal"
|
||||
other: "%{count} proposals"
|
||||
summary:
|
||||
title: Resume
|
||||
votes: votes
|
||||
debates_phase: Debates phase
|
||||
proposal_phase: Proposal phase
|
||||
comments_phase: Text comment phase
|
||||
comments:
|
||||
zero: No comments
|
||||
one: "%{count} comment"
|
||||
other: "%{count} comments"
|
||||
most_voted_comments: "Most voted comments: "
|
||||
no_allegation: There are no text comments
|
||||
version: version
|
||||
process_empty: The process have no phases.
|
||||
|
||||
@@ -20,6 +20,7 @@ es:
|
||||
index:
|
||||
title: Comentarios
|
||||
comments_about: Comentarios sobre
|
||||
comment_about: "Comentario sobre:"
|
||||
see_in_context: Ver en contexto
|
||||
comments_count:
|
||||
one: "%{count} comentario"
|
||||
@@ -96,6 +97,10 @@ es:
|
||||
form:
|
||||
leave_comment: Deja tu respuesta
|
||||
question:
|
||||
total:
|
||||
zero: No hay debates
|
||||
one: "%{count} debate"
|
||||
other: "%{count} debates"
|
||||
comments:
|
||||
zero: Sin comentarios
|
||||
one: "%{count} comentario"
|
||||
@@ -124,3 +129,21 @@ es:
|
||||
tags_label: "Categorías"
|
||||
not_verified: "Para votar propuestas %{verify_account}."
|
||||
process_title: Proceso de legislación colaborativa
|
||||
total:
|
||||
zero: No hay propuestas
|
||||
one: "%{count} propuesta"
|
||||
other: "%{count} propuestas"
|
||||
summary:
|
||||
title: Resumen
|
||||
votes: votos
|
||||
debates_phase: Fase de debates
|
||||
proposal_phase: Fase de propuestas
|
||||
comments_phase: Fase de comentarios de texto
|
||||
comments:
|
||||
zero: No hay comentarios
|
||||
one: "%{count} comentario"
|
||||
other: "%{count} comentarios"
|
||||
most_voted_comments: "Comentarios más votados:"
|
||||
no_allegation: No hay comentarios de texto.
|
||||
version: versión
|
||||
process_empty: The proces have no phases.
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace :legislation do
|
||||
get :result_publication
|
||||
get :proposals
|
||||
get :milestones
|
||||
get :resume
|
||||
|
||||
end
|
||||
|
||||
resources :questions, only: [:show] do
|
||||
|
||||
@@ -162,4 +162,28 @@ LOREM_IPSUM
|
||||
process factory: :legislation_process
|
||||
author factory: :user
|
||||
end
|
||||
|
||||
factory :debate_comment, class: "Comment" do
|
||||
commentable_id "10"
|
||||
commentable_type Legislation::Question
|
||||
body "This is a comment"
|
||||
user_id "1"
|
||||
cached_votes_down "0"
|
||||
cached_votes_total "0"
|
||||
cached_votes_up "0"
|
||||
confidence_score "0"
|
||||
end
|
||||
|
||||
factory :text_comment, class: "Comment" do
|
||||
commentable_id "10"
|
||||
commentable_type Legislation::Annotation
|
||||
body "This is a comment"
|
||||
user_id "1"
|
||||
cached_votes_down "0"
|
||||
cached_votes_total "0"
|
||||
cached_votes_up "0"
|
||||
confidence_score "0"
|
||||
ancestry nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
248
spec/features/legislation/resume_spec.rb
Normal file
248
spec/features/legislation/resume_spec.rb
Normal file
@@ -0,0 +1,248 @@
|
||||
require "rails_helper"
|
||||
|
||||
feature "Legislation" do
|
||||
context "process resume page" do
|
||||
|
||||
scenario "resume tab not show" do
|
||||
process = create(:legislation_process, :open)
|
||||
visit legislation_process_path(process)
|
||||
expect(page).not_to have_content("Resume")
|
||||
end
|
||||
|
||||
scenario "resume tab show" do
|
||||
process = create(:legislation_process, :past)
|
||||
visit legislation_process_path(process)
|
||||
expect(page).to have_content("Resume")
|
||||
end
|
||||
end
|
||||
|
||||
context "process empty" do
|
||||
before do
|
||||
@process = create(:legislation_process, :empty, end_date: Date.current - 1.days)
|
||||
end
|
||||
|
||||
scenario "warning empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("The process have no phases.")
|
||||
end
|
||||
end
|
||||
|
||||
context "phases empty" do
|
||||
before do
|
||||
@process = create(:legislation_process, end_date: Date.current - 1.days)
|
||||
end
|
||||
|
||||
scenario "debates empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Debates phase")
|
||||
expect(page).to have_content("No debates")
|
||||
expect(page).to have_content("There aren't any questions")
|
||||
end
|
||||
|
||||
scenario "proposals empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Proposal phase")
|
||||
expect(page).to have_content("No proposals")
|
||||
expect(page).to have_content("There are no proposals")
|
||||
end
|
||||
|
||||
scenario "text comments empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Text comment phase")
|
||||
expect(page).to have_content("No comments")
|
||||
expect(page).to have_content("There are no text comments")
|
||||
end
|
||||
end
|
||||
|
||||
context "process empty" do
|
||||
before do
|
||||
@process = create(:legislation_process, :empty, end_date: Date.current - 1.days)
|
||||
end
|
||||
|
||||
scenario "warning empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("The process have no phases.")
|
||||
end
|
||||
end
|
||||
|
||||
context "only debates exist" do
|
||||
before do
|
||||
user = create(:user, :level_two)
|
||||
@process = create(:legislation_process, end_date: Date.current - 1.days)
|
||||
@debate = create(:legislation_question, process: @process, title: "Question 1")
|
||||
create(:debate_comment, user: user, commentable_id: @debate.id, body: "Answer 1")
|
||||
create(:debate_comment, user: user, commentable_id: @debate.id, body: "Answer 2")
|
||||
@debate = create(:legislation_question, process: @process, title: "Question 2")
|
||||
create(:debate_comment, user: user, commentable_id: @debate.id, body: "Answer 3")
|
||||
create(:debate_comment, user: user, commentable_id: @debate.id, body: "Answer 4")
|
||||
|
||||
|
||||
end
|
||||
|
||||
scenario "show debates list" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Debates phase")
|
||||
expect(page).to have_content("2 debates")
|
||||
|
||||
expect(page).to have_content("Question 1")
|
||||
expect(page).to have_content("Answer 1")
|
||||
expect(page).to have_content("Answer 2")
|
||||
expect(page).to have_content("Question 2")
|
||||
expect(page).to have_content("Answer 3")
|
||||
expect(page).to have_content("Answer 4")
|
||||
|
||||
click_link "Question 1"
|
||||
expect(page).to have_content("Question 1")
|
||||
expect(page).to have_content("Answer 1")
|
||||
expect(page).to have_content("Answer 2")
|
||||
expect(page).not_to have_content("Answer 3")
|
||||
expect(page).not_to have_content("Answer 4")
|
||||
|
||||
visit resume_legislation_process_path(@process)
|
||||
click_link "Question 2"
|
||||
expect(page).to have_content("Question 2")
|
||||
expect(page).not_to have_content("Answer 1")
|
||||
expect(page).not_to have_content("Answer 2")
|
||||
expect(page).to have_content("Answer 3")
|
||||
expect(page).to have_content("Answer 4")
|
||||
|
||||
end
|
||||
|
||||
scenario "proposals empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Proposal phase")
|
||||
expect(page).to have_content("No proposals")
|
||||
expect(page).to have_content("There are no proposals")
|
||||
end
|
||||
|
||||
scenario "text comments empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Text comment phase")
|
||||
expect(page).to have_content("No comments")
|
||||
expect(page).to have_content("There are no text comments")
|
||||
end
|
||||
end
|
||||
|
||||
context "only proposals exist" do
|
||||
before do
|
||||
@process = create(:legislation_process, end_date: Date.current - 1.days)
|
||||
create(:legislation_proposal, legislation_process_id: @process.id,
|
||||
title: "Legislation proposal 1", selected: true)
|
||||
create(:legislation_proposal, legislation_process_id: @process.id,
|
||||
title: "Legislation proposal 2", selected: false)
|
||||
create(:legislation_proposal, legislation_process_id: @process.id,
|
||||
title: "Legislation proposal 3", selected: true)
|
||||
create(:legislation_proposal, legislation_process_id: @process.id,
|
||||
title: "Legislation proposal 4", selected: false)
|
||||
end
|
||||
|
||||
scenario "debates empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Debates phase")
|
||||
expect(page).to have_content("No debates")
|
||||
expect(page).to have_content("There aren't any questions")
|
||||
end
|
||||
|
||||
scenario "proposals empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Proposal phase")
|
||||
expect(page).to have_content("2 proposals")
|
||||
|
||||
expect(page).to have_content("Legislation proposal 1")
|
||||
expect(page).not_to have_content("Legislation proposal 2")
|
||||
expect(page).to have_content("Legislation proposal 3")
|
||||
expect(page).not_to have_content("Legislation proposal 4")
|
||||
|
||||
click_link "Legislation proposal 1"
|
||||
expect(page).to have_content("Legislation proposal 1")
|
||||
|
||||
visit resume_legislation_process_path(@process)
|
||||
click_link "Legislation proposal 3"
|
||||
expect(page).to have_content("Legislation proposal 3")
|
||||
|
||||
end
|
||||
|
||||
scenario "text comments empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Text comment phase")
|
||||
expect(page).to have_content("No comments")
|
||||
expect(page).to have_content("There are no text comments")
|
||||
end
|
||||
end
|
||||
|
||||
context "only text comments exist" do
|
||||
before do
|
||||
user = create(:user, :level_two)
|
||||
@process = create(:legislation_process, end_date: Date.current - 1.days)
|
||||
draft_version_1 = create(:legislation_draft_version, process: @process,
|
||||
title: "Version 1", body: "Body of the first version",
|
||||
status: "published")
|
||||
draft_version_2 = create(:legislation_draft_version, process: @process,
|
||||
title: "Version 2", body: "Body of the second version and that's it all of it",
|
||||
status: "published")
|
||||
annotation0 = create(:legislation_annotation,
|
||||
draft_version: draft_version_1, text: "my annotation123",
|
||||
ranges: [{"start" => "/p[1]", "startOffset" => 5, "end" => "/p[1]", "endOffset" => 10}])
|
||||
annotation1 = create(:legislation_annotation,
|
||||
draft_version: draft_version_2, text: "hola",
|
||||
ranges: [{"start" => "/p[1]", "startOffset" => 5, "end" => "/p[1]", "endOffset" => 10}])
|
||||
annotation2 = create(:legislation_annotation,
|
||||
draft_version: draft_version_2,
|
||||
ranges: [{"start" => "/p[1]", "startOffset" => 12, "end" => "/p[1]", "endOffset" => 19}])
|
||||
create(:text_comment, user: user, commentable_id: annotation0.id, body: "Comment 0")
|
||||
create(:text_comment, user: user, commentable_id: annotation1.id, body: "Comment 1")
|
||||
create(:text_comment, user: user, commentable_id: annotation2.id, body: "Comment 2")
|
||||
create(:text_comment, user: user, commentable_id: annotation2.id, body: "Comment 3")
|
||||
end
|
||||
|
||||
scenario "debates empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Debates phase")
|
||||
expect(page).to have_content("No debates")
|
||||
expect(page).to have_content("There aren't any questions")
|
||||
end
|
||||
|
||||
scenario "proposals empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Proposal phase")
|
||||
expect(page).to have_content("No proposals")
|
||||
expect(page).to have_content("There are no proposals")
|
||||
end
|
||||
|
||||
scenario "text comments empty" do
|
||||
visit resume_legislation_process_path(@process)
|
||||
expect(page).to have_content("Text comment phase (version Version 2")
|
||||
expect(page).to have_content("5 comments")
|
||||
expect(page).not_to have_content("Comment 0")
|
||||
expect(page).to have_content("Comment 1")
|
||||
expect(page).to have_content("Comment 2")
|
||||
expect(page).to have_content("Comment 3")
|
||||
|
||||
click_link "Comment 2"
|
||||
expect(page).to have_content("Comment 2")
|
||||
end
|
||||
|
||||
# scenario "excel download" do
|
||||
# visit resume_legislation_process_path(@process)
|
||||
# click_link "Download"
|
||||
# page.response_headers['Content-Type'].should eq "application/xlsx"
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
describe Legislation::ProcessesController, type: :controller do
|
||||
before do
|
||||
user = create(:user, :level_two)
|
||||
@process = create(:legislation_process, end_date: Date.current - 1.days)
|
||||
@debate = create(:legislation_question, process: @process, title: "Question 1")
|
||||
create(:debate_comment, user: user, commentable_id: @debate.id, body: "Answer 1")
|
||||
create(:debate_comment, user: user, commentable_id: @debate.id, body: "Answer 2")
|
||||
end
|
||||
|
||||
it "download execl file test" do
|
||||
get :resume, params: {id: @process, format: :xlsx}
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user