From 74706027cb3329af73caa84d71a81ea79fb9f500 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Feb 2017 15:28:24 +0100 Subject: [PATCH] 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