From cc4eed3500a18eb1bc5a198e4b5904ce6a04ab16 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 8 Feb 2017 12:21:28 +0100 Subject: [PATCH 01/34] fixes specs --- .../officing/residence_controller.rb | 6 +-- app/views/officing/residence/new.html.erb | 39 ++++++++----------- config/locales/en/officing.yml | 1 - config/locales/es/officing.yml | 1 - spec/support/common_actions.rb | 5 +++ 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/app/controllers/officing/residence_controller.rb b/app/controllers/officing/residence_controller.rb index ef76162ea..da39f8428 100644 --- a/app/controllers/officing/residence_controller.rb +++ b/app/controllers/officing/residence_controller.rb @@ -1,7 +1,6 @@ class Officing::ResidenceController < Officing::BaseController - before_action :load_officer_assignment - before_action :validate_officer_assignment, only: :create + before_action :validate_officer_assignment def new @residence = Officing::Residence.new @@ -23,13 +22,14 @@ class Officing::ResidenceController < Officing::BaseController end def load_officer_assignment - @officer_assignments = current_user.poll_officer. + @officer_assignments ||= current_user.poll_officer. officer_assignments. voting_days. where(date: Date.current) end def validate_officer_assignment + load_officer_assignment if @officer_assignments.blank? redirect_to officing_root_path, notice: t("officing.residence.flash.not_allowed") end diff --git a/app/views/officing/residence/new.html.erb b/app/views/officing/residence/new.html.erb index a508fae52..c736b1f23 100644 --- a/app/views/officing/residence/new.html.erb +++ b/app/views/officing/residence/new.html.erb @@ -1,32 +1,25 @@

<%= t("officing.residence.new.title") %>

-<% if @officer_assignments.present? %> -
-
- <%= form_for @residence, as: "residence", url: officing_residence_path do |f| %> - <%= render "errors" %> + -<% else %> -
- <%= t("officing.residence.new.no_assignments") %> -
-<% end %> +
diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index 3eb0e70d7..568c0e146 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -51,7 +51,6 @@ en: submit: Validate document error_verifying_census: "The Census was unable to verify this document." form_errors: prevented the verification of this document - no_assignments: "You don't have officing shifts today" voters: new: title: Polls diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index c1d1fa837..1314713b1 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -51,7 +51,6 @@ es: submit: Validar documento error_verifying_census: "El Padrón no pudo verificar este documento." form_errors: evitaron verificar este documento - no_assignments: "Hoy no tienes turno de presidente de mesa" voters: new: title: Votaciones diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 4972d215e..587932ebe 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -21,4 +21,9 @@ module CommonActions check "user_terms_of_service" end + def validate_officer + allow_any_instance_of(Officing::ResidenceController). + to receive(:validate_officer_assignment).and_return(true) + end + end From 10283c32ee65a314bf04a7a13569a3e62ad24430 Mon Sep 17 00:00:00 2001 From: kikito Date: Sat, 11 Feb 2017 11:14:15 +0100 Subject: [PATCH 02/34] Adds scopes to officer_assignment --- app/models/poll/officer_assignment.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/poll/officer_assignment.rb b/app/models/poll/officer_assignment.rb index bdd074995..7d0e31ded 100644 --- a/app/models/poll/officer_assignment.rb +++ b/app/models/poll/officer_assignment.rb @@ -17,6 +17,9 @@ class Poll scope :by_officer_and_poll, ->(officer_id, poll_id) do where("officer_id = ? AND poll_booth_assignments.poll_id = ?", officer_id, poll_id) end + scope :by_officer, ->(officer){ where(officer_id: officer.id) } + scope :by_poll, ->(poll){ joins(:booth_assignment).where("poll_booth_assignments.poll_id" => poll.id) } + scope :by_date, ->(date){ where(date: date) } before_create :log_user_data From 34dfeee9c95656590a73044c75dfdf28e666147c Mon Sep 17 00:00:00 2001 From: kikito Date: Sat, 11 Feb 2017 12:43:05 +0100 Subject: [PATCH 03/34] Denormalizes booth_assignmen on the models where it is needed --- app/models/poll/voter.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index 0826092d2..da05b1bc6 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -16,7 +16,7 @@ class Poll validates :document_number, presence: true, uniqueness: { scope: [:poll_id, :document_type], message: :has_voted } validates :origin, inclusion: { in: VALID_ORIGINS } - before_validation :set_demographic_info, :set_document_info + before_validation :set_demographic_info, :set_document_info, :set_denormalized_booth_assignment_id scope :web, -> { where(origin: "web") } scope :booth, -> { where(origin: "booth") } @@ -38,6 +38,10 @@ class Poll private + def set_denormalized_booth_assignment_id + self.booth_assignment_id ||= officer_assignment.try(:booth_assignment_id) + end + def in_census? census_api_response.valid? end From 5835d12694e8e147b82dce21bf2a2e17965ab1bd Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sun, 12 Feb 2017 13:10:50 +0100 Subject: [PATCH 04/34] stores the officer that allowed a voter to vote in a physical booth --- app/controllers/officing/voters_controller.rb | 9 ++++- spec/features/officing/voters_spec.rb | 38 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 2b7ed329f..564d71ba7 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -15,7 +15,8 @@ class Officing::VotersController < Officing::BaseController user: @user, poll: @poll, origin: "booth", - officer: current_user.poll_officer) + officer: current_user.poll_officer, + officer_assignment: officer_assignment(@poll)) @voter.save! end @@ -25,4 +26,10 @@ class Officing::VotersController < Officing::BaseController params.require(:voter).permit(:poll_id, :user_id) end + def officer_assignment(poll) + Poll::OfficerAssignment.by_officer(current_user.poll_officer) + .by_poll(poll) + .by_date(Date.current) + .first + end end diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 067520d27..01935b6f3 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -93,4 +93,42 @@ feature "Voters" do expect(page).to have_content poll_geozone_restricted_in.name expect(page).not_to have_content poll_geozone_restricted_out.name end + + scenario "Store officer and booth information", :js do + create(:user, :in_census, id: rand(9999)) + poll1 = create(:poll, name: "¿Quieres que XYZ sea aprobado?") + poll2 = create(:poll, name: "Pregunta de votación de prueba") + + ba1 = create(:poll_booth_assignment, poll: poll1) + ba2 = create(:poll_booth_assignment, poll: poll2) + oa1 = create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.current) + oa2 = create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.current) + + validate_officer + visit new_officing_residence_path + officing_verify_residence + + within("#poll_#{poll1.id}") do + click_button "Confirm vote" + + expect(page).to have_content "Vote introduced!" + end + + within("#poll_#{poll2.id}") do + click_button "Confirm vote" + + expect(page).to have_content "Vote introduced!" + end + + expect(Poll::Voter.count).to eq(2) + + voter1 = Poll::Voter.first + + expect(voter1.booth_assignment).to eq(ba1) + expect(voter1.officer_assignment).to eq(oa1) + + voter2 = Poll::Voter.last + expect(voter2.booth_assignment).to eq(ba2) + expect(voter2.officer_assignment).to eq(oa2) + end end From b4499321d3fc468db3a5efe04f08e7be4486ad02 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 14 Feb 2017 03:35:12 +0100 Subject: [PATCH 05/34] stores officer booth on sign in --- app/controllers/officing/base_controller.rb | 28 ++++++++- app/controllers/officing/booth_controller.rb | 43 +++++++++++++ .../officing/residence_controller.rb | 17 +----- app/controllers/officing/voters_controller.rb | 10 ++++ app/controllers/users/sessions_controller.rb | 4 +- app/models/poll/officer_assignment.rb | 8 ++- app/views/officing/booth/new.html.erb | 25 ++++++++ config/locales/en/officing.yml | 4 ++ config/locales/es/officing.yml | 4 ++ config/routes/officing.rb | 1 + spec/features/officing/booth_spec.rb | 60 +++++++++++++++++++ spec/features/officing/residence_spec.rb | 24 ++++++++ spec/features/officing/voters_spec.rb | 2 + spec/support/common_actions.rb | 8 ++- 14 files changed, 218 insertions(+), 20 deletions(-) create mode 100644 app/controllers/officing/booth_controller.rb create mode 100644 app/views/officing/booth/new.html.erb create mode 100644 spec/features/officing/booth_spec.rb diff --git a/app/controllers/officing/base_controller.rb b/app/controllers/officing/base_controller.rb index 48054ce6a..0e0d02ae6 100644 --- a/app/controllers/officing/base_controller.rb +++ b/app/controllers/officing/base_controller.rb @@ -6,7 +6,29 @@ class Officing::BaseController < ApplicationController skip_authorization_check - def verify_officer - raise CanCan::AccessDenied unless current_user.try(:poll_officer?) - end + private + + def verify_officer + raise CanCan::AccessDenied unless current_user.try(:poll_officer?) + end + + def load_officer_assignment + @officer_assignments ||= current_user.poll_officer. + officer_assignments. + voting_days. + where(date: Time.current.to_date) + end + + def verify_officer_assignment + if @officer_assignments.blank? + redirect_to officing_root_path, notice: t("officing.residence.flash.not_allowed") + end + end + + def verify_booth + if session[:booth_id].blank? + redirect_to new_officing_booth_path + end + end + end diff --git a/app/controllers/officing/booth_controller.rb b/app/controllers/officing/booth_controller.rb new file mode 100644 index 000000000..7dfee5400 --- /dev/null +++ b/app/controllers/officing/booth_controller.rb @@ -0,0 +1,43 @@ +class Officing::BoothController < Officing::BaseController + before_action :load_officer_assignment + before_action :verify_officer_assignment + + def new + load_booths + + if only_one_booth? + set_booth(@booths.first) + redirect_to officing_root_path, notice: t("officing.booth.new.success", booth: @booths.first.name) + end + end + + def create + find_booth + set_booth(@booth) + redirect_to officing_root_path, notice: t("officing.booth.new.success", booth: @booth.name) + end + + private + + def booth_params + params.require(:booth).permit(:id) + end + + def load_booths + officer = current_user.poll_officer + @booths = officer.officer_assignments.by_date(Date.today).map(&:booth) + end + + def only_one_booth? + @booths.count == 1 + end + + def find_booth + @booth = Poll::Booth.find(booth_params[:id]) + end + + def set_booth(booth) + session[:booth_id] = booth.id + end + +end diff --git a/app/controllers/officing/residence_controller.rb b/app/controllers/officing/residence_controller.rb index da39f8428..cb7b96a64 100644 --- a/app/controllers/officing/residence_controller.rb +++ b/app/controllers/officing/residence_controller.rb @@ -1,6 +1,8 @@ class Officing::ResidenceController < Officing::BaseController - before_action :validate_officer_assignment + before_action :load_officer_assignment + before_action :verify_officer_assignment + before_action :verify_booth def new @residence = Officing::Residence.new @@ -21,17 +23,4 @@ class Officing::ResidenceController < Officing::BaseController params.require(:residence).permit(:document_number, :document_type, :year_of_birth) end - def load_officer_assignment - @officer_assignments ||= current_user.poll_officer. - officer_assignments. - voting_days. - where(date: Date.current) - end - - def validate_officer_assignment - load_officer_assignment - if @officer_assignments.blank? - redirect_to officing_root_path, notice: t("officing.residence.flash.not_allowed") - end - end end diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 564d71ba7..3354795b6 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -1,6 +1,10 @@ class Officing::VotersController < Officing::BaseController respond_to :html, :js + before_action :load_officer_assignment + before_action :verify_officer_assignment + before_action :verify_booth + def new @user = User.find(params[:id]) booths = current_user.poll_officer.shifts.current.vote_collection.pluck(:booth_id).uniq @@ -29,7 +33,13 @@ class Officing::VotersController < Officing::BaseController def officer_assignment(poll) Poll::OfficerAssignment.by_officer(current_user.poll_officer) .by_poll(poll) + .by_booth(current_booth) .by_date(Date.current) .first end + + def current_booth + Poll::Booth.find(session[:booth_id]) + end + end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index d16f9c87e..0409a9d5e 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -3,7 +3,9 @@ class Users::SessionsController < Devise::SessionsController private def after_sign_in_path_for(resource) - if !verifying_via_email? && resource.show_welcome_screen? + if current_user.poll_officer? + new_officing_booth_path + elsif !verifying_via_email? && resource.show_welcome_screen? welcome_path else super diff --git a/app/models/poll/officer_assignment.rb b/app/models/poll/officer_assignment.rb index 7d0e31ded..7de4f98b3 100644 --- a/app/models/poll/officer_assignment.rb +++ b/app/models/poll/officer_assignment.rb @@ -18,7 +18,8 @@ class Poll where("officer_id = ? AND poll_booth_assignments.poll_id = ?", officer_id, poll_id) end scope :by_officer, ->(officer){ where(officer_id: officer.id) } - scope :by_poll, ->(poll){ joins(:booth_assignment).where("poll_booth_assignments.poll_id" => poll.id) } + scope :by_poll, ->(poll){ joins(:booth_assignment).where("poll_booth_assignments.poll_id" => poll.id) } + scope :by_booth, ->(booth){ joins(:booth_assignment).where("poll_booth_assignments.booth_id" => booth.id) } scope :by_date, ->(date){ where(date: date) } before_create :log_user_data @@ -26,5 +27,10 @@ class Poll def log_user_data self.user_data_log = "#{officer.user_id} - #{officer.user.name_and_email}" end + + def booth + booth_assignment.booth + end + end end diff --git a/app/views/officing/booth/new.html.erb b/app/views/officing/booth/new.html.erb new file mode 100644 index 000000000..5fbcd429e --- /dev/null +++ b/app/views/officing/booth/new.html.erb @@ -0,0 +1,25 @@ +
+
+
+

