From 1e0aec37abbeafdb074290dbc93f31aab4c16df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 28 Sep 2017 17:37:31 +0200 Subject: [PATCH 01/49] Removed link to poll question in the web in admin section --- app/views/admin/poll/questions/show.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 3f776c5c0..360886b89 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -55,7 +55,5 @@ <%= @question.documents.first.title %>

<% end %> - - <%= link_to t("admin.questions.show.preview"), question_path(@question) %> From 77d0a551cff440cfc4339a2b02571b9ce8d5d105 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 28 Sep 2017 17:46:30 +0200 Subject: [PATCH 02/49] Migration for adding summary and description to polls created. Both text_areas were added to polls form. Imageable class included in polls model and the first aproach for adding images added to form. --- .../admin/poll/polls_controller.rb | 4 +- app/models/poll.rb | 2 + app/views/admin/poll/polls/_form.html.erb | 37 +++++++++++++++++++ config/locales/en/images.yml | 2 + config/locales/es/images.yml | 1 + ...02_add_summary_and_description_to_polls.rb | 6 +++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170928132402_add_summary_and_description_to_polls.rb diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index c95c8ed1f..db4fb567c 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -73,7 +73,9 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end def poll_params - params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, geozone_ids: []) + params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description, + geozone_ids: [], + image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end def search_params diff --git a/app/models/poll.rb b/app/models/poll.rb index 3873ac5e0..e852e912a 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,4 +1,6 @@ class Poll < ActiveRecord::Base + include Imageable + has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booths, through: :booth_assignments has_many :partial_results, through: :booth_assignments diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 0b99ea9f5..3fa7daa4f 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -19,6 +19,43 @@ +
+
+ <%=f.text_area :summary, rows: 4%> +
+
+ +
+
+ <%=f.text_area :description, rows: 8%> +
+
+ +
+
+ <%= f.label :image, t("images.form.admin_title") %> + +
+ <%= f.fields_for :image do |image_builder| %> + <%= render 'images/image_fields', f: image_builder, imageable: @poll %> + <% end %> +
+
+ + <%= link_to_add_association t('images.form.add_new_image'), f, :image, + force_non_association_create: true, + partial: "images/image_fields", + id: "new_image_link", + class: "button hollow #{"hide" if @poll.image.present?}", + render_options: { + locals: { imageable: @poll } + }, + data: { + association_insertion_node: "#nested-image", + association_insertion_method: "append" + } %> +
+
<%= f.check_box :geozone_restricted, data: { checkbox_toggle: "#geozones" } %> diff --git a/config/locales/en/images.yml b/config/locales/en/images.yml index 6f16061fa..087c85021 100644 --- a/config/locales/en/images.yml +++ b/config/locales/en/images.yml @@ -9,6 +9,8 @@ en: delete_button: Remove image note: "You can upload one image of following content types: %{accepted_content_types}, up to %{max_file_size} MB." add_new_image: Add image + title_placeholder: Add a descriptive title for the image + admin_title: "Main image of the poll" actions: destroy: diff --git a/config/locales/es/images.yml b/config/locales/es/images.yml index 869a0824e..0207bceed 100644 --- a/config/locales/es/images.yml +++ b/config/locales/es/images.yml @@ -9,6 +9,7 @@ es: note: "Puedes subir una imagen en los formatos: %{accepted_content_types}, y de hasta %{max_file_size} MB por archivo." add_new_image: Añadir imagen title_placeholder: Añade un título descriptivo para la imagen + admin_title: "Imagen principal de la votación" actions: destroy: diff --git a/db/migrate/20170928132402_add_summary_and_description_to_polls.rb b/db/migrate/20170928132402_add_summary_and_description_to_polls.rb new file mode 100644 index 000000000..6fb965346 --- /dev/null +++ b/db/migrate/20170928132402_add_summary_and_description_to_polls.rb @@ -0,0 +1,6 @@ +class AddSummaryAndDescriptionToPolls < ActiveRecord::Migration + def change + add_column :polls, :summary, :text + add_column :polls, :description, :text + end +end From 14fe771fa55296f57e765653d28a358cafb781a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 28 Sep 2017 17:47:50 +0200 Subject: [PATCH 03/49] Fixed wrong officer action path Before this change, when a user searched for an officer already assigned the ui was blocked because that path wasn't correct. --- app/views/admin/poll/officers/_officer.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/poll/officers/_officer.html.erb b/app/views/admin/poll/officers/_officer.html.erb index 80434f385..3562b4a90 100644 --- a/app/views/admin/poll/officers/_officer.html.erb +++ b/app/views/admin/poll/officers/_officer.html.erb @@ -16,7 +16,7 @@ <% if officer.persisted? %> <%= link_to t('admin.poll_officers.officer.delete'), - admin_poll_officer_path(officer), + admin_officer_path(officer), method: :delete, class: "button hollow alert" %> <% else %> From c67620fdef6919e1dbb1c33df490d28cdec6f50e Mon Sep 17 00:00:00 2001 From: iagirre Date: Fri, 29 Sep 2017 14:51:49 +0200 Subject: [PATCH 04/49] Table for links added (links to add images/documents). Custom partial for admins upload image created, so that it can be reused in upload images and documents. --- app/assets/stylesheets/participation.scss | 3 +- app/models/concerns/imageable.rb | 1 + app/models/poll.rb | 3 +- app/views/admin/poll/polls/_form.html.erb | 43 ++++++++-------- app/views/images/_admin_image.html.erb | 60 +++++++++++++++++++++++ config/locales/en/activerecord.yml | 2 + config/locales/es/activerecord.yml | 2 + config/locales/es/admin.yml | 6 +++ 8 files changed, 96 insertions(+), 24 deletions(-) create mode 100644 app/views/images/_admin_image.html.erb diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index fbcda0ebb..ab3369387 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -313,7 +313,8 @@ .proposal-form, .proposal-edit, .new_poll_question, -.edit_poll_question { +.edit_poll_question, +.edit_poll { @include direct-uploads; } diff --git a/app/models/concerns/imageable.rb b/app/models/concerns/imageable.rb index a2a2f537d..fea94d102 100644 --- a/app/models/concerns/imageable.rb +++ b/app/models/concerns/imageable.rb @@ -5,6 +5,7 @@ module Imageable included do has_one :image, as: :imageable, dependent: :destroy + has_many :images, as: :imageable, dependent: :destroy accepts_nested_attributes_for :image, allow_destroy: true, update_only: true def image_url(style) diff --git a/app/models/poll.rb b/app/models/poll.rb index e852e912a..9aa41cd16 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,5 +1,6 @@ class Poll < ActiveRecord::Base - include Imageable + include Imageable + include Documentable has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booths, through: :booth_assignments diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 3fa7daa4f..235522c65 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -31,29 +31,28 @@
-
-
- <%= f.label :image, t("images.form.admin_title") %> +
+ <%= render 'images/admin_image', imageable: @poll, f: f %> +
-
- <%= f.fields_for :image do |image_builder| %> - <%= render 'images/image_fields', f: image_builder, imageable: @poll %> - <% end %> -
-
- - <%= link_to_add_association t('images.form.add_new_image'), f, :image, - force_non_association_create: true, - partial: "images/image_fields", - id: "new_image_link", - class: "button hollow #{"hide" if @poll.image.present?}", - render_options: { - locals: { imageable: @poll } - }, - data: { - association_insertion_node: "#nested-image", - association_insertion_method: "append" - } %> +
+ + + + + + + + + + + + + + + + +
<%= t("admin.polls.attachments.title") %>
<%= t("admin.polls.attachments.images_title") %><%= t("admin.polls.attachments.documents_title") %>
<%= link_to "#{t("admin.polls.attachments.images_link")} (#{@poll.images.count})", root_path %><%= link_to "#{t("admin.polls.attachments.documents_link")} (#{@poll.documents.count})", root_path %>
diff --git a/app/views/images/_admin_image.html.erb b/app/views/images/_admin_image.html.erb new file mode 100644 index 000000000..7c5157216 --- /dev/null +++ b/app/views/images/_admin_image.html.erb @@ -0,0 +1,60 @@ +
+
+ <%= f.label :image, t("images.form.admin_title") %> + +
+ <%= f.fields_for :image do |image_builder| %> + <%#= render 'images/image_fields', f: image_builder, imageable: imageable %> + + + +
+ <%= image_builder.hidden_field :id %> + <%= image_builder.hidden_field :user_id, value: current_user.id %> + <%= image_builder.hidden_field :cached_attachment %> + + <%= image_builder.text_field :title, placeholder: t("images.form.title_placeholder") %> + + + <%= render_image(image_builder.object, :thumb, false) if image_builder.object.attachment.exists? %> + +
+
+ <%= render_image_attachment(image_builder, imageable, image_builder.object) %> +
+
+ <%= render_destroy_image_link(image_builder, image_builder.object) %> +
+
+ +
+

+ <%= image_attachment_file_name(image_builder.object) %> +

+
+ +
+
+
+ +
+ + + + <% end %> +
+
+ + <%= link_to_add_association t('images.form.add_new_image'), f, :image, + force_non_association_create: true, + partial: "images/image_fields", + id: "new_image_link", + class: "button hollow #{"hide" if imageable.image.present?}", + render_options: { + locals: { imageable: imageable } + }, + data: { + association_insertion_node: "#nested-image", + association_insertion_method: "append" + } %> +
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 1e3f62b1a..8bb2c3286 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -152,6 +152,8 @@ en: starts_at: "Start Date" ends_at: "Closing Date" geozone_restricted: "Restricted by geozone" + summary: "Summary" + description: "Description" poll/question: title: "Question" valid_answers: "Posibles answers" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 108f19fcf..415e81bed 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -146,6 +146,8 @@ es: starts_at: "Fecha de apertura" ends_at: "Fecha de cierre" geozone_restricted: "Restringida por zonas" + summary: "Resumen" + description: "Descripción" poll/question: title: "Pregunta" valid_answers: "Posibles respuestas" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 816cadd57..afa963c20 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -580,6 +580,12 @@ es: error_on_question_added: "No se pudo asignar la pregunta" question_removed: "Pregunta eliminada de esta votación" error_on_question_removed: "No se pudo quitar la pregunta" + attachments: + title: "Imágenes y documentos de la votación" + images_title: "Imágenes" + documents_title: "Documents" + images_link: "Lista de imágenes" + documents_link: "Lista de documentos" questions: index: title: "Preguntas ciudadanas" From fd1d09c8c23efda9082057d02a5a10c41b85ad06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 10:25:11 +0200 Subject: [PATCH 05/49] Booths and shifts index pages minor fixes Showing only actions to assign and edit shifits in shifts index, and option to create a new booth in booths index. --- app/views/admin/poll/booths/_booth.html.erb | 16 +++++++++------- app/views/admin/poll/booths/index.html.erb | 5 +++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/views/admin/poll/booths/_booth.html.erb b/app/views/admin/poll/booths/_booth.html.erb index 80b1ef38f..921361c4a 100644 --- a/app/views/admin/poll/booths/_booth.html.erb +++ b/app/views/admin/poll/booths/_booth.html.erb @@ -6,11 +6,13 @@ <%= booth.location %> - <%= link_to t("admin.booths.booth.shifts"), - new_admin_booth_shift_path(booth), - class: "button hollow" %> - <%= link_to t("admin.actions.edit"), - edit_admin_booth_path(booth), - class: "button hollow" %> + <% if controller_name == "shifts" || controller_name == "booths" && action_name == "available" %> + <%= link_to t("admin.booths.booth.shifts"), + new_admin_booth_shift_path(booth), + class: "button hollow" %> + <%= link_to t("admin.actions.edit"), + edit_admin_booth_path(booth), + class: "button hollow" %> + <% end %> - \ No newline at end of file + diff --git a/app/views/admin/poll/booths/index.html.erb b/app/views/admin/poll/booths/index.html.erb index 05044dd0e..95b248b3f 100644 --- a/app/views/admin/poll/booths/index.html.erb +++ b/app/views/admin/poll/booths/index.html.erb @@ -1,7 +1,8 @@

<%= t("admin.booths.index.title") %>

