Deleting a booth shift with recounts or partial results.
Show a flash message that it's not possible to delete booth shifts when they have associated recounts or partial results. Before an execption was raised.
This commit is contained in:
@@ -26,9 +26,14 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
|
|||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@shift = Poll::Shift.find(params[:id])
|
@shift = Poll::Shift.find(params[:id])
|
||||||
@shift.destroy
|
if @shift.unable_to_destroy?
|
||||||
notice = t("admin.poll_shifts.flash.destroy")
|
alert = t("admin.poll_shifts.flash.unable_to_destroy")
|
||||||
redirect_to new_admin_booth_shift_path(@booth), notice: notice
|
redirect_to new_admin_booth_shift_path(@booth), alert: alert
|
||||||
|
else
|
||||||
|
@shift.destroy
|
||||||
|
notice = t("admin.poll_shifts.flash.destroy")
|
||||||
|
redirect_to new_admin_booth_shift_path(@booth), notice: notice
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_officers
|
def search_officers
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ class Poll
|
|||||||
shifts.empty? ? false : true
|
shifts.empty? ? false : true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unable_to_destroy?
|
||||||
|
(partial_results.count + recounts.count).positive?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def shifts
|
def shifts
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ class Poll
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unable_to_destroy?
|
||||||
|
booth.booth_assignments.map(&:unable_to_destroy?).any?
|
||||||
|
end
|
||||||
|
|
||||||
def destroy_officer_assignments
|
def destroy_officer_assignments
|
||||||
Poll::OfficerAssignment.where(booth_assignment: booth.booth_assignments,
|
Poll::OfficerAssignment.where(booth_assignment: booth.booth_assignments,
|
||||||
officer: officer,
|
officer: officer,
|
||||||
|
|||||||
@@ -872,6 +872,7 @@ en:
|
|||||||
flash:
|
flash:
|
||||||
create: "Shift added"
|
create: "Shift added"
|
||||||
destroy: "Shift removed"
|
destroy: "Shift removed"
|
||||||
|
unable_to_destroy: "Shifts with associated results or recounts cannot be deleted"
|
||||||
date_missing: "A date must be selected"
|
date_missing: "A date must be selected"
|
||||||
vote_collection: Collect Votes
|
vote_collection: Collect Votes
|
||||||
recount_scrutiny: Recount & Scrutiny
|
recount_scrutiny: Recount & Scrutiny
|
||||||
|
|||||||
@@ -872,6 +872,7 @@ es:
|
|||||||
flash:
|
flash:
|
||||||
create: "Añadido turno de presidente de mesa"
|
create: "Añadido turno de presidente de mesa"
|
||||||
destroy: "Eliminado turno de presidente de mesa"
|
destroy: "Eliminado turno de presidente de mesa"
|
||||||
|
unable_to_destroy: "No se pueden eliminar turnos que tienen resultados o recuentos asociados"
|
||||||
date_missing: "Debe seleccionarse una fecha"
|
date_missing: "Debe seleccionarse una fecha"
|
||||||
vote_collection: Recoger Votos
|
vote_collection: Recoger Votos
|
||||||
recount_scrutiny: Recuento & Escrutinio
|
recount_scrutiny: Recuento & Escrutinio
|
||||||
|
|||||||
@@ -165,6 +165,58 @@ feature 'Admin shifts' do
|
|||||||
expect(page).to have_css(".shift", count: 0)
|
expect(page).to have_css(".shift", count: 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Try to destroy with associated recount" do
|
||||||
|
assignment = create(:poll_booth_assignment)
|
||||||
|
officer_assignment = create(:poll_officer_assignment, booth_assignment: assignment)
|
||||||
|
create(:poll_recount, booth_assignment: assignment, officer_assignment: officer_assignment)
|
||||||
|
|
||||||
|
officer = officer_assignment.officer
|
||||||
|
booth = assignment.booth
|
||||||
|
shift = create(:poll_shift, officer: officer, booth: booth)
|
||||||
|
|
||||||
|
visit available_admin_booths_path
|
||||||
|
|
||||||
|
within("#booth_#{booth.id}") do
|
||||||
|
click_link "Manage shifts"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_css(".shift", count: 1)
|
||||||
|
within("#shift_#{shift.id}") do
|
||||||
|
click_link "Remove"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).not_to have_content "Shift removed"
|
||||||
|
expect(page).to have_content "Shifts with associated results or recounts cannot be deleted"
|
||||||
|
expect(page).to have_css(".shift", count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "try to destroy with associated partial results" do
|
||||||
|
assignment = create(:poll_booth_assignment)
|
||||||
|
officer_assignment = create(:poll_officer_assignment, booth_assignment: assignment)
|
||||||
|
create(:poll_partial_result,
|
||||||
|
booth_assignment: assignment,
|
||||||
|
officer_assignment: officer_assignment)
|
||||||
|
|
||||||
|
officer = officer_assignment.officer
|
||||||
|
booth = assignment.booth
|
||||||
|
shift = create(:poll_shift, officer: officer, booth: booth)
|
||||||
|
|
||||||
|
visit available_admin_booths_path
|
||||||
|
|
||||||
|
within("#booth_#{booth.id}") do
|
||||||
|
click_link "Manage shifts"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_css(".shift", count: 1)
|
||||||
|
within("#shift_#{shift.id}") do
|
||||||
|
click_link "Remove"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).not_to have_content "Shift removed"
|
||||||
|
expect(page).to have_content "Shifts with associated results or recounts cannot be deleted"
|
||||||
|
expect(page).to have_css(".shift", count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Destroy an officer" do
|
scenario "Destroy an officer" do
|
||||||
poll = create(:poll)
|
poll = create(:poll)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth)
|
||||||
|
|||||||
Reference in New Issue
Block a user