+ <%= t("officing.booth.new.title") %> +

+ <%= form_for Poll::Booth.new, + as: :booth, + url: officing_booth_path, + method: :post do |f| %> +
+
+ <%= f.select :id, + @booths.collect { |booth| [booth.name, booth.id] }, + selected: @booths.first, + label: false, + tabindex: "1" %> + + <%= f.submit(t("devise_views.sessions.new.submit"), class: "button expanded") %> +
+
+ <% end %> +
+
+
diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index 568c0e146..b38418e51 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -16,6 +16,10 @@ en: no_polls: You are not officing final recounts in any active poll select_poll: Select poll add_results: Add results + booth: + new: + title: "Choose your booth" + success: "You are officing booth %{booth}" results: flash: create: "Results saved" diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index 1314713b1..04ee109f6 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -16,6 +16,10 @@ es: no_polls: No tienes permiso para recuento final en ninguna votación reciente select_poll: Selecciona votación add_results: Añadir resultados + booth: + new: + title: "Escoge tu urna" + success: "Estás presidiendo la urna %{booth}" results: flash: create: "Datos guardados" diff --git a/config/routes/officing.rb b/config/routes/officing.rb index 7adfbbf60..6be5e5bc2 100644 --- a/config/routes/officing.rb +++ b/config/routes/officing.rb @@ -4,6 +4,7 @@ namespace :officing do resources :results, only: [:new, :create, :index] end + resource :booth, controller: "booth", only: [:new, :create] resource :residence, controller: "residence", only: [:new, :create] resources :voters, only: [:new, :create] root to: "dashboard#index" diff --git a/spec/features/officing/booth_spec.rb b/spec/features/officing/booth_spec.rb new file mode 100644 index 000000000..07d2fc7b9 --- /dev/null +++ b/spec/features/officing/booth_spec.rb @@ -0,0 +1,60 @@ +require "rails_helper" + +feature "Booth" do + + scenario "Officer with no booth assignments today" do + officer = create(:poll_officer) + + login_through_form_as(officer.user) + + expect(page).to have_content "You don't have officing shifts today" + end + + scenario "Officer with booth assignments another day" do + officer = create(:poll_officer) + create(:poll_officer_assignment, officer: officer, date: 1.day.from_now) + + login_through_form_as(officer.user) + + expect(page).to have_content "You don't have officing shifts today" + end + + scenario "Officer with single booth assignment today" do + officer = create(:poll_officer) + poll = create(:poll) + + booth = create(:poll_booth) + + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment, date: Date.today) + + login_through_form_as(officer.user) + + expect(page).to have_content "You are officing booth #{booth.name}" + end + + scenario "Officer with multiple booth assignments today" do + officer = create(:poll_officer) + poll = create(:poll) + + booth1 = create(:poll_booth) + booth2 = create(:poll_booth) + + ba1 = create(:poll_booth_assignment, poll: poll, booth: booth1) + ba2 = create(:poll_booth_assignment, poll: poll, booth: booth2) + + create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.today) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.today) + + login_through_form_as(officer.user) + + expect(page).to have_content "You have been signed in successfully." + expect(page).to have_content "Choose your booth" + + select booth2.name, from: "booth_id" + click_button "Enter" + + expect(page).to have_content "You are officing booth #{booth2.name}" + end + +end diff --git a/spec/features/officing/residence_spec.rb b/spec/features/officing/residence_spec.rb index 9f07eb8ce..664678e82 100644 --- a/spec/features/officing/residence_spec.rb +++ b/spec/features/officing/residence_spec.rb @@ -93,4 +93,28 @@ feature "Residence", :with_frozen_time do end + scenario "Verify booth", :js do + booth = create(:poll_booth) + poll = create(:poll) + + ba = create(:poll_booth_assignment, poll: poll, booth: booth ) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba) + + login_as(officer.user) + + # User somehow skips setting session[:booth_id] + # set_officing_booth(booth) + + visit new_officing_residence_path + expect(page).to have_content "You are officing booth #{booth.name}" + + visit new_officing_residence_path + officing_verify_residence + + expect(page).to have_content poll.name + click_button "Confirm vote" + + expect(page).to have_content "Vote introduced!" + end + end diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 01935b6f3..19e3cca33 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -15,6 +15,8 @@ feature "Voters" do end scenario "Can vote", :js do + create(:poll_officer_assignment, officer: officer) + visit new_officing_residence_path officing_verify_residence diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 587932ebe..7bb20af10 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -23,7 +23,13 @@ module CommonActions def validate_officer allow_any_instance_of(Officing::ResidenceController). - to receive(:validate_officer_assignment).and_return(true) + to receive(:verify_officer_assignment).and_return(true) end + def set_officing_booth(booth=nil) + booth = create(:poll_booth) if booth.blank? + + allow_any_instance_of(Officing::VotersController). + to receive(:current_booth).and_return(booth) + end end From 74706027cb3329af73caa84d71a81ea79fb9f500 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Feb 2017 15:28:24 +0100 Subject: [PATCH 06/34] fixes specs --- app/controllers/officing/base_controller.rb | 6 +++++- app/controllers/officing/voters_controller.rb | 4 ---- spec/features/officing/residence_spec.rb | 2 +- spec/features/officing/voters_spec.rb | 6 +++++- spec/support/common_actions.rb | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/controllers/officing/base_controller.rb b/app/controllers/officing/base_controller.rb index 0e0d02ae6..ff1eb52e7 100644 --- a/app/controllers/officing/base_controller.rb +++ b/app/controllers/officing/base_controller.rb @@ -26,9 +26,13 @@ class Officing::BaseController < ApplicationController end def verify_booth - if session[:booth_id].blank? + if current_booth.blank? redirect_to new_officing_booth_path end end + def current_booth + Poll::Booth.where(id: session[:booth_id]).first + end + end diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 3354795b6..49b7636fd 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -38,8 +38,4 @@ class Officing::VotersController < Officing::BaseController .first end - def current_booth - Poll::Booth.find(session[:booth_id]) - end - end diff --git a/spec/features/officing/residence_spec.rb b/spec/features/officing/residence_spec.rb index 664678e82..a55fb8b3e 100644 --- a/spec/features/officing/residence_spec.rb +++ b/spec/features/officing/residence_spec.rb @@ -25,7 +25,7 @@ feature "Residence", :with_frozen_time do background do create(:poll_officer_assignment, officer: officer) - login_as(officer.user) + login_through_form_as(officer.user) visit officing_root_path end diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 19e3cca33..264319f70 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -59,6 +59,10 @@ feature "Voters" do user = create(:user, residence_verified_at: Time.current, document_type: "1", document_number: "12345678Z") expect(user).not_to be_level_two_verified + visit root_path + click_link "Sign out" + login_through_form_as(officer.user) + visit new_officing_residence_path officing_verify_residence @@ -97,7 +101,7 @@ feature "Voters" do end scenario "Store officer and booth information", :js do - create(:user, :in_census, id: rand(9999)) + create(:user, :in_census, id: rand(9999999)) poll1 = create(:poll, name: "¿Quieres que XYZ sea aprobado?") poll2 = create(:poll, name: "Pregunta de votación de prueba") diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 7bb20af10..118508119 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -22,14 +22,14 @@ module CommonActions end def validate_officer - allow_any_instance_of(Officing::ResidenceController). + allow_any_instance_of(Officing::BaseController). to receive(:verify_officer_assignment).and_return(true) end def set_officing_booth(booth=nil) booth = create(:poll_booth) if booth.blank? - allow_any_instance_of(Officing::VotersController). + allow_any_instance_of(Officing::BaseController). to receive(:current_booth).and_return(booth) end end From 5dea0e039eca2722ee80b085f845d9d261041cf4 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Feb 2017 15:45:43 +0100 Subject: [PATCH 07/34] updates notice --- config/locales/en/officing.yml | 2 +- config/locales/es/officing.yml | 2 +- spec/features/officing/booth_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index b38418e51..9533f6bb8 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -19,7 +19,7 @@ en: booth: new: title: "Choose your booth" - success: "You are officing booth %{booth}" + success: "You are officing the booth located at %{booth}. If this is not correct, do not continue and call the help phone number. Thank you." results: flash: create: "Results saved" diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index 04ee109f6..1c6bae97b 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -19,7 +19,7 @@ es: booth: new: title: "Escoge tu urna" - success: "Estás presidiendo la urna %{booth}" + success: "Estás ahora mismo en la mesa ubicada en %{booth}. Si esto no es correcto no sigas adelante y llama al teléfono de incidencias. Gracias." results: flash: create: "Datos guardados" diff --git a/spec/features/officing/booth_spec.rb b/spec/features/officing/booth_spec.rb index 07d2fc7b9..9e6e03f2b 100644 --- a/spec/features/officing/booth_spec.rb +++ b/spec/features/officing/booth_spec.rb @@ -30,7 +30,7 @@ feature "Booth" do login_through_form_as(officer.user) - expect(page).to have_content "You are officing booth #{booth.name}" + expect(page).to have_content "You are officing the booth located at #{booth.name}." end scenario "Officer with multiple booth assignments today" do @@ -54,7 +54,7 @@ feature "Booth" do select booth2.name, from: "booth_id" click_button "Enter" - expect(page).to have_content "You are officing booth #{booth2.name}" + expect(page).to have_content "You are officing the booth located at #{booth2.name}." end end From 0286ca4c59b63c31158176327427dfa97843999f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Feb 2017 17:47:06 +0100 Subject: [PATCH 08/34] displays single booth for any number of polls --- app/controllers/officing/booth_controller.rb | 2 +- spec/features/officing/booth_spec.rb | 25 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/controllers/officing/booth_controller.rb b/app/controllers/officing/booth_controller.rb index 7dfee5400..e3bde3b8d 100644 --- a/app/controllers/officing/booth_controller.rb +++ b/app/controllers/officing/booth_controller.rb @@ -25,7 +25,7 @@ class Officing::BoothController < Officing::BaseController def load_booths officer = current_user.poll_officer - @booths = officer.officer_assignments.by_date(Date.today).map(&:booth) + @booths = officer.officer_assignments.by_date(Date.today).map(&:booth).uniq end def only_one_booth? diff --git a/spec/features/officing/booth_spec.rb b/spec/features/officing/booth_spec.rb index 9e6e03f2b..a4f9d3d0c 100644 --- a/spec/features/officing/booth_spec.rb +++ b/spec/features/officing/booth_spec.rb @@ -57,4 +57,29 @@ feature "Booth" do expect(page).to have_content "You are officing the booth located at #{booth2.name}." end + scenario "Display single booth for any number of polls" do + officer = create(:poll_officer) + + booth1 = create(:poll_booth) + booth2 = create(:poll_booth) + + poll1 = create(:poll) + poll2 = create(:poll) + + ba1 = create(:poll_booth_assignment, poll: poll1, booth: booth1) + ba2 = create(:poll_booth_assignment, poll: poll2, booth: booth2) + ba3 = create(:poll_booth_assignment, poll: poll2, booth: booth2) + + create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.today) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.today) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba3, date: Date.today) + + login_through_form_as(officer.user) + + expect(page).to have_content "You have been signed in successfully." + expect(page).to have_content "Choose your booth" + + expect(page).to have_select("booth_id", options: [booth1.name, booth2.name]) + end + end From 9c59c8b68e14c67e0eff4db578168c50502649b8 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Feb 2017 17:51:47 +0100 Subject: [PATCH 09/34] displays booth location instead of booth name --- app/controllers/officing/booth_controller.rb | 4 ++-- app/views/officing/booth/new.html.erb | 2 +- spec/features/officing/booth_spec.rb | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/officing/booth_controller.rb b/app/controllers/officing/booth_controller.rb index e3bde3b8d..624de8a2b 100644 --- a/app/controllers/officing/booth_controller.rb +++ b/app/controllers/officing/booth_controller.rb @@ -7,14 +7,14 @@ class Officing::BoothController < Officing::BaseController if only_one_booth? set_booth(@booths.first) - redirect_to officing_root_path, notice: t("officing.booth.new.success", booth: @booths.first.name) + redirect_to officing_root_path, notice: t("officing.booth.new.success", booth: @booths.first.location) end end def create find_booth set_booth(@booth) - redirect_to officing_root_path, notice: t("officing.booth.new.success", booth: @booth.name) + redirect_to officing_root_path, notice: t("officing.booth.new.success", booth: @booth.location) end private diff --git a/app/views/officing/booth/new.html.erb b/app/views/officing/booth/new.html.erb index 5fbcd429e..6cbfeda0f 100644 --- a/app/views/officing/booth/new.html.erb +++ b/app/views/officing/booth/new.html.erb @@ -11,7 +11,7 @@
<%= f.select :id, - @booths.collect { |booth| [booth.name, booth.id] }, + @booths.collect { |booth| [booth.location, booth.id] }, selected: @booths.first, label: false, tabindex: "1" %> diff --git a/spec/features/officing/booth_spec.rb b/spec/features/officing/booth_spec.rb index a4f9d3d0c..8f0e6cd3d 100644 --- a/spec/features/officing/booth_spec.rb +++ b/spec/features/officing/booth_spec.rb @@ -30,7 +30,7 @@ feature "Booth" do login_through_form_as(officer.user) - expect(page).to have_content "You are officing the booth located at #{booth.name}." + expect(page).to have_content "You are officing the booth located at #{booth.location}." end scenario "Officer with multiple booth assignments today" do @@ -51,10 +51,10 @@ feature "Booth" do expect(page).to have_content "You have been signed in successfully." expect(page).to have_content "Choose your booth" - select booth2.name, from: "booth_id" + select booth2.location, from: "booth_id" click_button "Enter" - expect(page).to have_content "You are officing the booth located at #{booth2.name}." + expect(page).to have_content "You are officing the booth located at #{booth2.location}." end scenario "Display single booth for any number of polls" do @@ -79,7 +79,7 @@ feature "Booth" do expect(page).to have_content "You have been signed in successfully." expect(page).to have_content "Choose your booth" - expect(page).to have_select("booth_id", options: [booth1.name, booth2.name]) + expect(page).to have_select("booth_id", options: [booth1.location, booth2.location]) end end From 4761ac91bd3b48971575260766be997f1fa70393 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Feb 2017 18:22:02 +0100 Subject: [PATCH 10/34] Displays officing booth in layout --- app/controllers/officing/base_controller.rb | 1 + app/controllers/officing/booth_controller.rb | 4 ++-- app/views/layouts/_officing_booth.html.erb | 5 +++++ app/views/layouts/admin.html.erb | 1 + config/locales/en/admin.yml | 2 ++ config/locales/en/officing.yml | 1 - config/locales/es/admin.yml | 2 ++ config/locales/es/officing.yml | 1 - spec/features/officing/booth_spec.rb | 8 ++++++-- 9 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 app/views/layouts/_officing_booth.html.erb diff --git a/app/controllers/officing/base_controller.rb b/app/controllers/officing/base_controller.rb index ff1eb52e7..7d9bf225d 100644 --- a/app/controllers/officing/base_controller.rb +++ b/app/controllers/officing/base_controller.rb @@ -1,5 +1,6 @@ class Officing::BaseController < ApplicationController layout "admin" + helper_method :current_booth before_action :authenticate_user! before_action :verify_officer diff --git a/app/controllers/officing/booth_controller.rb b/app/controllers/officing/booth_controller.rb index 624de8a2b..383154f97 100644 --- a/app/controllers/officing/booth_controller.rb +++ b/app/controllers/officing/booth_controller.rb @@ -7,14 +7,14 @@ class Officing::BoothController < Officing::BaseController if only_one_booth? set_booth(@booths.first) - redirect_to officing_root_path, notice: t("officing.booth.new.success", booth: @booths.first.location) + redirect_to officing_root_path end end def create find_booth set_booth(@booth) - redirect_to officing_root_path, notice: t("officing.booth.new.success", booth: @booth.location) + redirect_to officing_root_path end private diff --git a/app/views/layouts/_officing_booth.html.erb b/app/views/layouts/_officing_booth.html.erb new file mode 100644 index 000000000..aa1bd0f1e --- /dev/null +++ b/app/views/layouts/_officing_booth.html.erb @@ -0,0 +1,5 @@ +<% if current_user.poll_officer? %> +
+ <%= t("admin.officing_booth.title", booth: current_booth.try(:location)) %> +
+<% end %> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 4b772f614..6b231ce49 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -33,6 +33,7 @@
<%= render "layouts/flash" %> + <%= render "layouts/officing_booth" %> <%= yield %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 156702512..582a1c740 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -14,6 +14,8 @@ en: edit: Edit configure: Configure delete: Delete + officing_booth: + title: "You are officing the booth located at %{booth}. If this is not correct, do not continue and call the help phone number. Thank you." banners: index: title: Banners diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index 9533f6bb8..e377654f0 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -19,7 +19,6 @@ en: booth: new: title: "Choose your booth" - success: "You are officing the booth located at %{booth}. If this is not correct, do not continue and call the help phone number. Thank you." results: flash: create: "Results saved" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 456238bcc..9e2f54a62 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -14,6 +14,8 @@ es: edit: Editar configure: Configurar delete: Borrar + officing_booth: + title: "Estás ahora mismo en la mesa ubicada en %{booth}. Si esto no es correcto no sigas adelante y llama al teléfono de incidencias. Gracias." banners: index: title: Banners diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index 1c6bae97b..e25f9cde8 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -19,7 +19,6 @@ es: booth: new: title: "Escoge tu urna" - success: "Estás ahora mismo en la mesa ubicada en %{booth}. Si esto no es correcto no sigas adelante y llama al teléfono de incidencias. Gracias." results: flash: create: "Datos guardados" diff --git a/spec/features/officing/booth_spec.rb b/spec/features/officing/booth_spec.rb index 8f0e6cd3d..bbab9f53f 100644 --- a/spec/features/officing/booth_spec.rb +++ b/spec/features/officing/booth_spec.rb @@ -30,7 +30,9 @@ feature "Booth" do login_through_form_as(officer.user) - expect(page).to have_content "You are officing the booth located at #{booth.location}." + within("#officing-booth") do + expect(page).to have_content "You are officing the booth located at #{booth.location}." + end end scenario "Officer with multiple booth assignments today" do @@ -54,7 +56,9 @@ feature "Booth" do select booth2.location, from: "booth_id" click_button "Enter" - expect(page).to have_content "You are officing the booth located at #{booth2.location}." + within("#officing-booth") do + expect(page).to have_content "You are officing the booth located at #{booth2.location}." + end end scenario "Display single booth for any number of polls" do From 0acec655e2fcdded2ea808c381df80a92d01153e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Feb 2017 18:26:37 +0100 Subject: [PATCH 11/34] fixes specs --- spec/features/officing/residence_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/features/officing/residence_spec.rb b/spec/features/officing/residence_spec.rb index a55fb8b3e..c956bc31d 100644 --- a/spec/features/officing/residence_spec.rb +++ b/spec/features/officing/residence_spec.rb @@ -106,7 +106,9 @@ feature "Residence", :with_frozen_time do # set_officing_booth(booth) visit new_officing_residence_path - expect(page).to have_content "You are officing booth #{booth.name}" + within("#officing-booth") do + expect(page).to have_content "You are officing the booth located at #{booth.location}." + end visit new_officing_residence_path officing_verify_residence From 88c801d6c537f6447e32280007b1723deff740bf Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 21 Mar 2017 17:01:22 +0100 Subject: [PATCH 12/34] fixes specs --- spec/features/officing/booth_spec.rb | 12 +++++------- spec/features/officing/residence_spec.rb | 2 +- spec/features/officing/voters_spec.rb | 2 +- spec/features/officing_spec.rb | 1 + 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/spec/features/officing/booth_spec.rb b/spec/features/officing/booth_spec.rb index bbab9f53f..78fe6eeb8 100644 --- a/spec/features/officing/booth_spec.rb +++ b/spec/features/officing/booth_spec.rb @@ -5,7 +5,7 @@ feature "Booth" do scenario "Officer with no booth assignments today" do officer = create(:poll_officer) - login_through_form_as(officer.user) + login_through_form_as_officer(officer.user) expect(page).to have_content "You don't have officing shifts today" end @@ -14,7 +14,7 @@ feature "Booth" do officer = create(:poll_officer) create(:poll_officer_assignment, officer: officer, date: 1.day.from_now) - login_through_form_as(officer.user) + login_through_form_as_officer(officer.user) expect(page).to have_content "You don't have officing shifts today" end @@ -28,7 +28,7 @@ feature "Booth" do booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment, date: Date.today) - login_through_form_as(officer.user) + login_through_form_as_officer(officer.user) within("#officing-booth") do expect(page).to have_content "You are officing the booth located at #{booth.location}." @@ -48,9 +48,8 @@ feature "Booth" do create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.today) create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.today) - login_through_form_as(officer.user) + login_through_form_as_officer(officer.user) - expect(page).to have_content "You have been signed in successfully." expect(page).to have_content "Choose your booth" select booth2.location, from: "booth_id" @@ -78,9 +77,8 @@ feature "Booth" do create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.today) create(:poll_officer_assignment, officer: officer, booth_assignment: ba3, date: Date.today) - login_through_form_as(officer.user) + login_through_form_as_officer(officer.user) - expect(page).to have_content "You have been signed in successfully." expect(page).to have_content "Choose your booth" expect(page).to have_select("booth_id", options: [booth1.location, booth2.location]) diff --git a/spec/features/officing/residence_spec.rb b/spec/features/officing/residence_spec.rb index c956bc31d..c4c7784bc 100644 --- a/spec/features/officing/residence_spec.rb +++ b/spec/features/officing/residence_spec.rb @@ -25,7 +25,7 @@ feature "Residence", :with_frozen_time do background do create(:poll_officer_assignment, officer: officer) - login_through_form_as(officer.user) + login_through_form_as_officer(officer.user) visit officing_root_path end diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 264319f70..61b9ea221 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -61,7 +61,7 @@ feature "Voters" do visit root_path click_link "Sign out" - login_through_form_as(officer.user) + login_through_form_as_officer(officer.user) visit new_officing_residence_path officing_verify_residence diff --git a/spec/features/officing_spec.rb b/spec/features/officing_spec.rb index 0d865b13f..fe03d5eef 100644 --- a/spec/features/officing_spec.rb +++ b/spec/features/officing_spec.rb @@ -97,6 +97,7 @@ feature "Poll Officing" do end scenario "Poll officer access links" do + create(:poll) create(:poll_officer, user: user) login_as(user) visit root_path From 77930d3275e6d73628fe48b46a5e15b19046e4c8 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 16 Oct 2017 12:06:18 +0200 Subject: [PATCH 13/34] Enable officing panel booth selection back --- app/controllers/officing/results_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index 54bb1076c..6d373046b 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -8,6 +8,8 @@ class Officing::ResultsController < Officing::BaseController before_action :check_officer_assignment, only: :create before_action :build_results, only: :create + before_action :verify_booth + def new end From 80a9ba8aa7de7a14a39e9bddd75ad2758984d179 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 16 Oct 2017 19:03:19 +0200 Subject: [PATCH 14/34] Enable and fix booth selection back --- app/controllers/officing/base_controller.rb | 13 ++++++++++- app/controllers/officing/booth_controller.rb | 23 ++----------------- app/controllers/officing/polls_controller.rb | 1 + .../officing/results_controller.rb | 1 - spec/features/officing/residence_spec.rb | 7 ++---- spec/features/officing/voters_spec.rb | 8 +++++-- 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/app/controllers/officing/base_controller.rb b/app/controllers/officing/base_controller.rb index 7d9bf225d..729490ba4 100644 --- a/app/controllers/officing/base_controller.rb +++ b/app/controllers/officing/base_controller.rb @@ -27,7 +27,14 @@ class Officing::BaseController < ApplicationController end def verify_booth - if current_booth.blank? + return unless current_booth.blank? + booths = todays_booths_for_officer(current_user.poll_officer) + case booths.count + when 0 + redirect_to officing_root_path + when 1 + session[:booth_id] = booths.first.id + else redirect_to new_officing_booth_path end end @@ -36,4 +43,8 @@ class Officing::BaseController < ApplicationController Poll::Booth.where(id: session[:booth_id]).first end + def todays_booths_for_officer(officer) + officer.officer_assignments.by_date(Date.today).map(&:booth).uniq + end + end diff --git a/app/controllers/officing/booth_controller.rb b/app/controllers/officing/booth_controller.rb index 383154f97..68e33dd61 100644 --- a/app/controllers/officing/booth_controller.rb +++ b/app/controllers/officing/booth_controller.rb @@ -3,17 +3,11 @@ class Officing::BoothController < Officing::BaseController before_action :verify_officer_assignment def new - load_booths - - if only_one_booth? - set_booth(@booths.first) - redirect_to officing_root_path - end + @booths = todays_booths_for_officer(current_user.poll_officer) end def create - find_booth - set_booth(@booth) + set_booth(Poll::Booth.find(booth_params[:id])) redirect_to officing_root_path end @@ -23,19 +17,6 @@ class Officing::BoothController < Officing::BaseController params.require(:booth).permit(:id) end - def load_booths - officer = current_user.poll_officer - @booths = officer.officer_assignments.by_date(Date.today).map(&:booth).uniq - end - - def only_one_booth? - @booths.count == 1 - end - - def find_booth - @booth = Poll::Booth.find(booth_params[:id]) - end - def set_booth(booth) session[:booth_id] = booth.id end diff --git a/app/controllers/officing/polls_controller.rb b/app/controllers/officing/polls_controller.rb index 69b65ad23..dc806d35f 100644 --- a/app/controllers/officing/polls_controller.rb +++ b/app/controllers/officing/polls_controller.rb @@ -1,4 +1,5 @@ class Officing::PollsController < Officing::BaseController + before_action :verify_booth def index @polls = current_user.poll_officer? ? current_user.poll_officer.voting_days_assigned_polls : [] diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index 6d373046b..ff9bf3925 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -7,7 +7,6 @@ class Officing::ResultsController < Officing::BaseController before_action :load_officer_assignment, only: :create before_action :check_officer_assignment, only: :create before_action :build_results, only: :create - before_action :verify_booth def new diff --git a/spec/features/officing/residence_spec.rb b/spec/features/officing/residence_spec.rb index c4c7784bc..aeae7fb2c 100644 --- a/spec/features/officing/residence_spec.rb +++ b/spec/features/officing/residence_spec.rb @@ -97,20 +97,17 @@ feature "Residence", :with_frozen_time do booth = create(:poll_booth) poll = create(:poll) - ba = create(:poll_booth_assignment, poll: poll, booth: booth ) + ba = create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_officer_assignment, officer: officer, booth_assignment: ba) + create(:poll_shift, officer: officer, booth: booth, date: Time.zone.today) login_as(officer.user) - # User somehow skips setting session[:booth_id] - # set_officing_booth(booth) - visit new_officing_residence_path within("#officing-booth") do expect(page).to have_content "You are officing the booth located at #{booth.location}." end - visit new_officing_residence_path officing_verify_residence expect(page).to have_content poll.name diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 61b9ea221..1e39ec2d7 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -17,6 +17,8 @@ feature "Voters" do scenario "Can vote", :js do create(:poll_officer_assignment, officer: officer) + officer_assignment = create(:poll_officer_assignment, officer: officer) + set_officing_booth(officer_assignment.booth) visit new_officing_residence_path officing_verify_residence @@ -38,10 +40,11 @@ feature "Voters" do scenario "Already voted", :js do poll2 = create(:poll, :current) booth_assignment = create(:poll_booth_assignment, poll: poll2, booth: booth) - create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + officer_assignment = create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) user = create(:user, :level_two) voter = create(:poll_voter, poll: poll, user: user) + set_officing_booth(officer_assignment.booth) visit new_officing_voter_path(id: voter.user.id) @@ -74,7 +77,7 @@ feature "Voters" do poll_current = create(:poll, :current) second_booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll_current, booth: second_booth) - create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + officer_assignment = create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) create(:poll_shift, officer: officer, booth: second_booth, date: Date.current, task: :recount_scrutiny) create(:poll_shift, officer: officer, booth: second_booth, date: Date.tomorrow, task: :vote_collection) @@ -89,6 +92,7 @@ feature "Voters" do booth_assignment = create(:poll_booth_assignment, poll: poll_geozone_restricted_out, booth: booth) create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + set_officing_booth(officer_assignment.booth) visit new_officing_residence_path officing_verify_residence From d2e8f8475909856520df9753165c549622f34c4f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 16 Oct 2017 20:29:11 +0200 Subject: [PATCH 15/34] Create missing shift and choose booth for the officer --- spec/features/officing/results_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/features/officing/results_spec.rb b/spec/features/officing/results_spec.rb index 56a0aa4d8..1d67cc1a6 100644 --- a/spec/features/officing/results_spec.rb +++ b/spec/features/officing/results_spec.rb @@ -5,6 +5,7 @@ feature "Officing Results", :with_frozen_time do background do @poll_officer = create(:poll_officer) @officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer) + create(:poll_shift, officer: @poll_officer, booth: @officer_assignment.booth, date: Time.zone.today) @poll = @officer_assignment.booth_assignment.poll @poll.update(ends_at: 1.day.ago) @question_1 = create(:poll_question, poll: @poll) @@ -30,6 +31,9 @@ feature "Officing Results", :with_frozen_time do click_link "Polling officers" expect(page).to have_content("Poll officing") + + set_officing_booth(@officer_assignment.booth) + within("#side_menu") do click_link "Total recounts and results" end From 49ffcfac0666d3b94855371e5f0730bba293aabb Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 18 Oct 2017 16:35:26 +0200 Subject: [PATCH 16/34] Move set officing booth helper method calls to background block --- spec/features/officing/results_spec.rb | 3 +-- spec/features/officing/voters_spec.rb | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/spec/features/officing/results_spec.rb b/spec/features/officing/results_spec.rb index 1d67cc1a6..75735a497 100644 --- a/spec/features/officing/results_spec.rb +++ b/spec/features/officing/results_spec.rb @@ -16,6 +16,7 @@ feature "Officing Results", :with_frozen_time do create(:poll_question_answer, title: "Tomorrow", question: @question_2) login_as(@poll_officer.user) + set_officing_booth(@officer_assignment.booth) end scenario "Only polls where user is officer for results are accessible" do @@ -32,8 +33,6 @@ feature "Officing Results", :with_frozen_time do expect(page).to have_content("Poll officing") - set_officing_booth(@officer_assignment.booth) - within("#side_menu") do click_link "Total recounts and results" end diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 1e39ec2d7..924096f82 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -12,13 +12,12 @@ feature "Voters" do create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + set_officing_booth(booth) end scenario "Can vote", :js do create(:poll_officer_assignment, officer: officer) - officer_assignment = create(:poll_officer_assignment, officer: officer) - set_officing_booth(officer_assignment.booth) visit new_officing_residence_path officing_verify_residence @@ -40,11 +39,10 @@ feature "Voters" do scenario "Already voted", :js do poll2 = create(:poll, :current) booth_assignment = create(:poll_booth_assignment, poll: poll2, booth: booth) - officer_assignment = create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) user = create(:user, :level_two) voter = create(:poll_voter, poll: poll, user: user) - set_officing_booth(officer_assignment.booth) visit new_officing_voter_path(id: voter.user.id) From 8e610756594245407c5180f7f5c104395c333e60 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 18 Oct 2017 19:46:56 +0200 Subject: [PATCH 17/34] Make clearer the set officing booth usage for secondary booth --- spec/features/officing/voters_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 924096f82..d5db0bde2 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -75,7 +75,7 @@ feature "Voters" do poll_current = create(:poll, :current) second_booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll_current, booth: second_booth) - officer_assignment = create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) create(:poll_shift, officer: officer, booth: second_booth, date: Date.current, task: :recount_scrutiny) create(:poll_shift, officer: officer, booth: second_booth, date: Date.tomorrow, task: :vote_collection) @@ -90,7 +90,7 @@ feature "Voters" do booth_assignment = create(:poll_booth_assignment, poll: poll_geozone_restricted_out, booth: booth) create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) - set_officing_booth(officer_assignment.booth) + set_officing_booth(second_booth) visit new_officing_residence_path officing_verify_residence From 69bcd8ec9ae3242eb2c0dc0227997fbfff66cbed Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 20 Oct 2017 23:28:58 +0200 Subject: [PATCH 18/34] Set booth and officer assignments to Poll Voter on officing panel --- app/controllers/officing/voters_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 49b7636fd..78233d41c 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -20,6 +20,7 @@ class Officing::VotersController < Officing::BaseController poll: @poll, origin: "booth", officer: current_user.poll_officer, + booth_assignment: Poll::BoothAssignment.where(poll: @poll, booth: current_booth).first, officer_assignment: officer_assignment(@poll)) @voter.save! end @@ -35,6 +36,7 @@ class Officing::VotersController < Officing::BaseController .by_poll(poll) .by_booth(current_booth) .by_date(Date.current) + .where(final: false) .first end From 4e4057573d6630cbf6a31fedea0832af0c367e40 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 21 Oct 2017 00:23:33 +0200 Subject: [PATCH 19/34] Fix store officer and booth info spec --- spec/features/officing/voters_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index d5db0bde2..fabea072a 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -107,13 +107,15 @@ feature "Voters" do poll1 = create(:poll, name: "¿Quieres que XYZ sea aprobado?") poll2 = create(:poll, name: "Pregunta de votación de prueba") - ba1 = create(:poll_booth_assignment, poll: poll1) - ba2 = create(:poll_booth_assignment, poll: poll2) - oa1 = create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.current) - oa2 = create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.current) + second_booth = create(:poll_booth) + + ba1 = create(:poll_booth_assignment, poll: poll1, booth: second_booth ) + ba2 = create(:poll_booth_assignment, poll: poll2, booth: second_booth ) + create(:poll_shift, officer: officer, booth: second_booth, date: Date.current, task: :vote_collection) validate_officer visit new_officing_residence_path + set_officing_booth(second_booth) officing_verify_residence within("#poll_#{poll1.id}") do @@ -133,10 +135,10 @@ feature "Voters" do voter1 = Poll::Voter.first expect(voter1.booth_assignment).to eq(ba1) - expect(voter1.officer_assignment).to eq(oa1) + expect(voter1.officer_assignment).not_to be_nil voter2 = Poll::Voter.last expect(voter2.booth_assignment).to eq(ba2) - expect(voter2.officer_assignment).to eq(oa2) + expect(voter2.officer_assignment).not_to be_nil end end From 94c37eb588795bf4952006a83b2da0b9e0173471 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 21 Oct 2017 00:24:49 +0200 Subject: [PATCH 20/34] Fix store officer and booth info spec --- spec/features/officing/voters_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index fabea072a..2f21234e7 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -135,10 +135,10 @@ feature "Voters" do voter1 = Poll::Voter.first expect(voter1.booth_assignment).to eq(ba1) - expect(voter1.officer_assignment).not_to be_nil + expect(voter1.officer_assignment).to eq(ba1.officer_assignments.first) voter2 = Poll::Voter.last expect(voter2.booth_assignment).to eq(ba2) - expect(voter2.officer_assignment).not_to be_nil + expect(voter2.officer_assignment).to eq(ba2.officer_assignments.first) end end From 31428a5847cde83806f85b1b2f4bf0d0ca98ac01 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 21 Oct 2017 01:09:53 +0200 Subject: [PATCH 21/34] Add booth and officing assigments presence validation for booth votes, unskip specs --- app/models/poll/voter.rb | 2 ++ spec/models/poll/voter_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index da05b1bc6..1e4a0d204 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -12,6 +12,8 @@ class Poll validates :poll_id, presence: true validates :user_id, presence: true + validates :booth_assignment_id, presence: true, if: ->(voter) { voter.origin == "booth" } + validates :officer_assignment_id, presence: true, if: ->(voter) { voter.origin == "booth" } validates :document_number, presence: true, uniqueness: { scope: [:poll_id, :document_type], message: :has_voted } validates :origin, inclusion: { in: VALID_ORIGINS } diff --git a/spec/models/poll/voter_spec.rb b/spec/models/poll/voter_spec.rb index 85c72aa7d..3ebab9818 100644 --- a/spec/models/poll/voter_spec.rb +++ b/spec/models/poll/voter_spec.rb @@ -6,6 +6,7 @@ describe Poll::Voter do let(:booth) { create(:poll_booth) } let(:booth_assignment) { create(:poll_booth_assignment, poll: poll, booth: booth) } let(:voter) { create(:poll_voter) } + let(:officer_assignment) { create(:poll_officer_assignment) } describe "validations" do @@ -97,6 +98,7 @@ describe Poll::Voter do it "is valid with a booth origin" do voter.origin = "booth" + voter.officer_assignment = officer_assignment expect(voter).to be_valid end @@ -104,7 +106,27 @@ describe Poll::Voter do voter.origin = "web" expect(voter).to be_valid end + end + context "assignments" do + it "should not be valid without a booth_assignment_id when origin is booth" do + voter.origin = "booth" + voter.booth_assignment_id = nil + expect(voter).not_to be_valid + end + + it "should not be valid without an officer_assignment_id when origin is booth" do + voter.origin = "booth" + voter.officer_assignment_id = nil + expect(voter).not_to be_valid + end + + it "should be valid without assignments when origin is web" do + voter.origin = "web" + voter.booth_assignment_id = nil + voter.officer_assignment_id = nil + expect(voter).to be_valid + end end end From 9c7962c3a68ad11783e29bb3b8e1b02029819860 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 21 Oct 2017 01:24:00 +0200 Subject: [PATCH 22/34] Check poll recount values for booth votes on admin panel --- app/views/admin/poll/recounts/index.html.erb | 4 +- spec/features/polls/voter_spec.rb | 40 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb index 692078340..5a9766e94 100644 --- a/app/views/admin/poll/recounts/index.html.erb +++ b/app/views/admin/poll/recounts/index.html.erb @@ -43,14 +43,14 @@ <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: "tab-recounts") %> - "> + " id="<%= dom_id(booth_assignment) %>_recount"> <% if total_recounts.present? %> <%= total_recounts %> <% else %> - <% end %> - + <% if system_count.present? %> <%= system_count %> <% else %> diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 8e0271f8f..9c9f6cd1e 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -8,6 +8,7 @@ feature "Voter" do let(:question) { create(:poll_question, poll: poll) } let(:booth) { create(:poll_booth) } let(:officer) { create(:poll_officer) } + let(:admin) { create(:administrator) } let!(:answer_yes) { create(:poll_question_answer, question: question, title: "Yes") } let!(:answer_no) { create(:poll_question_answer, question: question, title: "No") } @@ -71,6 +72,19 @@ feature "Voter" do expect(Poll::Voter.count).to eq(1) expect(Poll::Voter.first.origin).to eq("booth") + + visit root_path + click_link "Sign out" + login_as(admin.user) + visit admin_poll_recounts_path(poll) + + within("#total_system") do + expect(page).to have_content "1" + end + + within("#poll_booth_assignment_#{Poll::BoothAssignment.where(poll: poll, booth: booth).first.id}_recounts") do + expect(page).to have_content "1" + end end context "Trying to vote the same poll in booth and web" do @@ -107,6 +121,19 @@ feature "Voter" do expect(page).not_to have_link(answer_yes.title) expect(page).to have_content "You have already participated in a physical booth. You can not participate again." expect(Poll::Voter.count).to eq(1) + + visit root_path + click_link "Sign out" + login_as(admin.user) + visit admin_poll_recounts_path(poll) + + within("#total_system") do + expect(page).to have_content "1" + end + + within("#poll_booth_assignment_#{Poll::BoothAssignment.where(poll: poll, booth: booth).first.id}_recounts") do + expect(page).to have_content "1" + end end scenario "Trying to vote in web again", :js do @@ -162,6 +189,19 @@ feature "Voter" do expect(page).not_to have_link(answer_yes.title) expect(page).to have_content "You have already participated in a physical booth. You can not participate again." expect(Poll::Voter.count).to eq(1) + + visit root_path + click_link "Sign out" + login_as(admin.user) + visit admin_poll_recounts_path(poll) + + within("#total_system") do + expect(page).to have_content "1" + end + + within("#poll_booth_assignment_#{Poll::BoothAssignment.where(poll: poll, booth: booth).first.id}_recounts") do + expect(page).to have_content "1" + end end context "Side menu" do From 71bd6e41c602b4c4dd71450d78f9f39865865238 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 17 Jan 2018 00:46:58 +0100 Subject: [PATCH 23/34] Replace time.zone.today for date.current --- spec/features/officing/residence_spec.rb | 2 +- spec/features/officing/results_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/officing/residence_spec.rb b/spec/features/officing/residence_spec.rb index aeae7fb2c..3908fa546 100644 --- a/spec/features/officing/residence_spec.rb +++ b/spec/features/officing/residence_spec.rb @@ -99,7 +99,7 @@ feature "Residence", :with_frozen_time do ba = create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_officer_assignment, officer: officer, booth_assignment: ba) - create(:poll_shift, officer: officer, booth: booth, date: Time.zone.today) + create(:poll_shift, officer: officer, booth: booth, date: Date.current) login_as(officer.user) diff --git a/spec/features/officing/results_spec.rb b/spec/features/officing/results_spec.rb index 75735a497..54d674220 100644 --- a/spec/features/officing/results_spec.rb +++ b/spec/features/officing/results_spec.rb @@ -5,7 +5,7 @@ feature "Officing Results", :with_frozen_time do background do @poll_officer = create(:poll_officer) @officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer) - create(:poll_shift, officer: @poll_officer, booth: @officer_assignment.booth, date: Time.zone.today) + create(:poll_shift, officer: @poll_officer, booth: @officer_assignment.booth, date: Date.current) @poll = @officer_assignment.booth_assignment.poll @poll.update(ends_at: 1.day.ago) @question_1 = create(:poll_question, poll: @poll) From a9d1fd35396c79b4bfb6082a89c2263d1e0f88e3 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 8 Mar 2018 11:38:02 +0100 Subject: [PATCH 24/34] Fix for issues 1202, 1203 and 1204. Stub the Date and Time functions in the booth_spec test so that it won't give errors when running tests at midnight. --- spec/features/officing/booth_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/features/officing/booth_spec.rb b/spec/features/officing/booth_spec.rb index 78fe6eeb8..72eddbdbc 100644 --- a/spec/features/officing/booth_spec.rb +++ b/spec/features/officing/booth_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -feature "Booth" do +feature "Booth", :with_frozen_time do scenario "Officer with no booth assignments today" do officer = create(:poll_officer) @@ -12,7 +12,7 @@ feature "Booth" do scenario "Officer with booth assignments another day" do officer = create(:poll_officer) - create(:poll_officer_assignment, officer: officer, date: 1.day.from_now) + create(:poll_officer_assignment, officer: officer, date: Date.current + 1.day) login_through_form_as_officer(officer.user) @@ -26,7 +26,7 @@ feature "Booth" do booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment, date: Date.today) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment, date: Date.current) login_through_form_as_officer(officer.user) @@ -45,8 +45,8 @@ feature "Booth" do ba1 = create(:poll_booth_assignment, poll: poll, booth: booth1) ba2 = create(:poll_booth_assignment, poll: poll, booth: booth2) - create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.today) - create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.today) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.current) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.current) login_through_form_as_officer(officer.user) @@ -73,9 +73,9 @@ feature "Booth" do ba2 = create(:poll_booth_assignment, poll: poll2, booth: booth2) ba3 = create(:poll_booth_assignment, poll: poll2, booth: booth2) - create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.today) - create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.today) - create(:poll_officer_assignment, officer: officer, booth_assignment: ba3, date: Date.today) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: Date.current) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: Date.current) + create(:poll_officer_assignment, officer: officer, booth_assignment: ba3, date: Date.current) login_through_form_as_officer(officer.user) From f7f9fc15a58a9e26a6a700903398aaa5bd4a1d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 31 Aug 2018 05:47:11 +0200 Subject: [PATCH 25/34] Move `todays_booths_for_officer` to the model This way we can easily add a test which will fail if by accident we change the method to use `Date.today`. Until now using `Date.today` would only fail if we ran specs in a time zone with a different date. --- app/controllers/officing/base_controller.rb | 6 +----- app/controllers/officing/booth_controller.rb | 2 +- app/models/poll/officer.rb | 4 ++++ spec/models/poll/officer_spec.rb | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/controllers/officing/base_controller.rb b/app/controllers/officing/base_controller.rb index 729490ba4..58ba3c8b2 100644 --- a/app/controllers/officing/base_controller.rb +++ b/app/controllers/officing/base_controller.rb @@ -28,7 +28,7 @@ class Officing::BaseController < ApplicationController def verify_booth return unless current_booth.blank? - booths = todays_booths_for_officer(current_user.poll_officer) + booths = current_user.poll_officer.todays_booths case booths.count when 0 redirect_to officing_root_path @@ -43,8 +43,4 @@ class Officing::BaseController < ApplicationController Poll::Booth.where(id: session[:booth_id]).first end - def todays_booths_for_officer(officer) - officer.officer_assignments.by_date(Date.today).map(&:booth).uniq - end - end diff --git a/app/controllers/officing/booth_controller.rb b/app/controllers/officing/booth_controller.rb index 68e33dd61..584c92de0 100644 --- a/app/controllers/officing/booth_controller.rb +++ b/app/controllers/officing/booth_controller.rb @@ -3,7 +3,7 @@ class Officing::BoothController < Officing::BaseController before_action :verify_officer_assignment def new - @booths = todays_booths_for_officer(current_user.poll_officer) + @booths = current_user.poll_officer.todays_booths end def create diff --git a/app/models/poll/officer.rb b/app/models/poll/officer.rb index 384202455..ef96cfa91 100644 --- a/app/models/poll/officer.rb +++ b/app/models/poll/officer.rb @@ -23,5 +23,9 @@ class Poll sort {|x, y| y.ends_at <=> x.ends_at} end + def todays_booths + officer_assignments.by_date(Date.current).map(&:booth).uniq + end + end end diff --git a/spec/models/poll/officer_spec.rb b/spec/models/poll/officer_spec.rb index 1cbad6f5d..4cdc581b1 100644 --- a/spec/models/poll/officer_spec.rb +++ b/spec/models/poll/officer_spec.rb @@ -121,4 +121,21 @@ describe Poll::Officer do expect(assigned_polls.last).to eq(poll_3) end end + + describe "todays_booths" do + let(:officer) { create(:poll_officer) } + + it "returns booths for the application's time zone date", :with_different_time_zone do + assignment_with_local_time_zone = create(:poll_officer_assignment, + date: Date.today, + officer: officer) + + assignment_with_application_time_zone = create(:poll_officer_assignment, + date: Date.current, + officer: officer) + + expect(officer.todays_booths).to include(assignment_with_application_time_zone.booth) + expect(officer.todays_booths).not_to include(assignment_with_local_time_zone.booth) + end + end end From e2fa2ecf0d97167f4dabb286fbb72cc4ac33499e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 14 Dec 2018 14:19:07 +0100 Subject: [PATCH 26/34] Avoid outer variable shadowing warning There were two variables named "title", one for the question and one for the answer. --- db/dev_seeds/polls.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb index 26256981d..15e1595d4 100644 --- a/db/dev_seeds/polls.rb +++ b/db/dev_seeds/polls.rb @@ -42,24 +42,24 @@ end section "Creating Poll Questions & Answers" do Poll.find_each do |poll| (1..4).to_a.sample.times do - title = Faker::Lorem.sentence(3).truncate(60) + "?" + question_title = Faker::Lorem.sentence(3).truncate(60) + "?" question = Poll::Question.new(author: User.all.sample, - title: title, + title: question_title, poll: poll) I18n.available_locales.map do |locale| Globalize.with_locale(locale) do - question.title = "#{title} (#{locale})" + question.title = "#{question_title} (#{locale})" end end question.save! - Faker::Lorem.words((2..4).to_a.sample).each do |title| + Faker::Lorem.words((2..4).to_a.sample).each do |answer_title| description = "

