diff --git a/Gemfile b/Gemfile index 1c04aea44..dc5e1a0e7 100644 --- a/Gemfile +++ b/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" diff --git a/Gemfile.lock b/Gemfile.lock index bef18a154..e90a4c4a0 100644 --- a/Gemfile.lock +++ b/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) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index cb4488004..a6e76b9b5 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -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%; +} diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 1d9f32c5f..791ad905d 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -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" @@ -20,7 +22,7 @@ class Legislation::ProcessesController < Legislation::BaseController if @process.homepage_enabled? && @process.homepage.present? render :show - elsif allegations_phase.enabled? && allegations_phase.started? && draft_version.present? + elsif allegations_phase.enabled? && allegations_phase.started? && draft_version.present? redirect_to legislation_process_draft_version_path(@process, draft_version) elsif @process.debate_phase.enabled? redirect_to debate_legislation_process_path(@process) @@ -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 diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 6cdc8b6c9..20f53f5f1 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -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 diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 3d2c72c27..60d103d49 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -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 diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 6c60eb9f3..91b542d4b 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -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 diff --git a/app/views/legislation/processes/_debate_phase.html.erb b/app/views/legislation/processes/_debate_phase.html.erb new file mode 100644 index 000000000..5c9efec04 --- /dev/null +++ b/app/views/legislation/processes/_debate_phase.html.erb @@ -0,0 +1,23 @@ +
+
+
+

<%= t("legislation.summary.debates_phase") %>

+
+
+

<%= t("legislation.questions.question.total", count: @process.questions.count) %>

+
+
+
+
+ <% if @process.questions.empty? %> +
+

<%= t("legislation.processes.debate.empty_questions") %>