-<%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, - class: "button success float-right" %> +<% if controller_name == "booths" && action_name != "available" %> + <%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, class: "button success float-right" %> +<% end %> <% if @booths.empty? %>
From adf18ee75635928fce0b8f029b024aa9b160829f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 10:37:10 +0200 Subject: [PATCH 06/49] Polls admin fixes Removed search from questions tab and unassign button. --- app/controllers/admin/poll/polls_controller.rb | 12 ------------ app/views/admin/poll/polls/_questions.html.erb | 4 ---- app/views/admin/poll/polls/show.html.erb | 1 - config/routes.rb | 1 - 4 files changed, 18 deletions(-) diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index c95c8ed1f..3b3c4f7bd 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -47,18 +47,6 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController redirect_to admin_poll_path(@poll), notice: notice end - def remove_question - question = ::Poll::Question.find(params[:question_id]) - - if @poll.questions.include? question - @poll.questions.delete(question) - notice = t("admin.polls.flash.question_removed") - else - notice = t("admin.polls.flash.error_on_question_removed") - end - redirect_to admin_poll_path(@poll), notice: notice - end - def search_questions @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search(search: @search).order(title: :asc) respond_to do |format| diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb index e41d2017e..5088572e1 100644 --- a/app/views/admin/poll/polls/_questions.html.erb +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -20,10 +20,6 @@ - <%= link_to t('admin.polls.show.remove_question'), - remove_question_admin_poll_path(poll_id: @poll.id, question_id: question.id), - class: "button hollow alert", - method: :patch %> <% end %> diff --git a/app/views/admin/poll/polls/show.html.erb b/app/views/admin/poll/polls/show.html.erb index 93ce52e47..be45eeb31 100644 --- a/app/views/admin/poll/polls/show.html.erb +++ b/app/views/admin/poll/polls/show.html.erb @@ -3,6 +3,5 @@
<%= render "subnav" %> - <%= render "search_questions" %> <%= render "questions" %>
diff --git a/config/routes.rb b/config/routes.rb index 410f2dced..d085acd2a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -275,7 +275,6 @@ Rails.application.routes.draw do resources :polls do get :search_questions, on: :member patch :add_question, on: :member - patch :remove_question, on: :member resources :booth_assignments, only: [:index, :show, :create, :destroy] do get :search_booths, on: :collection From 2365ec96fa4c74e7a1dfeec9cf729f522b203f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 10:41:48 +0200 Subject: [PATCH 07/49] Polls admin officers tab fixes Removed actions offered in search results. --- .../_search_officers_results.html.erb | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/app/views/admin/poll/officer_assignments/_search_officers_results.html.erb b/app/views/admin/poll/officer_assignments/_search_officers_results.html.erb index f665c6c0b..ee009f1fa 100644 --- a/app/views/admin/poll/officer_assignments/_search_officers_results.html.erb +++ b/app/views/admin/poll/officer_assignments/_search_officers_results.html.erb @@ -12,29 +12,19 @@ <%= t("admin.poll_officer_assignments.index.table_name") %> <%= t("admin.poll_officer_assignments.index.table_email") %> - <%= t("admin.polls.show.table_assignment") %> <% @officers.each do |user| %> - <%= user.name %> + + <%= link_to user.name, by_officer_admin_poll_officer_assignments_path(@poll, officer_id: user.id) %> + <%= user.email %> - - <% if @poll.officer_ids.include?(user.poll_officer.id) %> - <%= link_to t("admin.poll_officer_assignments.index.edit_officer_assignments"), - by_officer_admin_poll_officer_assignments_path(@poll, officer_id: user.poll_officer.id), - class: "button hollow alert" %> - <% else %> - <%= link_to t("admin.poll_officer_assignments.index.add_officer_assignments"), - by_officer_admin_poll_officer_assignments_path(@poll, officer_id: user.poll_officer.id), - class: "button hollow" %> - <% end %> - <% end %> From 2c72a054acc2e9f27994b1ecc181c75b22298f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 11:04:37 +0200 Subject: [PATCH 08/49] Polls admin officer assignments fixes Removed total results table from officer assignment as now there are only final results. --- .../officer_assignments/by_officer.html.erb | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/app/views/admin/poll/officer_assignments/by_officer.html.erb b/app/views/admin/poll/officer_assignments/by_officer.html.erb index 6ea421e2d..c9873db96 100644 --- a/app/views/admin/poll/officer_assignments/by_officer.html.erb +++ b/app/views/admin/poll/officer_assignments/by_officer.html.erb @@ -27,30 +27,4 @@ <% end %> - -

<%= t("admin.poll_officer_assignments.by_officer.total_recounts") %>

- - - - - - - - - - <% @officer_assignments.each do |officer_assignment| %> - - - - - - <% end %> - -
<%= t("admin.poll_officer_assignments.by_officer.date") %><%= t("admin.poll_officer_assignments.by_officer.booth") %><%= t("admin.poll_officer_assignments.by_officer.total_recount") %>
<%= l(officer_assignment.date.to_date) %><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %> - <% if officer_assignment.total_results.any? %> - <%= officer_assignment.total_results.to_a.sum(&:amount) %> - <% else %> - - - <% end %> -
<% end %> From 799e2475da66dfe90d93b2528572d01c1480e512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 11:08:18 +0200 Subject: [PATCH 09/49] Polls booth assignments fixes Poll booth preview now renders recounts tab by default instead of the officers one. --- app/views/admin/poll/booth_assignments/show.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb index f01270bd4..fd303d099 100644 --- a/app/views/admin/poll/booth_assignments/show.html.erb +++ b/app/views/admin/poll/booth_assignments/show.html.erb @@ -14,15 +14,15 @@
    -
  • +
  • <%= link_to t("admin.poll_booth_assignments.show.officers"), "#tab-officers" %>
  • -
  • +
  • <%= link_to t("admin.poll_booth_assignments.show.recounts"), "#tab-recounts" %>
-
+
<% if @booth_assignment.officers.empty? %>
<%= t("admin.poll_booth_assignments.show.no_officers") %> @@ -43,7 +43,7 @@ <% end %>
-
+

<%= t("admin.poll_booth_assignments.show.recounts_list") %>

From 166caa3b4c01ca65857ec408024bbd8a1ba69337 Mon Sep 17 00:00:00 2001 From: iagirre Date: Mon, 2 Oct 2017 12:59:26 +0200 Subject: [PATCH 10/49] Deleted code in views and concerns that lets polls have more images and documentes attached, like it was at first. Added missing text for english and new texts in english and spanish. Cambios para hacer commit: modificado: app/assets/stylesheets/participation.scss modificado: app/models/concerns/imageable.rb modificado: app/models/poll.rb modificado: app/views/admin/poll/polls/_form.html.erb modificado: app/views/images/_admin_image.html.erb modificado: config/locales/en/images.yml modificado: config/locales/es/admin.yml modificado: config/locales/es/images.yml modificado: spec/features/admin/poll/polls_spec.rb --- app/assets/stylesheets/participation.scss | 1 + app/models/concerns/imageable.rb | 1 - app/models/poll.rb | 3 +- app/views/admin/poll/polls/_form.html.erb | 20 ------ app/views/images/_admin_image.html.erb | 75 +++++++++-------------- config/locales/en/images.yml | 1 + config/locales/es/admin.yml | 6 -- config/locales/es/images.yml | 1 + spec/features/admin/poll/polls_spec.rb | 2 + 9 files changed, 36 insertions(+), 74 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index ab3369387..5b0bcaea7 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -314,6 +314,7 @@ .proposal-edit, .new_poll_question, .edit_poll_question, +.new_poll, .edit_poll { @include direct-uploads; } diff --git a/app/models/concerns/imageable.rb b/app/models/concerns/imageable.rb index fea94d102..a2a2f537d 100644 --- a/app/models/concerns/imageable.rb +++ b/app/models/concerns/imageable.rb @@ -5,7 +5,6 @@ module Imageable included do has_one :image, as: :imageable, dependent: :destroy - has_many :images, as: :imageable, dependent: :destroy accepts_nested_attributes_for :image, allow_destroy: true, update_only: true def image_url(style) diff --git a/app/models/poll.rb b/app/models/poll.rb index 9aa41cd16..9706edd6e 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,7 +1,6 @@ class Poll < ActiveRecord::Base include Imageable - include Documentable - + has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booths, through: :booth_assignments has_many :partial_results, through: :booth_assignments diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 235522c65..aff19d9d7 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -35,26 +35,6 @@ <%= render 'images/admin_image', imageable: @poll, f: f %> -
-
- - - - - - - - - - - - - - - -
<%= t("admin.polls.attachments.title") %>
<%= t("admin.polls.attachments.images_title") %><%= t("admin.polls.attachments.documents_title") %>
<%= link_to "#{t("admin.polls.attachments.images_link")} (#{@poll.images.count})", root_path %><%= link_to "#{t("admin.polls.attachments.documents_link")} (#{@poll.documents.count})", root_path %>
-
-
<%= f.check_box :geozone_restricted, data: { checkbox_toggle: "#geozones" } %> diff --git a/app/views/images/_admin_image.html.erb b/app/views/images/_admin_image.html.erb index 7c5157216..a782b743b 100644 --- a/app/views/images/_admin_image.html.erb +++ b/app/views/images/_admin_image.html.erb @@ -1,55 +1,13 @@
<%= f.label :image, t("images.form.admin_title") %> + -
- <%= f.fields_for :image do |image_builder| %> - <%#= render 'images/image_fields', f: image_builder, imageable: imageable %> - - - -
- <%= image_builder.hidden_field :id %> - <%= image_builder.hidden_field :user_id, value: current_user.id %> - <%= image_builder.hidden_field :cached_attachment %> - - <%= image_builder.text_field :title, placeholder: t("images.form.title_placeholder") %> - - - <%= render_image(image_builder.object, :thumb, false) if image_builder.object.attachment.exists? %> - -
-
- <%= render_image_attachment(image_builder, imageable, image_builder.object) %> -
-
- <%= render_destroy_image_link(image_builder, image_builder.object) %> -
-
- -
-

- <%= image_attachment_file_name(image_builder.object) %> -