#{Faker::Lorem.paragraphs.join("

")}

" answer = Poll::Question::Answer.new(question: question, - title: title.capitalize, + title: answer_title.capitalize, description: description) I18n.available_locales.map do |locale| Globalize.with_locale(locale) do - answer.title = "#{title} (#{locale})" + answer.title = "#{answer_title} (#{locale})" answer.description = "#{description} (#{locale})" end end From db7e8e79b7fbd54324709b4f79f624ca3ff60bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 14 Dec 2018 13:56:06 +0100 Subject: [PATCH 27/34] Fix voters on booth not being created in dev seeds There were validation errors because they didn't have officer nor booth assignments. --- db/dev_seeds/polls.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb index 15e1595d4..5f96445ba 100644 --- a/db/dev_seeds/polls.rb +++ b/db/dev_seeds/polls.rb @@ -114,12 +114,16 @@ end section "Creating Poll Voters" do def vote_poll_on_booth(user, poll) + officer = Poll::Officer.all.sample + Poll::Voter.create!(document_type: user.document_type, document_number: user.document_number, user: user, poll: poll, origin: "booth", - officer: Poll::Officer.all.sample) + officer: officer, + officer_assignment: officer.officer_assignments.sample, + booth_assignment: poll.booth_assignments.sample) end def vote_poll_on_web(user, poll) From 6ac91dafa8a0eb0788aef20b3c4548f643dbc767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 14 Dec 2018 14:11:45 +0100 Subject: [PATCH 28/34] Include level 3 users in dev seeds poll voters --- db/dev_seeds/polls.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb index 5f96445ba..f731876c0 100644 --- a/db/dev_seeds/polls.rb +++ b/db/dev_seeds/polls.rb @@ -146,11 +146,11 @@ section "Creating Poll Voters" do end (Poll.expired + Poll.current + Poll.recounting).uniq.each do |poll| - level_two_verified_users = User.level_two_verified + verified_users = User.level_two_or_three_verified if poll.geozone_restricted? - level_two_verified_users = level_two_verified_users.where(geozone_id: poll.geozone_ids) + verified_users = verified_users.where(geozone_id: poll.geozone_ids) end - user_groups = level_two_verified_users.in_groups(2) + user_groups = verified_users.in_groups(2) user_groups.first.each { |user| vote_poll_on_booth(user, poll) } user_groups.second.compact.each { |user| vote_poll_on_web(user, poll) } end From 061549c3c3940b039ec918eb96912a71f32e0393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 14 Dec 2018 18:07:54 +0100 Subject: [PATCH 29/34] Use booth voters to create recount in dev seeds --- db/dev_seeds/polls.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb index f731876c0..eb9b0d99f 100644 --- a/db/dev_seeds/polls.rb +++ b/db/dev_seeds/polls.rb @@ -162,13 +162,23 @@ section "Creating Poll Recounts" do officer_assignment = poll.officer_assignments.first author = Poll::Officer.first.user + total_amount = white_amount = null_amount = 0 + + booth_assignment.voters.count.times do + case rand + when 0...0.1 then null_amount += 1 + when 0.1...0.2 then white_amount += 1 + else total_amount += 1 + end + end + Poll::Recount.create!(officer_assignment: officer_assignment, booth_assignment: booth_assignment, author: author, date: poll.ends_at, - white_amount: rand(0..10), - null_amount: rand(0..10), - total_amount: rand(100..9999), + white_amount: white_amount, + null_amount: null_amount, + total_amount: total_amount, origin: "booth") end end From 99551e048b7b194ce58b242af378f55d60ade032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 14 Dec 2018 18:27:47 +0100 Subject: [PATCH 30/34] Fix user gender creation We use "male" and "female" conditions in scopes. --- db/dev_seeds/users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dev_seeds/users.rb b/db/dev_seeds/users.rb index 199b16dfb..95330b645 100644 --- a/db/dev_seeds/users.rb +++ b/db/dev_seeds/users.rb @@ -8,7 +8,7 @@ section "Creating Users" do password_confirmation: password, confirmed_at: Time.current, terms_of_service: "1", - gender: ["Male", "Female"].sample, + gender: %w[male female].sample, date_of_birth: rand((Time.current - 80.years)..(Time.current - 16.years)), public_activity: (rand(1..100) > 30) ) From 9329e4b6ea9504dd4b34165e73b245ec908aa6c9 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Feb 2017 18:58:55 +0100 Subject: [PATCH 31/34] hot fix current booth --- app/views/layouts/_officing_booth.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_officing_booth.html.erb b/app/views/layouts/_officing_booth.html.erb index aa1bd0f1e..bee7e78d7 100644 --- a/app/views/layouts/_officing_booth.html.erb +++ b/app/views/layouts/_officing_booth.html.erb @@ -1,5 +1,5 @@ <% if current_user.poll_officer? %>
- <%= t("admin.officing_booth.title", booth: current_booth.try(:location)) %> + <%= t("admin.officing_booth.title", booth: try(:current_booth).try(:location)) %>
<% end %> From 18e57b96620db052c1422082ee113b3f394da8ff Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 20 Jun 2018 14:37:36 +0200 Subject: [PATCH 32/34] Hides sibebar menu if officer has no shifts --- app/helpers/officers_helper.rb | 2 +- spec/features/budget_polls/officing_spec.rb | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/helpers/officers_helper.rb b/app/helpers/officers_helper.rb index e069cb9aa..06dd041ed 100644 --- a/app/helpers/officers_helper.rb +++ b/app/helpers/officers_helper.rb @@ -5,7 +5,7 @@ module OfficersHelper end def vote_collection_shift? - current_user.poll_officer.officer_assignments.where(date: Time.current.to_date).any? + current_user.poll_officer.officer_assignments.voting_days.where(date: Time.current.to_date).any? end def final_recount_shift? diff --git a/spec/features/budget_polls/officing_spec.rb b/spec/features/budget_polls/officing_spec.rb index 7f77b5caa..7b91eec12 100644 --- a/spec/features/budget_polls/officing_spec.rb +++ b/spec/features/budget_polls/officing_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" feature "Budget Poll Officing" do - scenario "Show sidebar menu if officer has shifts assigned" do + scenario "Show sidebar menus if officer has shifts assigned" do poll = create(:poll) booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) @@ -10,13 +10,21 @@ feature "Budget Poll Officing" do user = create(:user) officer = create(:poll_officer, user: user) + create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection) + + login_as user + visit officing_root_path + + expect(page).not_to have_content("You don't have officing shifts today") + expect(page).to have_content("Validate document") + expect(page).not_to have_content("Total recounts and results") + create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :recount_scrutiny) officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, officer: officer) - login_as user visit officing_root_path expect(page).not_to have_content("You don't have officing shifts today") @@ -24,7 +32,7 @@ feature "Budget Poll Officing" do expect(page).to have_content("Total recounts and results") end - scenario "Do not show sidebar menu if officer has no shifts assigned" do + scenario "Do not show sidebar menus if officer has no shifts assigned" do user = create(:user) officer = create(:poll_officer, user: user) From 170cc45a2031371f33c746baac3933fa7bc42127 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 20 Jun 2018 14:37:56 +0200 Subject: [PATCH 33/34] Shows message on index if officer has no shifts --- app/helpers/officers_helper.rb | 4 ++++ app/views/officing/dashboard/index.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/officers_helper.rb b/app/helpers/officers_helper.rb index 06dd041ed..1218af80e 100644 --- a/app/helpers/officers_helper.rb +++ b/app/helpers/officers_helper.rb @@ -12,4 +12,8 @@ module OfficersHelper current_user.poll_officer.officer_assignments.final.where(date: Time.current.to_date).any? end + def no_shifts? + current_user.poll_officer.officer_assignments.where(date: Time.current.to_date).blank? + end + end diff --git a/app/views/officing/dashboard/index.html.erb b/app/views/officing/dashboard/index.html.erb index 87ee59926..792786434 100644 --- a/app/views/officing/dashboard/index.html.erb +++ b/app/views/officing/dashboard/index.html.erb @@ -3,7 +3,7 @@

