stores the officer that allowed a voter to vote in a physical booth

This commit is contained in:
rgarcia
2017-02-12 13:10:50 +01:00
committed by Javi Martín
parent 34dfeee9c9
commit 5835d12694
2 changed files with 46 additions and 1 deletions

View File

@@ -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

View File

@@ -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