-
- -
-
-
- -
- - - - <% end %> -
-
- - <%= link_to_add_association t('images.form.add_new_image'), f, :image, + <%= link_to_add_association t('images.form.add_new_image'), f, :image, force_non_association_create: true, partial: "images/image_fields", id: "new_image_link", - class: "button hollow #{"hide" if imageable.image.present?}", + class: "button hollow", render_options: { locals: { imageable: imageable } }, @@ -57,4 +15,31 @@ association_insertion_node: "#nested-image", association_insertion_method: "append" } %> + +
+ <%= f.fields_for :image do |image_builder| %> + +
+ <%= image_builder.hidden_field :id %> + <%= image_builder.hidden_field :user_id, value: current_user.id %> + <%= image_builder.hidden_field :cached_attachment %> + + <%= image_builder.text_field :title, placeholder: t("images.form.title_placeholder"), label: "#{t("images.form.admin_alt_text")}" %> + + +
+
+ <%= render_image_attachment(image_builder, imageable, image_builder.object) %> +
+
+ +
+
+
+ +
+ + <% end %> +
+
diff --git a/config/locales/en/images.yml b/config/locales/en/images.yml index 087c85021..afd8b2308 100644 --- a/config/locales/en/images.yml +++ b/config/locales/en/images.yml @@ -11,6 +11,7 @@ en: add_new_image: Add image title_placeholder: Add a descriptive title for the image admin_title: "Main image of the poll" + admin_alt_text: "Alternative text for the image" actions: destroy: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index afa963c20..816cadd57 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -580,12 +580,6 @@ es: error_on_question_added: "No se pudo asignar la pregunta" question_removed: "Pregunta eliminada de esta votación" error_on_question_removed: "No se pudo quitar la pregunta" - attachments: - title: "Imágenes y documentos de la votación" - images_title: "Imágenes" - documents_title: "Documents" - images_link: "Lista de imágenes" - documents_link: "Lista de documentos" questions: index: title: "Preguntas ciudadanas" diff --git a/config/locales/es/images.yml b/config/locales/es/images.yml index 0207bceed..e842f3f5c 100644 --- a/config/locales/es/images.yml +++ b/config/locales/es/images.yml @@ -10,6 +10,7 @@ es: add_new_image: Añadir imagen title_placeholder: Añade un título descriptivo para la imagen admin_title: "Imagen principal de la votación" + admin_alt_text: "Texto alternativo para la imagen" actions: destroy: diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 6eb64f6e1..c282bee5d 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -58,6 +58,8 @@ feature 'Admin polls' do fill_in "poll_name", with: "Upcoming poll" fill_in 'poll_starts_at', with: start_date.strftime("%d/%m/%Y") fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") + fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..." + fill_in 'poll_description', with: "Upcomming poll's description. This poll..." click_button "Create poll" expect(page).to have_content "Poll created successfully" From 1c85c8af7950775bcb757848fa2f797906ff6a77 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 2 Oct 2017 13:08:55 +0200 Subject: [PATCH 11/49] Sort Shift recount and scrutiny dates --- app/helpers/shifts_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb index af291779a..dc9f97a91 100644 --- a/app/helpers/shifts_helper.rb +++ b/app/helpers/shifts_helper.rb @@ -5,7 +5,7 @@ module ShiftsHelper end def shift_recount_scrutiny_dates(polls) - date_options(polls.map(&:ends_at).map(&:to_date).inject([]) { |total, date| total << (date..date + 1.week).to_a }.flatten.uniq) + date_options(polls.map(&:ends_at).map(&:to_date).sort.inject([]) { |total, date| total << (date..date + 1.week).to_a }.flatten.uniq) end def date_options(dates) From ca42bc984534378b1616eb3015a3eaa2f7d0e616 Mon Sep 17 00:00:00 2001 From: iagirre Date: Mon, 2 Oct 2017 13:28:44 +0200 Subject: [PATCH 12/49] Added schema.rb with new columns for polls summary and description --- db/schema.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 500f03540..a3bc6065c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170927110953) do +ActiveRecord::Schema.define(version: 20170928132402) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -763,6 +763,8 @@ ActiveRecord::Schema.define(version: 20170927110953) do t.datetime "ends_at" t.boolean "published", default: false t.boolean "geozone_restricted", default: false + t.text "summary" + t.text "description" end add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree From 35f6a5bb65817d1d99d14ee7d66dd8a2a0817766 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 2 Oct 2017 13:45:19 +0200 Subject: [PATCH 13/49] Add task to unique triple index on Shift for booth, officer and task --- app/models/poll/shift.rb | 2 +- db/migrate/20171002103314_add_poll_shift_task_index.rb | 7 +++++++ db/schema.rb | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20171002103314_add_poll_shift_task_index.rb diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index d64bce9ac..cc5f7045e 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -6,8 +6,8 @@ class Poll validates :booth_id, presence: true validates :officer_id, presence: true validates :date, presence: true - validates :date, uniqueness: { scope: [:officer_id, :booth_id] } validates :task, presence: true + validates :date, uniqueness: { scope: [:officer_id, :booth_id, :task] } enum task: { vote_collection: 0, recount_scrutiny: 1 } diff --git a/db/migrate/20171002103314_add_poll_shift_task_index.rb b/db/migrate/20171002103314_add_poll_shift_task_index.rb new file mode 100644 index 000000000..d15275556 --- /dev/null +++ b/db/migrate/20171002103314_add_poll_shift_task_index.rb @@ -0,0 +1,7 @@ +class AddPollShiftTaskIndex < ActiveRecord::Migration + def change + remove_index "poll_shifts", name: "index_poll_shifts_on_booth_id_and_officer_id" + add_index :poll_shifts, :task + add_index :poll_shifts, [:booth_id, :officer_id, :task], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 500f03540..f6ff7447d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170927110953) do +ActiveRecord::Schema.define(version: 20171002103314) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -701,9 +701,10 @@ ActiveRecord::Schema.define(version: 20170927110953) do t.integer "task", default: 0, null: false end - add_index "poll_shifts", ["booth_id", "officer_id"], name: "index_poll_shifts_on_booth_id_and_officer_id", using: :btree + add_index "poll_shifts", ["booth_id", "officer_id", "task"], name: "index_poll_shifts_on_booth_id_and_officer_id_and_task", unique: true, using: :btree add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree + add_index "poll_shifts", ["task"], name: "index_poll_shifts_on_task", using: :btree create_table "poll_total_results", force: :cascade do |t| t.integer "author_id" From afbdd4889101595d14fa866e23fd5176363495e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 16:11:17 +0200 Subject: [PATCH 14/49] Fixed tests --- config/locales/en/admin.yml | 8 ----- config/locales/es/admin.yml | 8 ----- spec/features/admin/poll/polls_spec.rb | 48 ------------------------- spec/features/admin/poll/shifts_spec.rb | 15 ++++---- 4 files changed, 9 insertions(+), 70 deletions(-) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 0545e6af5..008f36f3e 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -489,15 +489,11 @@ en: no_officers: "There are no officers assigned to this poll." table_name: "Name" table_email: "Email" - add_officer_assignments: "Add shifts as officer" - edit_officer_assignments: "Edit officing shifts" by_officer: date: "Date" booth: "Booth" assignments: "Officing shifts in this poll" no_assignments: "This user has no officing shifts in this poll." - total_recounts: "Total recounts" - total_recount: "Total recount (by officer)" poll_shifts: new: add_shift: "Add shift" @@ -570,7 +566,6 @@ en: results_tab: Results no_questions: "There are no questions assigned to this poll." questions_title: "List of questions" - remove_question: "Remove question from poll" add_question: "Include question" table_title: "Title" table_assignment: "Assignment" @@ -578,8 +573,6 @@ en: flash: question_added: "Question added to this poll" error_on_question_added: "Question could not be assigned to this poll" - question_removed: "Question removed from this poll" - error_on_question_removed: "Question could not be removed from this poll" questions: index: title: "Questions" @@ -606,7 +599,6 @@ en: description: Description video_url: External video documents: Documents (1) - preview: View on website recounts: index: title: "Recounts" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 816cadd57..4a4616338 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -489,15 +489,11 @@ es: no_officers: "No hay presidentes de mesa asignados a esta votación." table_name: "Nombre" table_email: "Email" - add_officer_assignments: "Añadir turnos como presidente de mesa" - edit_officer_assignments: "Editar turnos" by_officer: date: "Fecha" booth: "Urna" assignments: "Turnos como presidente de mesa en esta votación" no_assignments: "No tiene turnos como presidente de mesa en esta votación." - total_recounts: "Recuentos totales" - total_recount: "Recuento total (presidente de mesa)" poll_shifts: new: add_shift: "Añadir turno" @@ -570,7 +566,6 @@ es: results_tab: Resultados no_questions: "No hay preguntas asignadas a esta votación." questions_title: "Listado de preguntas asignadas" - remove_question: "Desasignar pregunta" add_question: "Incluir pregunta" table_title: "Título" table_assignment: "Asignación" @@ -578,8 +573,6 @@ es: flash: question_added: "Pregunta añadida a esta votación" error_on_question_added: "No se pudo asignar la pregunta" - question_removed: "Pregunta eliminada de esta votación" - error_on_question_removed: "No se pudo quitar la pregunta" questions: index: title: "Preguntas ciudadanas" @@ -606,7 +599,6 @@ es: description: Descripción video_url: Video externo documents: Documentos (1) - preview: Ver en la web recounts: index: title: "Recuentos" diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 6eb64f6e1..153f0885a 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -181,54 +181,6 @@ feature 'Admin polls' do expect(page).to_not have_content "There are no questions assigned to this poll" end - scenario 'Add question to poll', :js do - poll = create(:poll) - question = create(:poll_question, title: 'Should we rebuild the city?') - - visit admin_poll_path(poll) - - expect(page).to have_content 'Questions (0)' - expect(page).to have_content 'There are no questions assigned to this poll' - - fill_in 'search-questions', with: 'rebuild' - click_button 'Search' - - within('#search-questions-results') do - click_link 'Include question' - end - - expect(page).to have_content 'Question added to this poll' - - visit admin_poll_path(poll) - - expect(page).to have_content 'Questions (1)' - expect(page).to_not have_content 'There are no questions assigned to this poll' - expect(page).to have_content question.title - end - - scenario 'Remove question from poll', :js do - poll = create(:poll) - question = create(:poll_question, poll: poll) - - visit admin_poll_path(poll) - - expect(page).to have_content 'Questions (1)' - expect(page).to_not have_content 'There are no questions assigned to this poll' - expect(page).to have_content question.title - - within("#poll_question_#{question.id}") do - click_link 'Remove question from poll' - end - - expect(page).to have_content 'Question removed from this poll' - - visit admin_poll_path(poll) - - expect(page).to have_content 'Questions (0)' - expect(page).to have_content 'There are no questions assigned to this poll' - expect(page).to_not have_content question.title - end - end end diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 46c737c64..9dea5f8d1 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -31,13 +31,14 @@ feature 'Admin shifts' do end scenario "Create Vote Collection Shift", :js do - poll = create(:poll) + poll = create(:poll, :current) vote_collection_dates = (poll.starts_at.to_date..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } booth = create(:poll_booth) + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) officer = create(:poll_officer) - visit admin_booths_path + visit available_admin_booths_path within("#booth_#{booth.id}") do click_link "Manage shifts" @@ -63,13 +64,14 @@ feature 'Admin shifts' do end scenario "Create Recount & Scrutiny Shift", :js do - poll = create(:poll) + poll = create(:poll, :current) recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a.map { |date| I18n.l(date, format: :long) } booth = create(:poll_booth) + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) officer = create(:poll_officer) - visit admin_booths_path + visit available_admin_booths_path within("#booth_#{booth.id}") do click_link "Manage shifts" @@ -97,11 +99,12 @@ feature 'Admin shifts' do end scenario "Error on create", :js do - poll = create(:poll) + poll = create(:poll, :current) booth = create(:poll_booth) + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) officer = create(:poll_officer) - visit admin_booths_path + visit available_admin_booths_path within("#booth_#{booth.id}") do click_link "Manage shifts" From c0dcedcd0fcbda471ab87c36e9cf04716249ca62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 16:39:09 +0200 Subject: [PATCH 15/49] Tests fix --- spec/features/admin/poll/shifts_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 9dea5f8d1..ceccc1867 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -119,13 +119,14 @@ feature 'Admin shifts' do end scenario "Destroy" do - poll = create(:poll) + poll = create(:poll, :current) booth = create(:poll_booth) + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) officer = create(:poll_officer) shift = create(:poll_shift, officer: officer, booth: booth) - visit admin_booths_path + visit available_admin_booths_path within("#booth_#{booth.id}") do click_link "Manage shifts" From e464985114c7e351ec1db79246d46c31df685f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 20:34:38 +0200 Subject: [PATCH 16/49] Minor fix Removed unnecessary markdown --- app/views/admin/poll/polls/_questions.html.erb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb index 5088572e1..fb92a4e43 100644 --- a/app/views/admin/poll/polls/_questions.html.erb +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -9,7 +9,6 @@ <%= t('admin.polls.show.table_title') %> - <%= t('admin.polls.show.table_assignment') %> <% @poll.questions.each do |question| %> @@ -19,8 +18,6 @@ <%= link_to question.title, admin_question_path(question) %> - - <% end %> From 9ae72387fe9feba12de561238ef4fc9fa9b79eb0 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 2 Oct 2017 23:29:57 +0200 Subject: [PATCH 17/49] Remove remove_question ability from admin on Poll --- app/models/abilities/administrator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 4278d4f8d..2d1a0ee22 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -56,7 +56,7 @@ module Abilities can [:index, :create, :edit, :update, :destroy], Geozone - can [:read, :create, :update, :destroy, :add_question, :remove_question, :search_booths, :search_questions, :search_officers], Poll + can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_questions, :search_officers], Poll can [:read, :create, :update, :destroy, :available], Poll::Booth can [:search, :create, :index, :destroy], ::Poll::Officer can [:create, :destroy], ::Poll::BoothAssignment From bf61dffd4b354e3b0d8fe016265e652151e2ef8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 10:47:48 +0200 Subject: [PATCH 18/49] Removed files that are not used --- .../admin/poll/polls_controller.rb | 9 +---- .../poll/polls/_search_questions.html.erb | 17 ---------- .../polls/_search_questions_results.html.erb | 33 ------------------- .../admin/poll/polls/search_questions.js.erb | 1 - 4 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 app/views/admin/poll/polls/_search_questions.html.erb delete mode 100644 app/views/admin/poll/polls/_search_questions_results.html.erb delete mode 100644 app/views/admin/poll/polls/search_questions.js.erb diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 3b3c4f7bd..fb4b4d127 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -1,7 +1,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController load_and_authorize_resource - before_action :load_search, only: [:search_booths, :search_questions, :search_officers] + before_action :load_search, only: [:search_booths, :search_officers] before_action :load_geozones, only: [:new, :create, :edit, :update] def index @@ -47,13 +47,6 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController redirect_to admin_poll_path(@poll), notice: notice end - def search_questions - @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search(search: @search).order(title: :asc) - respond_to do |format| - format.js - end - end - private def load_geozones diff --git a/app/views/admin/poll/polls/_search_questions.html.erb b/app/views/admin/poll/polls/_search_questions.html.erb deleted file mode 100644 index 659cdcd37..000000000 --- a/app/views/admin/poll/polls/_search_questions.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -
-
- <%= form_tag(search_questions_admin_poll_path(@poll), method: :get, remote: true) do |f| %> -
- <%= text_field_tag :search, - @search, - placeholder: t("admin.shared.poll_questions_search.placeholder"), id: "search-questions" %> - -
- <%= submit_tag t("admin.shared.poll_questions_search.button"), class: "button" %> -
-
- <% end %> -
-
- -
diff --git a/app/views/admin/poll/polls/_search_questions_results.html.erb b/app/views/admin/poll/polls/_search_questions_results.html.erb deleted file mode 100644 index f6f11e1f1..000000000 --- a/app/views/admin/poll/polls/_search_questions_results.html.erb +++ /dev/null @@ -1,33 +0,0 @@ -<% if @questions.blank? %> -
- <%= t('admin.shared.no_search_results') %> -
-<% else %> -