+
+ <% else %> + <%= render "resume_questions", process: @process %> + <% end %> +
+
+
+
+
diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index 4e8ab85c0..7bd9e7a28 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -52,6 +52,15 @@ <% end %> <% end %> + + <% if process.result_publication.enabled? && process.end_date <= Date.today %> +
  • > + <%= link_to resume_legislation_process_path(process) do %> +

    <%= t("legislation.summary.title") %>

    + <%= format_date(process.result_publication_date) %> + <% end %> +
  • + <% end %> diff --git a/app/views/legislation/processes/_proposal_phase.html.erb b/app/views/legislation/processes/_proposal_phase.html.erb new file mode 100644 index 000000000..59245ce2a --- /dev/null +++ b/app/views/legislation/processes/_proposal_phase.html.erb @@ -0,0 +1,23 @@ +
    +
    +
    +

    <%= t("legislation.summary.proposal_phase") %>

    +
    +
    +

    <%= t("legislation.proposals.total", count: Legislation::Proposal.where(legislation_process_id: @process).where(selected: true).count) %>

    +
    +
    +
    +
    + <% if Legislation::Proposal.where(legislation_process_id: @process).where(selected: true).empty? %> +
    +

    <%= t("legislation.processes.proposals.empty_proposals") %>

    +
    + <% else %> + <%= render "resume_proposal", process: @process %> + <% end %> +
    +
    +
    +
    +
    diff --git a/app/views/legislation/processes/_resume_proposal.html.erb b/app/views/legislation/processes/_resume_proposal.html.erb new file mode 100644 index 000000000..22b39ed53 --- /dev/null +++ b/app/views/legislation/processes/_resume_proposal.html.erb @@ -0,0 +1,17 @@ +<% Legislation::Proposal.where(legislation_process_id: @process) + .where(selected: true).order('cached_votes_score desc').each do |proposal| %> +
    +
    +
    +
    +

    + <%= link_to proposal.title, legislation_process_proposal_path(proposal.legislation_process_id, proposal) %> +

    +
    +
    +

    <%= proposal.cached_votes_total - proposal.cached_votes_down %> <%= t("legislation.summary.votes") %>

    +
    +
    +
    +
    +<% end %> diff --git a/app/views/legislation/processes/_resume_questions.html.erb b/app/views/legislation/processes/_resume_questions.html.erb new file mode 100644 index 000000000..1d683a3c8 --- /dev/null +++ b/app/views/legislation/processes/_resume_questions.html.erb @@ -0,0 +1,34 @@ +<% @process.questions.each do |question| %> +
    +
    +
    +
    +
    +
    +

    <%= link_to question.title, legislation_process_question_path(question.process, question) %>

    +
    +
    +
    + + + <%= link_to t("legislation.summary.comments", count: question.comments.count), legislation_process_question_path(question.process, question) %> + +
    +
    + <% if question.comments.count > 0 %> + <%= t("legislation.summary.most_voted_comments") %> + <% end %> +
    + <% question.best_comments(3).each do |comment| %> +
    +

    <%= link_to comment.body, comment_path(comment) %>

    +
    +
    +

    <%= comment.cached_votes_up - comment.cached_votes_down %> <%= t("legislation.summary.votes") %>

    +
    + <% end %> +
    +
    +
    +
    +<% end %> diff --git a/app/views/legislation/processes/_resume_text.html.erb b/app/views/legislation/processes/_resume_text.html.erb new file mode 100644 index 000000000..f61e25fea --- /dev/null +++ b/app/views/legislation/processes/_resume_text.html.erb @@ -0,0 +1,29 @@ +<% @process.get_best_annotation_comments.take(10).each do |comment| %> +
    +
    +
    +
    +
    + <%= t("legislation.annotations.index.comment_about") %> +
    +
    +
    +
    +
    + "<%= Legislation::Annotation.find_by(id: comment.commentable_id).quote %>" +
    +
    +
    + <%= comment.cached_votes_up - comment.cached_votes_down %> <%= t("legislation.summary.votes") %> +
    +
    + <%= t("legislation.annotations.show.title") %>: +
    +
    +

    <%= link_to comment.body, comment_path(comment) %>

    +
    +
    +
    +
    +
    +<% end %> diff --git a/app/views/legislation/processes/_text_comment_phase.html.erb b/app/views/legislation/processes/_text_comment_phase.html.erb new file mode 100644 index 000000000..763c0798e --- /dev/null +++ b/app/views/legislation/processes/_text_comment_phase.html.erb @@ -0,0 +1,32 @@ +
    +
    +
    +

    <%= t("legislation.summary.comments_phase") %> + <% if !@process.get_last_draft_version.nil? %> + (<%= t("legislation.summary.version") %> <%= @process.get_last_draft_version.title %>)

    + <% end %> +
    +
    +

    <%= t("legislation.annotations.index.comments_count", count: @process.get_best_annotation_comments.count) %>

    +
    +
    +
    +
    + <% if !@process.get_last_draft_version.nil? %> + <% if @process.get_last_draft_version.annotations.empty? %> +
    +

    <%= t("legislation.summary.no_allegation") %>

    +
    + <% else %> + <%= render "resume_text", process: @process %> + <% end %> + <% else %> +
    +

    <%= t("legislation.summary.no_allegation") %>

    +
    + <% end %> +
    +
    +
    +
    +
    diff --git a/app/views/legislation/processes/resume.html.erb b/app/views/legislation/processes/resume.html.erb new file mode 100644 index 000000000..32596455c --- /dev/null +++ b/app/views/legislation/processes/resume.html.erb @@ -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? %> +
    +

    <%= t("legislation.summary.process_empty") %>

    +
    +<% else %> + + + <% 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 %> diff --git a/app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx b/app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx new file mode 100644 index 000000000..27486bd08 --- /dev/null +++ b/app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx @@ -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 diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index 8d24194ae..7900d86bd 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -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. diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index 6d45afca8..2864a6184 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -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. diff --git a/config/routes/legislation.rb b/config/routes/legislation.rb index d5054e2d4..b2a0aa734 100644 --- a/config/routes/legislation.rb +++ b/config/routes/legislation.rb @@ -7,6 +7,8 @@ namespace :legislation do get :result_publication get :proposals get :milestones + get :resume + end resources :questions, only: [:show] do diff --git a/db/schema.rb b/db/schema.rb index 5178cec3c..ea2c98be3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1182,8 +1182,8 @@ ActiveRecord::Schema.define(version: 20190429125842) do t.datetime "confirmed_hide_at" t.bigint "hot_score", default: 0 t.integer "confidence_score", default: 0 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "responsible_name", limit: 60 t.text "summary" t.string "video_url" diff --git a/spec/factories/legislations.rb b/spec/factories/legislations.rb index 204bc67e1..d9b1f74e5 100644 --- a/spec/factories/legislations.rb +++ b/spec/factories/legislations.rb @@ -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 diff --git a/spec/features/legislation/resume_spec.rb b/spec/features/legislation/resume_spec.rb new file mode 100644 index 000000000..4ffd87a9c --- /dev/null +++ b/spec/features/legislation/resume_spec.rb @@ -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