<% 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") %>
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? %>
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 %>
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 cefe161d9..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") %>
-
-
-
- | <%= 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") %> |
-
-
-
- <% @officer_assignments.each do |officer_assignment| %>
-
- | <%= l(officer_assignment.date.to_date) %> |
- <%= booth_name_with_location(officer_assignment.booth_assignment.booth) %> |
-
- <% if officer_assignment.recounts.any? %>
- <%= officer_assignment.recounts.to_a.sum(&:total_amount) %>
- <% else %>
- -
- <% end %>
- |
-
- <% end %>
-
-
<% end %>
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 %>
diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb
index 0b99ea9f5..aff19d9d7 100644
--- a/app/views/admin/poll/polls/_form.html.erb
+++ b/app/views/admin/poll/polls/_form.html.erb
@@ -19,6 +19,22 @@
+
+
+ <%=f.text_area :summary, rows: 4%>
+
+
+
+
+
+ <%=f.text_area :description, rows: 8%>
+
+
+
+
+ <%= render 'images/admin_image', imageable: @poll, f: f %>
+
+
<%= f.check_box :geozone_restricted, data: { checkbox_toggle: "#geozones" } %>
diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb
index e41d2017e..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,12 +18,6 @@
<%= link_to question.title, admin_question_path(question) %>
|
-
- <%= 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/_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| %>
-
- <% 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? %>
-
-
-
- | <%= t("admin.polls.show.table_name") %> |
- <%= t("admin.polls.show.table_assignment") %> |
-
-
-
- <% @questions.each do |question| %>
-
- |
- <%= 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 %>
-
-
-<% 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
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/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) %>
diff --git a/app/views/images/_admin_image.html.erb b/app/views/images/_admin_image.html.erb
new file mode 100644
index 000000000..a782b743b
--- /dev/null
+++ b/app/views/images/_admin_image.html.erb
@@ -0,0 +1,45 @@
+
+
+ <%= f.label :image, t("images.form.admin_title") %>
+
+
+ <%= 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",
+ render_options: {
+ locals: { imageable: imageable }
+ },
+ data: {
+ 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/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/en/admin.yml b/config/locales/en/admin.yml
index 0545e6af5..a3751615a 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,16 +566,10 @@ 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"
- table_name: "Name"
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 +596,6 @@ en:
description: Description
video_url: External video
documents: Documents (1)
- preview: View on website
recounts:
index:
title: "Recounts"
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/config/locales/en/images.yml b/config/locales/en/images.yml
index 6f16061fa..afd8b2308 100644
--- a/config/locales/en/images.yml
+++ b/config/locales/en/images.yml
@@ -9,6 +9,9 @@ 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"
+ admin_alt_text: "Alternative text for the image"
actions:
destroy:
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..f95c2d39f 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,16 +566,10 @@ 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"
- table_name: "Nombre"
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 +596,6 @@ es:
description: Descripción
video_url: Video externo
documents: Documentos (1)
- preview: Ver en la web
recounts:
index:
title: "Recuentos"
diff --git a/config/locales/es/images.yml b/config/locales/es/images.yml
index 869a0824e..e842f3f5c 100644
--- a/config/locales/es/images.yml
+++ b/config/locales/es/images.yml
@@ -9,6 +9,8 @@ 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"
+ admin_alt_text: "Texto alternativo para la imagen"
actions:
destroy:
diff --git a/config/routes.rb b/config/routes.rb
index 410f2dced..51e1f351d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -273,9 +273,7 @@ Rails.application.routes.draw do
scope module: :poll 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
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
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/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/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/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 af121fa0e..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: 20171002191347) do
+ActiveRecord::Schema.define(version: 20171003223152) 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|
@@ -720,7 +719,7 @@ ActiveRecord::Schema.define(version: 20171002191347) 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", "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
@@ -753,6 +752,7 @@ ActiveRecord::Schema.define(version: 20171002191347) 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
@@ -783,6 +783,8 @@ ActiveRecord::Schema.define(version: 20171002191347) 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
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
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
diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb
index 8d30dc5eb..be987df2d 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"
@@ -181,54 +183,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..1804735de 100644
--- a/spec/features/admin/poll/shifts_spec.rb
+++ b/spec/features/admin/poll/shifts_spec.rb
@@ -30,14 +30,15 @@ feature 'Admin shifts' do
expect(page).to have_content officer.name
end
- scenario "Create Vote Collection Shift", :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) }
-
+ scenario "Create Vote Collection Shift and Recount & Scrutiny Shift on same date", :js do
+ poll = create(:poll, :current)
booth = create(:poll_booth)
+ assignment = create(:poll_booth_assignment, poll: poll, booth: 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
+ visit available_admin_booths_path
within("#booth_#{booth.id}") do
click_link "Manage shifts"
@@ -60,16 +61,8 @@ 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
+ visit available_admin_booths_path
within("#booth_#{booth.id}") do
click_link "Manage shifts"
@@ -89,7 +82,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)
@@ -97,11 +90,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"
@@ -116,13 +110,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"
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/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/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
diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb
index b7918b95c..cba4285ae 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
@@ -24,45 +29,80 @@ 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
+
+ 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
- it "should create corresponding officer_assignments" do
- poll1 = create(:poll)
+ it "should create and destroy corresponding officer_assignments" do
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)
- 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
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
+
+ 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
+ booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
+ recount_shift.save
+
+ 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
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
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')