<%= t("officing.dashboard.index.info") %>

- <% unless final_recount_shift? && vote_collection_shift? %> + <% if no_shifts? %>
<%= t("officing.dashboard.index.no_shifts") %>
From 17730a41dd5fd6a6c57f35dd5257c9d00bc3de62 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 20 Jun 2018 14:38:23 +0200 Subject: [PATCH 34/34] Hides not to vote at this time button if already voted --- app/views/officing/voters/create.js.erb | 1 + app/views/officing/voters/new.html.erb | 6 +++- spec/features/polls/voter_spec.rb | 37 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/views/officing/voters/create.js.erb b/app/views/officing/voters/create.js.erb index 676d153bd..eebdb9100 100644 --- a/app/views/officing/voters/create.js.erb +++ b/app/views/officing/voters/create.js.erb @@ -1,3 +1,4 @@ $("#<%= dom_id(@poll) %> #actions").html("<%= j render("voted") %>"); $("#<%= dom_id(@poll) %> #can_vote_callout").hide(); +$("#not_voted").hide(); $(".js-vote-collection").removeClass("is-hidden"); diff --git a/app/views/officing/voters/new.html.erb b/app/views/officing/voters/new.html.erb index 474b3c2a6..a61f4f842 100644 --- a/app/views/officing/voters/new.html.erb +++ b/app/views/officing/voters/new.html.erb @@ -28,4 +28,8 @@ <% end %> -<%= link_to t("officing.voters.new.not_to_vote"), namespaced_root_path, class: "button" %> +<% if Poll.votable_by(@user).any? %> +
+ <%= link_to t("officing.voters.new.not_to_vote"), namespaced_root_path, class: "button" %> +
+<% end %> diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 9c9f6cd1e..9310c2438 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -87,6 +87,43 @@ feature "Voter" do end end + context "The person has decided not to vote at this time" do + let!(:user) { create(:user, :in_census) } + + scenario "Show not to vote at this time button" do + login_through_form_as_officer(officer.user) + + visit new_officing_residence_path + officing_verify_residence + + expect(page).to have_content poll.name + expect(page).to have_button "Confirm vote" + expect(page).to have_content "Can vote" + expect(page).to have_link "The person has decided not to vote at this time" + end + + scenario "Hides not to vote at this time button if already voted", :js do + login_through_form_as_officer(officer.user) + + visit new_officing_residence_path + officing_verify_residence + + within("#poll_#{poll.id}") do + click_button("Confirm vote") + expect(page).not_to have_button("Confirm vote") + expect(page).to have_content "Vote introduced!" + expect(page).not_to have_content "The person has decided not to vote at this time" + end + + visit new_officing_residence_path + officing_verify_residence + + expect(page).to have_content "Has already participated in this poll" + expect(page).not_to have_content "The person has decided not to vote at this time" + end + + end + context "Trying to vote the same poll in booth and web" do let!(:user) { create(:user, :in_census) }