<%= t('admin.shared.search_results') %>

-<% end %> - -<% if @questions.any? %> - - - - - - - - - <% @questions.each do |question| %> - - - - - <% end %> - -
<%= t("admin.polls.show.table_name") %><%= t("admin.polls.show.table_assignment") %>
- <%= question.title %> - - <%= link_to t("admin.polls.show.add_question"), - add_question_admin_poll_path(poll_id: @poll.id, question_id: question.id), - method: :patch, - class: "button hollow" %> -
-<% end %> diff --git a/app/views/admin/poll/polls/search_questions.js.erb b/app/views/admin/poll/polls/search_questions.js.erb deleted file mode 100644 index 05f5c5167..000000000 --- a/app/views/admin/poll/polls/search_questions.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#search-questions-results").html("<%= j render 'search_questions_results' %>"); \ No newline at end of file From e6b5de77fe8889e9d8a9f18c6b1e55b0e4a58f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 10:50:18 +0200 Subject: [PATCH 19/49] Removed files that are not being used --- app/models/abilities/administrator.rb | 2 +- config/routes.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 2d1a0ee22..bfccc5d52 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -56,7 +56,7 @@ module Abilities can [:index, :create, :edit, :update, :destroy], Geozone - can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_questions, :search_officers], Poll + can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_officers], Poll can [:read, :create, :update, :destroy, :available], Poll::Booth can [:search, :create, :index, :destroy], ::Poll::Officer can [:create, :destroy], ::Poll::BoothAssignment diff --git a/config/routes.rb b/config/routes.rb index d085acd2a..51e1f351d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -273,7 +273,6 @@ Rails.application.routes.draw do scope module: :poll do resources :polls do - get :search_questions, on: :member patch :add_question, on: :member resources :booth_assignments, only: [:index, :show, :create, :destroy] do From 4e85e136d1da2095646a903b8d30ea7ac8f7d9b1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 12:02:05 +0200 Subject: [PATCH 20/49] Remove OfficerAssignment composed index --- app/models/poll/officer_assignment.rb | 2 +- ...20171003095936_remove_officer_assigment_composed_index.rb | 5 +++++ db/schema.rb | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20171003095936_remove_officer_assigment_composed_index.rb diff --git a/app/models/poll/officer_assignment.rb b/app/models/poll/officer_assignment.rb index 9fcf02890..417e6a150 100644 --- a/app/models/poll/officer_assignment.rb +++ b/app/models/poll/officer_assignment.rb @@ -8,7 +8,7 @@ class Poll validates :officer_id, presence: true validates :booth_assignment_id, presence: true - validates :date, presence: true, uniqueness: { scope: [:officer_id, :booth_assignment_id] } + validates :date, presence: true delegate :poll_id, :booth_id, to: :booth_assignment diff --git a/db/migrate/20171003095936_remove_officer_assigment_composed_index.rb b/db/migrate/20171003095936_remove_officer_assigment_composed_index.rb new file mode 100644 index 000000000..874672f84 --- /dev/null +++ b/db/migrate/20171003095936_remove_officer_assigment_composed_index.rb @@ -0,0 +1,5 @@ +class RemoveOfficerAssigmentComposedIndex < ActiveRecord::Migration + def change + remove_index "poll_officer_assignments", name: "index_poll_officer_assignments_on_officer_id_and_date" + end +end diff --git a/db/schema.rb b/db/schema.rb index 5c5b99d11..e75c2aac3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171002191347) do +ActiveRecord::Schema.define(version: 20171003095936) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -639,7 +639,6 @@ ActiveRecord::Schema.define(version: 20171002191347) do end add_index "poll_officer_assignments", ["booth_assignment_id"], name: "index_poll_officer_assignments_on_booth_assignment_id", using: :btree - add_index "poll_officer_assignments", ["officer_id", "date"], name: "index_poll_officer_assignments_on_officer_id_and_date", using: :btree add_index "poll_officer_assignments", ["officer_id"], name: "index_poll_officer_assignments_on_officer_id", using: :btree create_table "poll_officers", force: :cascade do |t| From 1afd97b6875dfe16e6af4d053d4ec6f566438c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 12:09:02 +0200 Subject: [PATCH 21/49] Removed unnused translations --- config/locales/en/admin.yml | 3 --- config/locales/es/admin.yml | 3 --- 2 files changed, 6 deletions(-) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 008f36f3e..a3751615a 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -566,10 +566,7 @@ en: results_tab: Results no_questions: "There are no questions assigned to this poll." questions_title: "List of questions" - add_question: "Include question" table_title: "Title" - table_assignment: "Assignment" - table_name: "Name" flash: question_added: "Question added to this poll" error_on_question_added: "Question could not be assigned to this poll" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 4a4616338..f95c2d39f 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -566,10 +566,7 @@ es: results_tab: Resultados no_questions: "No hay preguntas asignadas a esta votación." questions_title: "Listado de preguntas asignadas" - add_question: "Incluir pregunta" table_title: "Título" - table_assignment: "Asignación" - table_name: "Nombre" flash: question_added: "Pregunta añadida a esta votación" error_on_question_added: "No se pudo asignar la pregunta" From 34fbf1472c0d0f39d794c56e3570d158b29381ff Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 12:26:04 +0200 Subject: [PATCH 22/49] Join in a single validation both Shift date validates statements --- app/models/poll/shift.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index cc5f7045e..7fc5e09d1 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -5,9 +5,8 @@ class Poll validates :booth_id, presence: true validates :officer_id, presence: true - validates :date, presence: true + validates :date, presence: true, uniqueness: { scope: [:officer_id, :booth_id, :task] } validates :task, presence: true - validates :date, uniqueness: { scope: [:officer_id, :booth_id, :task] } enum task: { vote_collection: 0, recount_scrutiny: 1 } From 332b9be94a3e1562779ea0d539fa1ba401858ccd Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 12:26:43 +0200 Subject: [PATCH 23/49] Reorder before/after create methods --- app/models/poll/shift.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index 7fc5e09d1..2870709d7 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -13,19 +13,21 @@ class Poll before_create :persist_data after_create :create_officer_assignments - def create_officer_assignments - booth.booth_assignments.each do |booth_assignment| - attrs = { officer_id: officer_id, - date: date, - booth_assignment_id: booth_assignment.id } - Poll::OfficerAssignment.create!(attrs) - end - end - def persist_data self.officer_name = officer.name self.officer_email = officer.email end + def create_officer_assignments + booth.booth_assignments.each do |booth_assignment| + attrs = { + officer_id: officer_id, + date: date, + booth_assignment_id: booth_assignment.id, + final: recount_scrutiny? + } + Poll::OfficerAssignment.create!(attrs) + end + end end end From fc5ff61365c0ae78d98c5e2dd6a612a1fbea032a Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 12:30:42 +0200 Subject: [PATCH 24/49] Destroy all related OfficerAssignments when destroying a Shift --- app/models/poll/shift.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index 2870709d7..4edeb26ef 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -12,6 +12,7 @@ class Poll before_create :persist_data after_create :create_officer_assignments + before_destroy :destroy_officer_assignments def persist_data self.officer_name = officer.name @@ -29,5 +30,12 @@ class Poll Poll::OfficerAssignment.create!(attrs) end end + + def destroy_officer_assignments + Poll::OfficerAssignment.where(booth_assignment: booth.booth_assignments, + officer: officer, + date: date, + final: recount_scrutiny?).destroy_all + end end end From c624129175cb8e2b9d441d568e682db76663b38e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 12:57:40 +0200 Subject: [PATCH 25/49] Check Shift creates final/not-final OfficerAssigments correctly --- spec/models/poll/shift_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index b7918b95c..86755a310 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -50,10 +50,32 @@ describe :shift do expect(oa1.officer).to eq(officer) expect(oa1.date).to eq(Date.current) expect(oa1.booth_assignment).to eq(booth_assignment1) + expect(oa1.final).to be_falsey expect(oa2.officer).to eq(officer) expect(oa2.date).to eq(Date.current) expect(oa2.booth_assignment).to eq(booth_assignment2) + expect(oa2.final).to be_falsey + end + + it "should create final officer_assignments" do + poll = create(:poll) + booth = create(:poll_booth) + officer = create(:poll_officer) + + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + + shift = create(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny) + + officer_assignments = Poll::OfficerAssignment.all + expect(officer_assignments.count).to eq(1) + + officer_assignment = officer_assignments.first + + expect(officer_assignment.officer).to eq(officer) + expect(officer_assignment.date).to eq(Date.current) + expect(officer_assignment.booth_assignment).to eq(booth_assignment) + expect(officer_assignment.final).to be_truthy end end From 690ebfba01c3e10cb45c8ec695f8392090c8f7a7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 13:24:07 +0200 Subject: [PATCH 26/49] Check Shift destroy also destroy only associated OfficerAssigments --- spec/models/poll/shift_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index 86755a310..b62f220da 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -28,7 +28,7 @@ describe :shift do describe "officer_assignments" do - it "should create corresponding officer_assignments" do + it "should create and destroy corresponding officer_assignments" do poll1 = create(:poll) poll2 = create(:poll) poll3 = create(:poll) @@ -39,11 +39,9 @@ describe :shift do booth_assignment1 = create(:poll_booth_assignment, poll: poll1, booth: booth) booth_assignment2 = create(:poll_booth_assignment, poll: poll2, booth: booth) - shift = create(:poll_shift, booth: booth, officer: officer, date: Date.current) + expect { create(:poll_shift, booth: booth, officer: officer, date: Date.current) }.to change {Poll::OfficerAssignment.all.count}.by(2) officer_assignments = Poll::OfficerAssignment.all - expect(officer_assignments.count).to eq(2) - oa1 = officer_assignments.first oa2 = officer_assignments.second @@ -56,6 +54,10 @@ describe :shift do expect(oa2.date).to eq(Date.current) expect(oa2.booth_assignment).to eq(booth_assignment2) expect(oa2.final).to be_falsey + + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment1, date: Date.tomorrow) + + expect { Poll::Shift.last.destroy }.to change {Poll::OfficerAssignment.all.count}.by(-2) end it "should create final officer_assignments" do From 0384baf26aac314fac2afa9e8aa18ef24dc1cd4a Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 13:29:26 +0200 Subject: [PATCH 27/49] Unify both Shift task type creation on a single scenario to check double task on same day --- spec/features/admin/poll/shifts_spec.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 46c737c64..2e957ef11 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -30,12 +30,12 @@ feature 'Admin shifts' do expect(page).to have_content officer.name end - scenario "Create Vote Collection Shift", :js do + scenario "Create Vote Collection Shift and Recount & Scrutiny Shift on same date", :js do poll = create(:poll) - vote_collection_dates = (poll.starts_at.to_date..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } - booth = create(:poll_booth) officer = create(:poll_officer) + vote_collection_dates = (poll.starts_at.to_date..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } + recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a.map { |date| I18n.l(date, format: :long) } visit admin_booths_path @@ -60,14 +60,6 @@ feature 'Admin shifts' do expect(page).to have_content("Collect Votes") expect(page).to have_content(officer.name) end - end - - scenario "Create Recount & Scrutiny Shift", :js do - poll = create(:poll) - recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a.map { |date| I18n.l(date, format: :long) } - - booth = create(:poll_booth) - officer = create(:poll_officer) visit admin_booths_path @@ -89,7 +81,7 @@ feature 'Admin shifts' do expect(page).to have_content "Shift added" within("#shifts") do - expect(page).to have_css(".shift", count: 1) + expect(page).to have_css(".shift", count: 2) expect(page).to have_content(I18n.l(poll.ends_at.to_date + 4.days, format: :long)) expect(page).to have_content("Recount & Scrutiny") expect(page).to have_content(officer.name) From 367b43fd31ebb8a7ca797b04a7ce1f4bd6c55228 Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 3 Oct 2017 13:51:15 +0200 Subject: [PATCH 28/49] adds polls index orders on ignore i18n-tasks --- config/i18n-tasks.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 156a38eff..427fec5ad 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -154,6 +154,7 @@ ignore_unused: - 'users.show.filters.*' - 'polls.index.filters.*' - 'polls.index.section_header.*' + - 'polls.index.orders.*' - 'debates.index.select_order' - 'debates.index.orders.*' - 'debates.index.section_header.*' From 894bda92ba3e2e2d84ea3748aa610ced858db08e Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 3 Oct 2017 13:53:57 +0200 Subject: [PATCH 29/49] moves custom setting to consul settings css --- app/assets/stylesheets/_consul_settings.scss | 2 ++ app/assets/stylesheets/_settings.scss | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/_consul_settings.scss b/app/assets/stylesheets/_consul_settings.scss index 0844f861f..1f03c9be7 100644 --- a/app/assets/stylesheets/_consul_settings.scss +++ b/app/assets/stylesheets/_consul_settings.scss @@ -75,3 +75,5 @@ $accordion-content-color: foreground($accordion-background, $text); $tab-item-font-size: $base-font-size; $tab-item-padding: $line-height / 2 0; $tab-content-border: $border; + +$orbit-bullet-diameter: 0.8rem; diff --git a/app/assets/stylesheets/_settings.scss b/app/assets/stylesheets/_settings.scss index a38071a05..33800fed5 100644 --- a/app/assets/stylesheets/_settings.scss +++ b/app/assets/stylesheets/_settings.scss @@ -411,7 +411,7 @@ $maincontent-shadow: 0 0 10px rgba($black, 0.5); $orbit-bullet-background: $medium-gray; $orbit-bullet-background-active: $dark-gray; -$orbit-bullet-diameter: 0.8rem; +$orbit-bullet-diameter: 1.2rem; $orbit-bullet-margin: 0.1rem; $orbit-bullet-margin-top: 0.8rem; $orbit-bullet-margin-bottom: 0.8rem; From d39c2c6e9edb45f4510248236e5c78269928ddb6 Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 3 Oct 2017 13:55:59 +0200 Subject: [PATCH 30/49] cleans css format --- app/assets/stylesheets/layout.scss | 37 ++++++++++++----------- app/assets/stylesheets/mixins.scss | 8 +++-- app/assets/stylesheets/participation.scss | 2 +- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 44b450779..b9f79430e 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -343,11 +343,9 @@ a { } .truncate-horizontal-text { - white-space: nowrap; overflow: hidden; text-overflow: ellipsis; - -o-text-overflow: ellipsis; - -ms-text-overflow: ellipsis; + white-space: nowrap; } .align-top { @@ -633,7 +631,7 @@ header { text-align: left; @include breakpoint(medium) { - margin-right: rem-calc(24); + margin-right: $line-height; } &:hover { @@ -2183,9 +2181,10 @@ table { } // 19. Recommended Section Home -// ----------- +// ---------------------------- .home-page { + .push { display: none; } @@ -2219,7 +2218,7 @@ table { .card-section { padding: $line-height 0; - max-width: 300px; + max-width: rem-calc(300); margin: 0 auto; p { @@ -2229,10 +2228,10 @@ table { } .orbit { - height: 300px; + height: rem-calc(300); .orbit-wrapper { - max-height: 250px; + max-height: rem-calc(250); overflow: hidden; position: relative; } @@ -2248,7 +2247,7 @@ table { background: image-url('truncate.png'); background-repeat: repeat-x; bottom: 0; - height: 20px; + height: rem-calc(20); position: absolute; width: 100%; } @@ -2269,21 +2268,21 @@ table { .proposals-inner, .budget-investments-inner { background: #fff; - max-height: 350px; + max-height: rem-calc(350); @include breakpoint(small) { - max-height: 400px; + max-height: rem-calc(400); } h4 { margin-top: $line-height; margin-bottom: 0; font-size: rem-calc(18); - min-height: 50px; + min-height: rem-calc(50); } h5 { - font-size: rem-calc(14); + font-size: $small-font-size; text-align: left; } } @@ -2291,20 +2290,20 @@ table { .carousel-image { .card .orbit { - height: 480px; + height: rem-calc(480); .orbit-wrapper { - max-height: 450px; + max-height: rem-calc(450); } } .debates-inner, .proposals-inner, .budget-investments-inner { - max-height: 500px; + max-height: rem-calc(500); @include breakpoint(small) { - max-height: 600px; + max-height: rem-calc(600); } } } @@ -2318,7 +2317,9 @@ table { } } -// 19. Documents +// 20. Documents +// ------------- + .documents-list { table { diff --git a/app/assets/stylesheets/mixins.scss b/app/assets/stylesheets/mixins.scss index 1aa51d1a6..ac3c0a923 100644 --- a/app/assets/stylesheets/mixins.scss +++ b/app/assets/stylesheets/mixins.scss @@ -2,7 +2,8 @@ // // 01. Logo // 02. Orbit bullets -// +// 03. Direct uploads +// ------------------ // 01. Logo // -------- @@ -34,6 +35,7 @@ // 02. Orbit bullet // ---------------- + @mixin orbit-bullets { @include disable-mouse-outline; position: relative; @@ -59,8 +61,9 @@ } } -// 02. Direct uploads +// 03. Direct uploads // ------------------ + @mixin direct-uploads { .cached-image { @@ -133,5 +136,4 @@ .loading-bar.no-transition { transition: none; } - } diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index b1edc246d..c0eb6eed7 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -825,7 +825,7 @@ background: image-url('truncate.png'); background-repeat: repeat-x; bottom: 0; - height: 24px; + height: rem-calc(24); position: absolute; width: 100%; } From 5e9a452e55e31d88e8bdeb029a4b4f536dc1626f Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 3 Oct 2017 13:56:16 +0200 Subject: [PATCH 31/49] removes unnecessary blank space --- app/views/budgets/investments/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 8a19c188a..b3bbf4e14 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -41,7 +41,7 @@ parent_class: "budget_investment" %>
- <% end %> + <% end %>
<%= f.text_field :location %> From c32a70d2a92ab8f2500bde1d26553df70169ca29 Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 3 Oct 2017 13:57:01 +0200 Subject: [PATCH 32/49] improves css for items on list with images --- app/assets/stylesheets/participation.scss | 9 ++++----- app/views/budgets/investments/_investment.html.erb | 4 ++-- app/views/proposals/_proposal.html.erb | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index c0eb6eed7..565803114 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -668,16 +668,15 @@ padding-top: 100%; } } - - .column:first-child { - text-align: center; - } } @include breakpoint(medium) { .panel { - padding: 0 $line-height / 2 0 0; + + &.with-image { + padding: 0 $line-height / 2 0 0; + } .no-image { height: 100%; diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index 2c6269a3f..ecfdcb3c7 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -1,8 +1,8 @@
-
+
-
+
<% if investment.image.present? %> <%= image_tag investment.image_url(:thumb), alt: investment.image.title %> diff --git a/app/views/proposals/_proposal.html.erb b/app/views/proposals/_proposal.html.erb index be5ac8e17..2f5c22c3c 100644 --- a/app/views/proposals/_proposal.html.erb +++ b/app/views/proposals/_proposal.html.erb @@ -1,11 +1,11 @@
Proposal.votes_needed_for_success) %>" data-type="proposal"> -
+
-
+
<% if proposal.image.present? %> <%= image_tag proposal.image_url(:thumb), alt: proposal.image.title %> From 2cb620296bdcf241610381511c563fdf4b871396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 15:49:03 +0200 Subject: [PATCH 33/49] Fixed test --- spec/features/admin/poll/booths_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/poll/booths_spec.rb b/spec/features/admin/poll/booths_spec.rb index 13f3af2ff..22b77b397 100644 --- a/spec/features/admin/poll/booths_spec.rb +++ b/spec/features/admin/poll/booths_spec.rb @@ -87,9 +87,11 @@ feature 'Admin booths' do end scenario "Edit" do + poll = create(:poll, :current) booth = create(:poll_booth) + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - visit admin_booths_path + visit available_admin_booths_path within("#booth_#{booth.id}") do click_link "Edit" @@ -109,4 +111,4 @@ feature 'Admin booths' do end end -end \ No newline at end of file +end From 080064ed46cb9c950ee68bbbd93def5cd5cc1488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 16:48:21 +0200 Subject: [PATCH 34/49] Updated schema.rb --- db/schema.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index e859a487f..e75c2aac3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171002122312) do +ActiveRecord::Schema.define(version: 20171003095936) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -639,7 +639,6 @@ ActiveRecord::Schema.define(version: 20171002122312) do end add_index "poll_officer_assignments", ["booth_assignment_id"], name: "index_poll_officer_assignments_on_booth_assignment_id", using: :btree - add_index "poll_officer_assignments", ["officer_id", "date"], name: "index_poll_officer_assignments_on_officer_id_and_date", using: :btree add_index "poll_officer_assignments", ["officer_id"], name: "index_poll_officer_assignments_on_officer_id", using: :btree create_table "poll_officers", force: :cascade do |t| @@ -698,11 +697,11 @@ ActiveRecord::Schema.define(version: 20171002122312) do t.integer "officer_assignment_id" t.text "officer_assignment_id_log", default: "" t.text "author_id_log", default: "" - t.integer "white_amount" + t.integer "white_amount", default: 0 t.text "white_amount_log", default: "" - t.integer "null_amount" + t.integer "null_amount", default: 0 t.text "null_amount_log", default: "" - t.integer "total_amount" + t.integer "total_amount", default: 0 t.text "total_amount_log", default: "" end @@ -720,9 +719,10 @@ ActiveRecord::Schema.define(version: 20171002122312) do t.integer "task", default: 0, null: false end - add_index "poll_shifts", ["booth_id", "officer_id"], name: "index_poll_shifts_on_booth_id_and_officer_id", using: :btree + add_index "poll_shifts", ["booth_id", "officer_id", "task"], name: "index_poll_shifts_on_booth_id_and_officer_id_and_task", unique: true, using: :btree add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree + add_index "poll_shifts", ["task"], name: "index_poll_shifts_on_task", using: :btree create_table "poll_total_results", force: :cascade do |t| t.integer "author_id" @@ -752,6 +752,7 @@ ActiveRecord::Schema.define(version: 20171002122312) do t.integer "answer_id" t.integer "officer_assignment_id" t.integer "user_id" + t.string "origin" end add_index "poll_voters", ["booth_assignment_id"], name: "index_poll_voters_on_booth_assignment_id", using: :btree From 825671ad9b14df9b2f5ab434b9c379c17b768051 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 18:53:44 +0200 Subject: [PATCH 35/49] Fix polls answer this question show text --- config/locales/en/general.yml | 2 +- spec/features/polls/questions_spec.rb | 8 ++++---- spec/features/polls/voter_spec.rb | 6 +++--- spec/support/common_actions.rb | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 67d8eef2c..ff8a77014 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -494,7 +494,7 @@ en: create_question: "Create question" default_valid_answers: "Yes, No" show: - answer_this_question: "Answer this question" + answer_this_question: "Go to voting page" original_proposal: "Original proposal" author: "Created by" dates_title: "Participation dates" diff --git a/spec/features/polls/questions_spec.rb b/spec/features/polls/questions_spec.rb index 1563ca81a..06dd9df08 100644 --- a/spec/features/polls/questions_spec.rb +++ b/spec/features/polls/questions_spec.rb @@ -82,7 +82,7 @@ feature 'Poll Questions' do login_as(create(:user, :level_two, geozone: geozone)) visit question_path(question) - expect(page).to have_link('Answer this question') + expect(page).to have_link('Go to voting page') end scenario 'Level 2 users who have already answered' do @@ -94,7 +94,7 @@ feature 'Poll Questions' do login_as user visit question_path(question) - expect(page).to have_link('Answer this question') + expect(page).to have_link('Go to voting page') end scenario 'Level 2 users answering', :js do @@ -104,7 +104,7 @@ feature 'Poll Questions' do login_as user visit question_path(question) - expect(page).to have_link('Answer this question') + expect(page).to have_link('Go to voting page') end scenario 'Records participation', :js do @@ -114,7 +114,7 @@ feature 'Poll Questions' do login_as user visit question_path(question) - click_link 'Answer this question' + click_link 'Go to voting page' click_link 'Han Solo' expect(page).to_not have_link('Han Solo') diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 08bc6f963..c12a9f0e4 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -12,7 +12,7 @@ feature "Voter" do login_as user visit question_path(question) - click_link 'Answer this question' + click_link 'Go to voting page' click_link 'Yes' expect(page).to_not have_link('Yes') @@ -81,7 +81,7 @@ feature "Voter" do login_as user visit question_path(question) - click_link 'Answer this question' + click_link 'Go to voting page' expect(page).to_not have_link('Yes') expect(page).to have_content "You have already participated in a booth for this poll." @@ -91,4 +91,4 @@ feature "Voter" do end -end \ No newline at end of file +end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 97f05294c..eda55986f 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -301,7 +301,7 @@ module CommonActions def vote_for_poll_via_web visit question_path(question) - click_link 'Answer this question' + click_link 'Go to voting page' click_link 'Yes' expect(page).to_not have_link('Yes') From 45831a0b68fd4b760e3c96964f4f05fb2c145236 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 18:10:16 +0200 Subject: [PATCH 36/49] Include last day of poll in range for recount and scrutiny on officing panel --- app/controllers/officing/polls_controller.rb | 4 +++- app/controllers/officing/results_controller.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/officing/polls_controller.rb b/app/controllers/officing/polls_controller.rb index 5ba94e024..69b65ad23 100644 --- a/app/controllers/officing/polls_controller.rb +++ b/app/controllers/officing/polls_controller.rb @@ -7,7 +7,9 @@ class Officing::PollsController < Officing::BaseController def final @polls = if current_user.poll_officer? - current_user.poll_officer.final_days_assigned_polls.select {|poll| poll.ends_at > 2.weeks.ago && poll.expired?} + current_user.poll_officer.final_days_assigned_polls.select do |poll| + poll.ends_at > 2.weeks.ago && poll.expired? || poll.ends_at.today? + end else [] end diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index f517f081a..23ef0b038 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -93,7 +93,7 @@ class Officing::ResultsController < Officing::BaseController end def load_poll - @poll = ::Poll.expired.includes(:questions).find(params[:poll_id]) + @poll = ::Poll.includes(:questions).find(params[:poll_id]) end def load_officer_assignment From 5bb831e9595c6d2f7fa55c3eda0676878ccd0617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 19:11:39 +0200 Subject: [PATCH 37/49] Removed poll question show --- app/controllers/polls/questions_controller.rb | 9 -- app/views/polls/_poll_group.html.erb | 2 +- app/views/polls/questions/_answers.html.erb | 22 ----- app/views/polls/questions/_comments.html.erb | 31 ------- .../polls/questions/_filter_subnav.html.erb | 22 ----- app/views/polls/questions/_question.html.erb | 9 -- app/views/polls/questions/answer.js.erb | 1 - app/views/polls/questions/show.html.erb | 92 ------------------- config/routes.rb | 6 +- 9 files changed, 2 insertions(+), 192 deletions(-) delete mode 100644 app/views/polls/questions/_answers.html.erb delete mode 100644 app/views/polls/questions/_comments.html.erb delete mode 100644 app/views/polls/questions/_filter_subnav.html.erb delete mode 100644 app/views/polls/questions/_question.html.erb delete mode 100644 app/views/polls/questions/answer.js.erb delete mode 100644 app/views/polls/questions/show.html.erb diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index 1849dff97..74266a6fc 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -5,15 +5,6 @@ class Polls::QuestionsController < ApplicationController has_orders %w{most_voted newest oldest}, only: :show - def show - @commentable = @question.proposal.present? ? @question.proposal : @question - @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) - set_comment_flags(@comment_tree.comments) - - question_answer = @question.answers.where(author_id: current_user.try(:id)).first - @answers_by_question_id = {@question.id => question_answer.try(:answer)} - end - def answer answer = @question.answers.find_or_initialize_by(author: current_user) diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index 9372aee17..fe12c341b 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -51,7 +51,7 @@ <%= poll_dates(poll) %>
    <% poll.questions.each do |question| %> -
  • <%= link_to question.title, question_path(question) %>
  • +
  • <%= question.title %>
  • <% end %>
<% end %> diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb deleted file mode 100644 index c88156b68..000000000 --- a/app/views/polls/questions/_answers.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
- <% if can? :answer, question %> - <% question.valid_answers.each do |answer| %> - <% if @answers_by_question_id[question.id] == answer %> - "> - <%= answer %> - - <% else %> - <%= link_to answer, - answer_question_path(question, answer: answer), - method: :post, - remote: true, - title: t("poll_questions.show.vote_answer", answer: answer), - class: "button secondary hollow" %> - <% end %> - <% end %> - <% else %> - <% question.valid_answers.each do |answer| %> - <%= answer %> - <% end %> - <% end %> -
diff --git a/app/views/polls/questions/_comments.html.erb b/app/views/polls/questions/_comments.html.erb deleted file mode 100644 index a967406aa..000000000 --- a/app/views/polls/questions/_comments.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@commentable), @comment_tree.comments, @comment_tree.comment_authors, @commentable.comments_count, @comment_flags] do %> -
-
-
-

- <%= t("shared.comments.title") %> - (<%= @commentable.comments_count %>) -

- - <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> - - <% if user_signed_in? %> - <%= render 'comments/form', {commentable: @commentable, parent_id: nil, toggeable: false} %> - <% else %> -
- -
- <%= t("shared.comments.login_to_comment", - signin: link_to(t("votes.signin"), new_user_session_path), - signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> -
- <% end %> - - <% @comment_tree.root_comments.each do |comment| %> - <%= render 'comments/comment', comment: comment %> - <% end %> - <%= paginate @comment_tree.root_comments %> -
-
-
-<% end %> \ No newline at end of file diff --git a/app/views/polls/questions/_filter_subnav.html.erb b/app/views/polls/questions/_filter_subnav.html.erb deleted file mode 100644 index 738fc3700..000000000 --- a/app/views/polls/questions/_filter_subnav.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
-
-
    -
  • - <%= link_to "#tab-comments" do %> -

    - <%= t("proposals.show.comments_tab") %> - (<%= @question.comments_count %>) -

    - <% end %> -
  • -
  • - <%= link_to "#tab-documents" do %> -

    - <%= t("documents.tab") %> - (<%= @question.documents.count %>) -

    - <% end %> -
  • -
-
-
diff --git a/app/views/polls/questions/_question.html.erb b/app/views/polls/questions/_question.html.erb deleted file mode 100644 index f0958b6e4..000000000 --- a/app/views/polls/questions/_question.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -
-

- <%= link_to question.title, question_path(question) %> -

- -
- <%= render 'polls/questions/answers', question: question %> -
-
diff --git a/app/views/polls/questions/answer.js.erb b/app/views/polls/questions/answer.js.erb deleted file mode 100644 index aabbd8d89..000000000 --- a/app/views/polls/questions/answer.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#<%= dom_id(@question) %>_answers").html('<%= j render("polls/questions/answers", question: @question) %>'); diff --git a/app/views/polls/questions/show.html.erb b/app/views/polls/questions/show.html.erb deleted file mode 100644 index f67633129..000000000 --- a/app/views/polls/questions/show.html.erb +++ /dev/null @@ -1,92 +0,0 @@ -<% provide :title do %><%= @question.title %><% end %> - -
-
-
- <%= back_link_to %> - -

<%= @question.title %>

- - <% if @question.proposal.present? %> -
- <%= link_to t('poll_questions.show.original_proposal'), @question.proposal %> -
- <% end %> - - <% if can? :answer, @question %> - <%= link_to t('poll_questions.show.answer_this_question'), - @question.poll, - class: 'large button' %> - <% else %> - <%= render 'polls/reasons_for_not_answering', poll: @question.poll %> - <% end %> -
- -
-

- - <%= t('poll_questions.show.author') %> - -
- <% if @question.author_visible_name.present? %> - <%= @question.author_visible_name %> - <% else %> - <%= link_to @question.author.name, @question.author %> - <% end %> - -

- -

- - <%= t('poll_questions.show.poll') %> - -
- <%= link_to @question.poll.name, @question.poll %> -

- -

- - <%= t('poll_questions.show.dates_title') %> - -
- <%= poll_dates(@question.poll) %> -

-
-
-
- -<% if @question.video_url.present? %> -
-
- -
-
- -<% end %> - -
-
-

<%= t('poll_questions.show.more_info') %>

- <%= @question.description %> -
-
- -
- <%= render "polls/questions/filter_subnav" %> - -
- <%= render "polls/questions/comments" %> -
- -
- <%= render 'documents/documents', - documents: @question.documents, - max_documents_allowed: Poll::Question.max_documents_allowed %> -
-
diff --git a/config/routes.rb b/config/routes.rb index 410f2dced..6c893c24a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,11 +112,7 @@ Rails.application.routes.draw do get :search, on: :collection end - resources :polls, only: [:show, :index] do - resources :questions, only: [:show], controller: 'polls/questions', shallow: true do - post :answer, on: :member - end - end + resources :polls, only: [:show, :index] namespace :legislation do resources :processes, only: [:index, :show] do From 348e4e54f324ec18f16c93e530fc2267717aa863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 19:11:54 +0200 Subject: [PATCH 38/49] Removed question description --- app/controllers/admin/poll/questions_controller.rb | 2 +- app/models/poll/question.rb | 7 ------- app/views/admin/poll/questions/_form.html.erb | 6 ------ ...0171003170029_remove_description_from_poll_questions.rb | 5 +++++ db/schema.rb | 3 +-- 5 files changed, 7 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20171003170029_remove_description_from_poll_questions.rb diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb index 97b301d43..107c06740 100644 --- a/app/controllers/admin/poll/questions_controller.rb +++ b/app/controllers/admin/poll/questions_controller.rb @@ -56,7 +56,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController private def question_params - params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers, :video_url, + params.require(:poll_question).permit(:poll_id, :title, :question, :proposal_id, :valid_answers, :video_url, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index a46f28a8c..55396fd3b 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -23,7 +23,6 @@ class Poll::Question < ActiveRecord::Base validates :poll_id, presence: true validates :title, length: { minimum: 4 } - validates :description, length: { maximum: Poll::Question.description_max_length } scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) } @@ -40,15 +39,10 @@ class Poll::Question < ActiveRecord::Base def searchable_values { title => 'A', proposal.try(:title) => 'A', - description => 'B', author.username => 'C', author_visible_name => 'C' } end - def description - super.try :html_safe - end - def valid_answers (super.try(:split, ',').compact || []).map(&:strip) end @@ -59,7 +53,6 @@ class Poll::Question < ActiveRecord::Base self.author_visible_name = proposal.author.name self.proposal_id = proposal.id self.title = proposal.title - self.description = proposal.description self.valid_answers = I18n.t('poll_questions.default_valid_answers') end end diff --git a/app/views/admin/poll/questions/_form.html.erb b/app/views/admin/poll/questions/_form.html.erb index 7881936e4..6091c024f 100644 --- a/app/views/admin/poll/questions/_form.html.erb +++ b/app/views/admin/poll/questions/_form.html.erb @@ -20,12 +20,6 @@

<%= t("admin.questions.new.valid_answers_note") %>

<%= f.text_field :valid_answers, label: false, aria: {describedby: "valid-answers-help-text"} %> -
- <%= f.cktext_area :description, - maxlength: Poll::Question.description_max_length, - ckeditor: { language: I18n.locale } %> -
-
<%= render 'documents/nested_documents', documentable: @question, f: f %>
diff --git a/db/migrate/20171003170029_remove_description_from_poll_questions.rb b/db/migrate/20171003170029_remove_description_from_poll_questions.rb new file mode 100644 index 000000000..31e1b9578 --- /dev/null +++ b/db/migrate/20171003170029_remove_description_from_poll_questions.rb @@ -0,0 +1,5 @@ +class RemoveDescriptionFromPollQuestions < ActiveRecord::Migration + def change + remove_column :poll_questions, :description + end +end diff --git a/db/schema.rb b/db/schema.rb index e75c2aac3..9381f8e2c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171003095936) do +ActiveRecord::Schema.define(version: 20171003170029) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -675,7 +675,6 @@ ActiveRecord::Schema.define(version: 20171003095936) do t.string "author_visible_name" t.string "title" t.string "valid_answers" - t.text "description" t.integer "comments_count" t.datetime "hidden_at" t.datetime "created_at" From 9871503c5e8a8bf33088fba5a00e1ca48958a8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 21:00:40 +0200 Subject: [PATCH 39/49] Restored views --- app/views/admin/poll/questions/show.html.erb | 8 ------- app/views/polls/questions/_answers.html.erb | 22 ++++++++++++++++++++ app/views/polls/questions/_question.html.erb | 9 ++++++++ app/views/polls/questions/answer.js.erb | 1 + config/routes.rb | 6 +++++- 5 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 app/views/polls/questions/_answers.html.erb create mode 100644 app/views/polls/questions/_question.html.erb create mode 100644 app/views/polls/questions/answer.js.erb diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb index 3f776c5c0..438ee3a40 100644 --- a/app/views/admin/poll/questions/show.html.erb +++ b/app/views/admin/poll/questions/show.html.erb @@ -34,12 +34,6 @@ <% end %> -

- <%= t("admin.questions.show.description") %> -
- <%= @question.description %> -

- <% if @question.video_url.present? %>

<%= t("admin.questions.show.video_url") %> @@ -55,7 +49,5 @@ <%= @question.documents.first.title %>

<% end %> - - <%= link_to t("admin.questions.show.preview"), question_path(@question) %>
diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb new file mode 100644 index 000000000..c88156b68 --- /dev/null +++ b/app/views/polls/questions/_answers.html.erb @@ -0,0 +1,22 @@ +
+ <% if can? :answer, question %> + <% question.valid_answers.each do |answer| %> + <% if @answers_by_question_id[question.id] == answer %> + "> + <%= answer %> + + <% else %> + <%= link_to answer, + answer_question_path(question, answer: answer), + method: :post, + remote: true, + title: t("poll_questions.show.vote_answer", answer: answer), + class: "button secondary hollow" %> + <% end %> + <% end %> + <% else %> + <% question.valid_answers.each do |answer| %> + <%= answer %> + <% end %> + <% end %> +
diff --git a/app/views/polls/questions/_question.html.erb b/app/views/polls/questions/_question.html.erb new file mode 100644 index 000000000..982d0a070 --- /dev/null +++ b/app/views/polls/questions/_question.html.erb @@ -0,0 +1,9 @@ +
+

+ <%= question.title %> +

+ +
+ <%= render 'polls/questions/answers', question: question %> +
+
diff --git a/app/views/polls/questions/answer.js.erb b/app/views/polls/questions/answer.js.erb new file mode 100644 index 000000000..aabbd8d89 --- /dev/null +++ b/app/views/polls/questions/answer.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@question) %>_answers").html('<%= j render("polls/questions/answers", question: @question) %>'); diff --git a/config/routes.rb b/config/routes.rb index 6c893c24a..9e7c8d307 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,7 +112,11 @@ Rails.application.routes.draw do get :search, on: :collection end - resources :polls, only: [:show, :index] + resources :polls, only: [:show, :index] do + resources :questions, controller: 'polls/questions', shallow: true do + post :answer, on: :member + end + end namespace :legislation do resources :processes, only: [:index, :show] do From 81e9682aa3bc4142436dcc47b9a6dd447ace0c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 22:30:15 +0200 Subject: [PATCH 40/49] Fixed tests --- spec/factories.rb | 1 - spec/features/polls/questions_spec.rb | 117 -------------------------- 2 files changed, 118 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index c21c35b4e..f311f58d4 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -498,7 +498,6 @@ FactoryGirl.define do poll association :author, factory: :user sequence(:title) { |n| "Question title #{n}" } - sequence(:description) { |n| "Question description #{n}" } valid_answers { Faker::Lorem.words(3).join(', ') } end diff --git a/spec/features/polls/questions_spec.rb b/spec/features/polls/questions_spec.rb index 1563ca81a..9e7efeedc 100644 --- a/spec/features/polls/questions_spec.rb +++ b/spec/features/polls/questions_spec.rb @@ -11,121 +11,4 @@ feature 'Poll Questions' do expect(proposal_question.title).to appear_before(normal_question.title) end - - scenario 'shows the author visible name instead of a link to the author' do - poll = create(:poll) - question_with_author = create(:poll_question, poll: poll) - question_with_author_visible_name = create(:poll_question, poll: poll, author_visible_name: 'potato') - - visit question_path(question_with_author) - expect(page).to have_link(question_with_author.author.name) - - visit question_path(question_with_author_visible_name) - expect(page).to_not have_link(question_with_author_visible_name.author.name) - expect(page).to have_content(question_with_author_visible_name.author_visible_name) - end - - scenario '#show view has video_url present' do - poll = create(:poll) - normal_question = create(:poll_question, poll: poll, video_url: "https://puppyvideos.com") - - visit question_path(normal_question) - - expect(page).to have_link(normal_question.video_url) - end - - scenario '#show view has document present' do - poll = create(:poll) - normal_question = create(:poll_question, poll: poll) - document = create(:document, documentable: normal_question) - - visit question_path(normal_question) - - expect(page).to have_content(document.title) - end - - context 'Answering' do - let(:geozone) { create(:geozone) } - let(:poll) { create(:poll, geozone_restricted: true, geozone_ids: [geozone.id]) } - - scenario 'Non-logged in users' do - question = create(:poll_question, valid_answers: 'Han Solo, Chewbacca') - - visit question_path(question) - - expect(page).to have_content('You must Sign in or Sign up to participate') - end - - scenario 'Level 1 users' do - question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca') - - login_as(create(:user, geozone: geozone)) - visit question_path(question) - - expect(page).to have_content('You must verify your account in order to answer') - end - - scenario 'Level 2 users in an poll question for a geozone which is not theirs' do - - other_poll = create(:poll, geozone_restricted: true, geozone_ids: [create(:geozone).id]) - question = create(:poll_question, poll: other_poll, valid_answers: 'Vader, Palpatine') - - login_as(create(:user, :level_two, geozone: geozone)) - visit question_path(question) - - expect(page).to have_content('This question is not available on your geozone') - end - - scenario 'Level 2 users who can answer' do - question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca') - - login_as(create(:user, :level_two, geozone: geozone)) - visit question_path(question) - - expect(page).to have_link('Answer this question') - end - - scenario 'Level 2 users who have already answered' do - question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca') - - user = create(:user, :level_two, geozone: geozone) - create(:poll_answer, question: question, author: user, answer: 'Chewbacca') - - login_as user - visit question_path(question) - - expect(page).to have_link('Answer this question') - end - - scenario 'Level 2 users answering', :js do - question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca') - user = create(:user, :level_two, geozone: geozone) - - login_as user - visit question_path(question) - - expect(page).to have_link('Answer this question') - end - - scenario 'Records participation', :js do - question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca') - user = create(:user, :level_two, geozone: geozone, gender: 'female', date_of_birth: 33.years.ago) - - login_as user - visit question_path(question) - - click_link 'Answer this question' - click_link 'Han Solo' - - expect(page).to_not have_link('Han Solo') - - voter = poll.voters.first - expect(voter.document_number).to eq(user.document_number) - expect(voter.geozone_id).to eq(user.geozone_id) - expect(voter.gender).to eq(user.gender) - expect(voter.age).to eq(33) - expect(voter.poll_id).to eq(poll.id) - end - - end end From bdfe822ddf2b27631ab40df8a339c17fbdc0f9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 3 Oct 2017 23:05:06 +0200 Subject: [PATCH 41/49] Removed unused translations --- config/locales/en/admin.yml | 1 - config/locales/en/general.yml | 9 --------- config/locales/es/admin.yml | 1 - config/locales/es/general.yml | 9 --------- 4 files changed, 20 deletions(-) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index a3751615a..c4694b310 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -593,7 +593,6 @@ en: author: Author title: Title valid_answers: Valid answers - description: Description video_url: External video documents: Documents (1) recounts: diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index ff8a77014..fbaa3e4d0 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -494,11 +494,6 @@ en: create_question: "Create question" default_valid_answers: "Yes, No" show: - answer_this_question: "Go to voting page" - original_proposal: "Original proposal" - author: "Created by" - dates_title: "Participation dates" - more_info: "More information" not_logged_in: "You must %{signin} or %{signup} to participate." signin: Sign in signup: Sign up @@ -509,7 +504,6 @@ en: cant_answer_wrong_geozone: "This question is not available on your geozone." vote_answer: "Vote %{answer}" voted: "You have voted %{answer}" - poll: "Poll" proposal_notifications: new: title: "Send message" @@ -524,9 +518,6 @@ en: edit: 'Edit' save: 'Save' delete: 'Delete' - comments: - title: 'Comments' - login_to_comment: 'You must %{signin} or %{signup} to leave a comment.' "yes": "Yes" "no": "No" search_results: "Search results" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index f95c2d39f..c1c2cbf9d 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -593,7 +593,6 @@ es: author: Autor title: Título valid_answers: Respuestas válidas - description: Descripción video_url: Video externo documents: Documentos (1) recounts: diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index aaa59a900..898826c0e 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -494,11 +494,6 @@ es: create_question: "Crear pregunta para votación" default_valid_answers: "Sí, No" show: - answer_this_question: "Responder a esta pregunta" - original_proposal: "Propuesta original" - author: "Creado por" - dates_title: "Fechas de participación" - more_info: "Más información" not_logged_in: "Necesitas %{signin} o %{signup} para participar." signin: iniciar sesión signup: registrarte @@ -509,7 +504,6 @@ es: cant_answer_wrong_geozone: "Esta votación no está disponible en tu zona." vote_answer: "Votar %{answer}" voted: "Has votado %{answer}" - poll: "Votación" proposal_notifications: new: title: "Enviar mensaje" @@ -524,9 +518,6 @@ es: edit: 'Editar' save: 'Guardar' delete: 'Borrar' - comments: - title: 'Comentarios' - login_to_comment: 'Necesitas %{signin} o %{signup} para comentar.' "yes": "Sí" "no": "No" search_results: "Resultados de búsqueda" From 3a0e709e14a8311f528537a9fb19769ad8743373 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 23:34:09 +0200 Subject: [PATCH 42/49] Correct composed index on poll Shift model adding date --- ...20171003212958_add_date_to_poll_shift_composed_index.rb | 7 +++++++ db/schema.rb | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20171003212958_add_date_to_poll_shift_composed_index.rb diff --git a/db/migrate/20171003212958_add_date_to_poll_shift_composed_index.rb b/db/migrate/20171003212958_add_date_to_poll_shift_composed_index.rb new file mode 100644 index 000000000..b59a859c1 --- /dev/null +++ b/db/migrate/20171003212958_add_date_to_poll_shift_composed_index.rb @@ -0,0 +1,7 @@ +class AddDateToPollShiftComposedIndex < ActiveRecord::Migration + def change + remove_index "poll_shifts", name: "index_poll_shifts_on_booth_id_and_officer_id_and_task" + remove_index "poll_shifts", name: "index_poll_shifts_on_task" + add_index :poll_shifts, [:booth_id, :officer_id, :date, :task], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 8b3e89a19..9a6fe919d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171003095936) do +ActiveRecord::Schema.define(version: 20171003212958) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -719,10 +719,9 @@ ActiveRecord::Schema.define(version: 20171003095936) do t.integer "task", default: 0, null: false end - add_index "poll_shifts", ["booth_id", "officer_id", "task"], name: "index_poll_shifts_on_booth_id_and_officer_id_and_task", unique: true, using: :btree + add_index "poll_shifts", ["booth_id", "officer_id", "date", "task"], name: "index_poll_shifts_on_booth_id_and_officer_id_and_date_and_task", unique: true, using: :btree add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree - add_index "poll_shifts", ["task"], name: "index_poll_shifts_on_task", using: :btree create_table "poll_total_results", force: :cascade do |t| t.integer "author_id" From b893c0bacef22fd4281089b15b3d0d810e94c508 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 23:45:02 +0200 Subject: [PATCH 43/49] Add shift task presence validation expectation --- spec/models/poll/shift_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index b62f220da..686dc41db 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -24,6 +24,11 @@ describe :shift do expect(shift).to_not be_valid end + it "should not be valid without a task" do + shift.task = nil + expect(shift).to_not be_valid + end + end describe "officer_assignments" do From 19750995455f6cbe9d876e6048e2b4288da0b346 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 23:53:20 +0200 Subject: [PATCH 44/49] Refactor & cleanup let statements on Shift model spec --- spec/models/poll/shift_spec.rb | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index 686dc41db..be564421c 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -1,9 +1,14 @@ require 'rails_helper' describe :shift do - let(:shift) { build(:poll_shift) } + let(:poll) { create(:poll) } + let(:booth) { create(:poll_booth) } + let(:user) { create(:user, username: "Ana", email: "ana@example.com") } + let(:officer) { create(:poll_officer, user: user) } + let(:recount_shift) { build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny) } describe "validations" do + let(:shift) { build(:poll_shift) } it "should be valid" do expect(shift).to be_valid @@ -34,14 +39,10 @@ describe :shift do describe "officer_assignments" do it "should create and destroy corresponding officer_assignments" do - poll1 = create(:poll) poll2 = create(:poll) poll3 = create(:poll) - booth = create(:poll_booth) - officer = create(:poll_officer) - - booth_assignment1 = create(:poll_booth_assignment, poll: poll1, booth: booth) + booth_assignment1 = create(:poll_booth_assignment, poll: poll, booth: booth) booth_assignment2 = create(:poll_booth_assignment, poll: poll2, booth: booth) expect { create(:poll_shift, booth: booth, officer: officer, date: Date.current) }.to change {Poll::OfficerAssignment.all.count}.by(2) @@ -66,13 +67,8 @@ describe :shift do end it "should create final officer_assignments" do - poll = create(:poll) - booth = create(:poll_booth) - officer = create(:poll_officer) - booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - - shift = create(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny) + recount_shift.save officer_assignments = Poll::OfficerAssignment.all expect(officer_assignments.count).to eq(1) @@ -88,10 +84,7 @@ describe :shift do end describe "#persist_data" do - - let(:user) { create(:user, username: "Ana", email: "ana@example.com") } - let(:officer) { create(:poll_officer, user: user) } - let(:shift) { create(:poll_shift, officer: officer) } + let(:shift) { create(:poll_shift, officer: officer, booth: booth) } it "should maintain officer data after destroying associated user" do shift.officer.user.destroy From b1eb6698be18674dfb968aac923d6fff24f457df Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 4 Oct 2017 00:13:10 +0200 Subject: [PATCH 45/49] Add validation expectations for shift date/task/booth/officer combinations --- spec/models/poll/shift_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index be564421c..cba4285ae 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -34,6 +34,24 @@ describe :shift do expect(shift).to_not be_valid end + it "should not be valid with same booth, officer, date and task" do + recount_shift.save + + expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny)).to_not be_valid + end + + it "should be valid with same booth, officer and date but different task" do + recount_shift.save + + expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :vote_collection)).to be_valid + end + + it "should be valid with same booth, officer and task but different date" do + recount_shift.save + + expect(build(:poll_shift, booth: booth, officer: officer, date: Date.tomorrow, task: :recount_scrutiny)).to be_valid + end + end describe "officer_assignments" do From e928eb38acd093dead71fb1401a109daa37fdd0c Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 4 Oct 2017 00:39:31 +0200 Subject: [PATCH 46/49] Add Officer relationship to Poll Voter --- app/controllers/officing/voters_controller.rb | 3 ++- app/models/poll/voter.rb | 1 + db/migrate/20171003223152_add_officer_to_poll_voter.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories.rb | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20171003223152_add_officer_to_poll_voter.rb diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index a5343f83d..2c3867416 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -13,7 +13,8 @@ class Officing::VotersController < Officing::BaseController document_number: @user.document_number, user: @user, poll: @poll, - origin: "booth") + origin: "booth", + officer: current_user.poll_officer) @voter.save! end diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index abcae7d25..bc0118a88 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -8,6 +8,7 @@ class Poll belongs_to :geozone belongs_to :booth_assignment belongs_to :officer_assignment + belongs_to :officer validates :poll_id, presence: true validates :user_id, presence: true diff --git a/db/migrate/20171003223152_add_officer_to_poll_voter.rb b/db/migrate/20171003223152_add_officer_to_poll_voter.rb new file mode 100644 index 000000000..99f9cd3e3 --- /dev/null +++ b/db/migrate/20171003223152_add_officer_to_poll_voter.rb @@ -0,0 +1,5 @@ +class AddOfficerToPollVoter < ActiveRecord::Migration + def change + add_column :poll_voters, :officer_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 9a6fe919d..a53b0c490 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171003212958) do +ActiveRecord::Schema.define(version: 20171003223152) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -752,6 +752,7 @@ ActiveRecord::Schema.define(version: 20171003212958) do t.integer "officer_assignment_id" t.integer "user_id" t.string "origin" + t.integer "officer_id" end add_index "poll_voters", ["booth_assignment_id"], name: "index_poll_voters_on_booth_assignment_id", using: :btree diff --git a/spec/factories.rb b/spec/factories.rb index c21c35b4e..a127d1bc9 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -531,6 +531,7 @@ FactoryGirl.define do factory :poll_voter, class: 'Poll::Voter' do poll association :user, :level_two + association :officer, factory: :poll_officer origin "web" trait :from_booth do From 85087b0bea5b457cdbcb3a8d3ed94fa39f20f20d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 4 Oct 2017 01:08:33 +0200 Subject: [PATCH 47/49] Check officer value for Poll Voter created from officing panel --- spec/features/officing/voters_spec.rb | 2 ++ spec/models/poll/answer_spec.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 0a23a6a27..b4127b5b8 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -26,6 +26,8 @@ feature 'Voters' do page.evaluate_script("window.location.reload()") expect(page).to have_content "Has already participated in this poll" expect(page).to_not have_button "Confirm vote" + + expect(Poll::Voter.last.officer_id).to eq(officer.id) end scenario "Already voted", :js do diff --git a/spec/models/poll/answer_spec.rb b/spec/models/poll/answer_spec.rb index d66cdc18c..d245af8d4 100644 --- a/spec/models/poll/answer_spec.rb +++ b/spec/models/poll/answer_spec.rb @@ -51,6 +51,7 @@ describe Poll::Answer do expect(voter.document_number).to eq(answer.author.document_number) expect(voter.poll_id).to eq(answer.poll.id) + expect(voter.officer_id).to eq(nil) end it "updates a poll_voter with user and poll data" do From 8dc05d399b9ba1343ef5efbe8e111cf7453866d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 4 Oct 2017 10:03:44 +0200 Subject: [PATCH 48/49] Fixed tests --- spec/features/admin/poll/questions_spec.rb | 5 ----- spec/shared/features/nested_documentable.rb | 1 - 2 files changed, 6 deletions(-) diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index ca3706a24..52e3783f0 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -24,7 +24,6 @@ feature 'Admin poll questions' do visit admin_question_path(question) expect(page).to have_content(question.title) - expect(page).to have_content(question.description) expect(page).to have_content(question.author.name) expect(page).to have_content(question.valid_answers.join(" ")) end @@ -45,13 +44,11 @@ feature 'Admin poll questions' do select 'Movies', from: 'poll_question_poll_id' fill_in 'poll_question_title', with: title - fill_in 'poll_question_description', with: description fill_in 'poll_question_video_url', with: video_url click_button 'Save' expect(page).to have_content(title) - expect(page).to have_content(description) expect(page).to have_content(video_url) end @@ -64,7 +61,6 @@ feature 'Admin poll questions' do expect(current_path).to eq(new_admin_question_path) expect(page).to have_field('poll_question_title', with: proposal.title) - expect(page).to have_field('poll_question_description', with: proposal.description) expect(page).to have_field('poll_question_valid_answers', with: "Yes, No") select 'Proposals', from: 'poll_question_poll_id' @@ -72,7 +68,6 @@ feature 'Admin poll questions' do click_button 'Save' expect(page).to have_content(proposal.title) - expect(page).to have_content(proposal.description) expect(page).to have_link(proposal.title, href: proposal_path(proposal)) expect(page).to have_link(proposal.author.name, href: user_path(proposal.author)) end diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 10a2c9fbf..8780936a7 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -322,5 +322,4 @@ end def documentable_fill_new_valid_poll_question page.select documentable.poll.name, from: 'poll_question_poll_id' fill_in 'poll_question_title', with: "Star Wars: Episode IV - A New Hope" - fill_in_ckeditor "poll_question_description", with: "Description" end From 5b7a90221aab7ed780fa09c7531c83bbaf077ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 4 Oct 2017 11:18:09 +0200 Subject: [PATCH 49/49] Fixed tests --- spec/features/polls/voter_spec.rb | 15 +++++++-------- spec/support/common_actions.rb | 11 ++++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index c12a9f0e4..d925d3394 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -10,12 +10,13 @@ feature "Voter" do user = create(:user, :level_two) login_as user - visit question_path(question) + visit poll_path(poll) - click_link 'Go to voting page' - click_link 'Yes' + within("#poll_question_#{question.id}_answers") do + click_link 'Yes' + expect(page).to_not have_link('Yes') + end - expect(page).to_not have_link('Yes') expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.first.origin).to eq("web") end @@ -56,7 +57,7 @@ feature "Voter" do scenario "Trying to vote in web and then in booth", :js do login_as user - vote_for_poll_via_web + vote_for_poll_via_web(poll, question) click_link "Sign out" @@ -79,9 +80,7 @@ feature "Voter" do click_link "Sign out" login_as user - visit question_path(question) - - click_link 'Go to voting page' + visit poll_path(poll) expect(page).to_not have_link('Yes') expect(page).to have_content "You have already participated in a booth for this poll." diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index eda55986f..256b070e4 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -298,13 +298,14 @@ module CommonActions end end - def vote_for_poll_via_web - visit question_path(question) + def vote_for_poll_via_web(poll, question) + visit poll_path(poll) - click_link 'Go to voting page' - click_link 'Yes' + within("#poll_question_#{question.id}_answers") do + click_link 'Yes' + expect(page).to_not have_link('Yes') + end - expect(page).to_not have_link('Yes') expect(Poll::Voter.count).to eq(1) end