Remove officing final recounts controller, spec and view
This commit is contained in:
@@ -42,7 +42,6 @@ Layout/DotPosition:
|
|||||||
- 'app/controllers/admin/poll/officer_assignments_controller.rb'
|
- 'app/controllers/admin/poll/officer_assignments_controller.rb'
|
||||||
- 'app/controllers/admin/poll/polls_controller.rb'
|
- 'app/controllers/admin/poll/polls_controller.rb'
|
||||||
- 'app/controllers/admin/poll/recounts_controller.rb'
|
- 'app/controllers/admin/poll/recounts_controller.rb'
|
||||||
- 'app/controllers/officing/final_recounts_controller.rb'
|
|
||||||
- 'app/controllers/officing/residence_controller.rb'
|
- 'app/controllers/officing/residence_controller.rb'
|
||||||
- 'app/controllers/officing/results_controller.rb'
|
- 'app/controllers/officing/results_controller.rb'
|
||||||
- 'app/models/poll/officer.rb'
|
- 'app/models/poll/officer.rb'
|
||||||
@@ -191,7 +190,6 @@ Layout/MultilineMethodCallIndentation:
|
|||||||
- 'app/controllers/admin/poll/officer_assignments_controller.rb'
|
- 'app/controllers/admin/poll/officer_assignments_controller.rb'
|
||||||
- 'app/controllers/admin/poll/polls_controller.rb'
|
- 'app/controllers/admin/poll/polls_controller.rb'
|
||||||
- 'app/controllers/admin/poll/recounts_controller.rb'
|
- 'app/controllers/admin/poll/recounts_controller.rb'
|
||||||
- 'app/controllers/officing/final_recounts_controller.rb'
|
|
||||||
- 'app/controllers/officing/residence_controller.rb'
|
- 'app/controllers/officing/residence_controller.rb'
|
||||||
- 'app/controllers/officing/results_controller.rb'
|
- 'app/controllers/officing/results_controller.rb'
|
||||||
- 'app/models/poll/officer.rb'
|
- 'app/models/poll/officer.rb'
|
||||||
@@ -473,7 +471,6 @@ Style/ConditionalAssignment:
|
|||||||
- 'app/controllers/admin/poll/questions_controller.rb'
|
- 'app/controllers/admin/poll/questions_controller.rb'
|
||||||
- 'app/controllers/comments_controller.rb'
|
- 'app/controllers/comments_controller.rb'
|
||||||
- 'app/controllers/management/spending_proposals_controller.rb'
|
- 'app/controllers/management/spending_proposals_controller.rb'
|
||||||
- 'app/controllers/officing/final_recounts_controller.rb'
|
|
||||||
- 'app/controllers/spending_proposals_controller.rb'
|
- 'app/controllers/spending_proposals_controller.rb'
|
||||||
- 'app/controllers/verification/sms_controller.rb'
|
- 'app/controllers/verification/sms_controller.rb'
|
||||||
- 'lib/graph_ql/api_types_creator.rb'
|
- 'lib/graph_ql/api_types_creator.rb'
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
class Officing::FinalRecountsController < Officing::BaseController
|
|
||||||
before_action :load_poll
|
|
||||||
before_action :load_officer_assignment, only: :create
|
|
||||||
|
|
||||||
def new
|
|
||||||
@officer_assignments = ::Poll::OfficerAssignment.
|
|
||||||
includes(:final_recounts, booth_assignment: [:booth]).
|
|
||||||
joins(:booth_assignment).
|
|
||||||
final.
|
|
||||||
where(id: current_user.poll_officer.officer_assignment_ids).
|
|
||||||
where("poll_booth_assignments.poll_id = ?", @poll.id).
|
|
||||||
order(date: :asc)
|
|
||||||
|
|
||||||
@final_recounts = @officer_assignments.select {|oa| oa.final_recounts.any?}.map(&:final_recounts).flatten
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@final_recount = ::Poll::FinalRecount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
|
||||||
date: final_recount_params[:date])
|
|
||||||
@final_recount.officer_assignment_id = @officer_assignment.id
|
|
||||||
@final_recount.count = final_recount_params[:count]
|
|
||||||
|
|
||||||
if @final_recount.save
|
|
||||||
msg = { notice: t("officing.final_recounts.flash.create") }
|
|
||||||
else
|
|
||||||
msg = { alert: t("officing.final_recounts.flash.error_create") }
|
|
||||||
end
|
|
||||||
redirect_to new_officing_poll_final_recount_path(@poll), msg
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def load_poll
|
|
||||||
@poll = Poll.expired.find(params[:poll_id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def load_officer_assignment
|
|
||||||
@officer_assignment = current_user.poll_officer.
|
|
||||||
officer_assignments.final.find_by(id: final_recount_params[:officer_assignment_id])
|
|
||||||
if @officer_assignment.blank?
|
|
||||||
redirect_to new_officing_poll_final_recount_path(@poll), alert: t("officing.final_recounts.flash.error_create")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def final_recount_params
|
|
||||||
params.permit(:officer_assignment_id, :count, :date)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
<% if @officer_assignments.any? %>
|
|
||||||
<h2><%= t("officing.final_recounts.new.title", poll: @poll.name) %></h2>
|
|
||||||
|
|
||||||
<%= form_tag(officing_poll_final_recounts_path(@poll), {id: "officer_assignment_form"}) do %>
|
|
||||||
<div class="row">
|
|
||||||
<div class="small-12 medium-6 column">
|
|
||||||
<label><%= t("officing.final_recounts.new.booth") %></label>
|
|
||||||
<%= select_tag :officer_assignment_id,
|
|
||||||
booths_for_officer_select_options(@officer_assignments),
|
|
||||||
{ prompt: t("officing.final_recounts.new.select_booth"),
|
|
||||||
label: false } %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="small-12 medium-6 column">
|
|
||||||
<label><%= t("officing.final_recounts.new.date") %></label>
|
|
||||||
<%= select_tag :date,
|
|
||||||
poll_dates_select_options(@poll),
|
|
||||||
{ prompt: t("officing.final_recounts.new.select_date"),
|
|
||||||
label: false } %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="small-12 medium-6 large-4 column">
|
|
||||||
<label><%= t("officing.final_recounts.new.count") %></label>
|
|
||||||
<%= text_field_tag :count, nil, placeholder: t("officing.final_recounts.new.count_placeholder") %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="small-12 medium-6 large-4 column">
|
|
||||||
<%= submit_tag t("officing.final_recounts.new.submit"), class: "button expanded" %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
|
||||||
<h2><%= @poll.name %></h2>
|
|
||||||
<div class="callout alert">
|
|
||||||
<%= t("officing.final_recounts.new.not_allowed") %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
|
|
||||||
<% if @final_recounts.any? %>
|
|
||||||
<hr>
|
|
||||||
<h3><%= t("officing.final_recounts.new.final_recount_list") %></h3>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<th><%= t("officing.final_recounts.new.date") %></th>
|
|
||||||
<th><%= t("officing.final_recounts.new.booth") %></th>
|
|
||||||
<th><%= t("officing.final_recounts.new.count") %></th>
|
|
||||||
<th><%= t("officing.final_recounts.new.system_count") %></th>
|
|
||||||
<th> </th>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<% @final_recounts.each do |final_recount| %>
|
|
||||||
<tr id="<%= dom_id(final_recount) %>">
|
|
||||||
<td>
|
|
||||||
<%= l(final_recount.date.to_date, format: :long) %>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<%= final_recount.booth_assignment.booth.name %>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<strong><%= final_recount.count %></strong>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<strong><%= system_recount_to_compare_with_final_recount final_recount %></strong>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<%= link_to t("officing.final_recounts.new.add_results"), new_officing_poll_result_path(@poll, oa: final_recount.officer_assignment.id, d: l(final_recount.date.to_date) )%>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<% end %>
|
|
||||||
@@ -420,7 +420,6 @@ Rails.application.routes.draw do
|
|||||||
resources :polls, only: [:index] do
|
resources :polls, only: [:index] do
|
||||||
get :final, on: :collection
|
get :final, on: :collection
|
||||||
|
|
||||||
resources :final_recounts, only: [:new, :create]
|
|
||||||
resources :results, only: [:new, :create, :index]
|
resources :results, only: [:new, :create, :index]
|
||||||
end
|
end
|
||||||
resource :residence, controller: "residence", only: [:new, :create]
|
resource :residence, controller: "residence", only: [:new, :create]
|
||||||
|
|||||||
@@ -1,149 +0,0 @@
|
|||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
feature 'Officing Final Recount' do
|
|
||||||
|
|
||||||
background do
|
|
||||||
@poll_officer = create(:poll_officer)
|
|
||||||
@officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
|
|
||||||
@poll = @officer_assignment.booth_assignment.poll
|
|
||||||
@poll.update(ends_at: 1.day.ago)
|
|
||||||
login_as(@poll_officer.user)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Only polls where user is officer for final recounts are accessible' do
|
|
||||||
regular_officer_assignment_1 = create(:poll_officer_assignment, officer: @poll_officer)
|
|
||||||
regular_officer_assignment_2 = create(:poll_officer_assignment, officer: @poll_officer)
|
|
||||||
|
|
||||||
not_allowed_poll_1 = create(:poll, :expired)
|
|
||||||
not_allowed_poll_2 = regular_officer_assignment_1.booth_assignment.poll
|
|
||||||
not_allowed_poll_2.update(ends_at: 1.day.ago)
|
|
||||||
not_allowed_poll_3 = regular_officer_assignment_2.booth_assignment.poll
|
|
||||||
|
|
||||||
visit root_path
|
|
||||||
click_link 'Polling officers'
|
|
||||||
|
|
||||||
expect(page).to have_content('Poll officing')
|
|
||||||
within('#side_menu') do
|
|
||||||
click_link 'Final recounts and results'
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to_not have_content(not_allowed_poll_1.name)
|
|
||||||
expect(page).to_not have_content(not_allowed_poll_2.name)
|
|
||||||
expect(page).to_not have_content(not_allowed_poll_3.name)
|
|
||||||
expect(page).to have_content(@poll.name)
|
|
||||||
|
|
||||||
visit new_officing_poll_final_recount_path(not_allowed_poll_1)
|
|
||||||
expect(page).to have_content('You are allowed to add final recounts for this poll')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Add final recount' do
|
|
||||||
visit officing_root_path
|
|
||||||
|
|
||||||
within('#side_menu') do
|
|
||||||
click_link 'Final recounts and results'
|
|
||||||
end
|
|
||||||
|
|
||||||
within("#poll_#{@poll.id}") do
|
|
||||||
expect(page).to have_content(@poll.name)
|
|
||||||
click_link 'Add final recount'
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to_not have_content('Your recounts')
|
|
||||||
|
|
||||||
booth_name = @officer_assignment.booth_assignment.booth.name
|
|
||||||
date = I18n.l(@poll.starts_at.to_date, format: :long)
|
|
||||||
select booth_name, from: 'officer_assignment_id'
|
|
||||||
select date, from: 'date'
|
|
||||||
fill_in :count, with: '33'
|
|
||||||
click_button 'Save'
|
|
||||||
|
|
||||||
expect(page).to have_content('Your final recounts')
|
|
||||||
|
|
||||||
within("#poll_final_recount_#{@officer_assignment.booth_assignment.final_recounts.first.id}") do
|
|
||||||
expect(page).to have_content(date)
|
|
||||||
expect(page).to have_content(booth_name)
|
|
||||||
expect(page).to have_content('33')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Edit final recount' do
|
|
||||||
final_recount = create(:poll_final_recount,
|
|
||||||
officer_assignment: @officer_assignment,
|
|
||||||
booth_assignment: @officer_assignment.booth_assignment,
|
|
||||||
date: @poll.starts_at,
|
|
||||||
count: 100)
|
|
||||||
|
|
||||||
booth_name = @officer_assignment.booth_assignment.booth.name
|
|
||||||
date = I18n.l(final_recount.date.to_date, format: :long)
|
|
||||||
|
|
||||||
visit new_officing_poll_final_recount_path(@poll)
|
|
||||||
|
|
||||||
expect(page).to have_content('Your final recounts')
|
|
||||||
|
|
||||||
within("#poll_final_recount_#{final_recount.id}") do
|
|
||||||
expect(page).to have_content(date)
|
|
||||||
expect(page).to have_content(booth_name)
|
|
||||||
expect(page).to have_content('100')
|
|
||||||
end
|
|
||||||
|
|
||||||
select booth_name, from: 'officer_assignment_id'
|
|
||||||
select date, from: 'date'
|
|
||||||
fill_in :count, with: '42'
|
|
||||||
click_button 'Save'
|
|
||||||
|
|
||||||
expect(page).to have_content "Data added"
|
|
||||||
|
|
||||||
within("#poll_final_recount_#{final_recount.id}") do
|
|
||||||
expect(page).to have_content(date)
|
|
||||||
expect(page).to have_content(booth_name)
|
|
||||||
expect(page).to have_content('42')
|
|
||||||
end
|
|
||||||
expect(page).to_not have_content('100')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Show final and system recounts to compare' do
|
|
||||||
final_officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
|
|
||||||
poll = final_officer_assignment.booth_assignment.poll
|
|
||||||
poll.update(ends_at: 1.day.ago)
|
|
||||||
final_recount = create(:poll_final_recount,
|
|
||||||
officer_assignment: final_officer_assignment,
|
|
||||||
booth_assignment: final_officer_assignment.booth_assignment,
|
|
||||||
date: 7.days.ago,
|
|
||||||
count: 100)
|
|
||||||
33.times do
|
|
||||||
create(:poll_voter, :valid_document,
|
|
||||||
poll: poll,
|
|
||||||
booth_assignment: final_officer_assignment.booth_assignment,
|
|
||||||
created_at: final_recount.date)
|
|
||||||
end
|
|
||||||
|
|
||||||
visit new_officing_poll_final_recount_path(poll)
|
|
||||||
within("#poll_final_recount_#{final_recount.id}") do
|
|
||||||
expect(page).to have_content(I18n.l(final_recount.date.to_date, format: :long))
|
|
||||||
expect(page).to have_content(final_officer_assignment.booth_assignment.booth.name)
|
|
||||||
expect(page).to have_content('100')
|
|
||||||
expect(page).to have_content('33')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show link to add results for same booth/date" do
|
|
||||||
final_officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
|
|
||||||
poll = final_officer_assignment.booth_assignment.poll
|
|
||||||
poll.update(ends_at: 1.day.ago)
|
|
||||||
final_recount = create(:poll_final_recount,
|
|
||||||
officer_assignment: final_officer_assignment,
|
|
||||||
booth_assignment: final_officer_assignment.booth_assignment,
|
|
||||||
date: 7.days.ago,
|
|
||||||
count: 100)
|
|
||||||
visit new_officing_poll_final_recount_path(poll)
|
|
||||||
within("#poll_final_recount_#{final_recount.id}") do
|
|
||||||
click_link "Add results"
|
|
||||||
end
|
|
||||||
|
|
||||||
expected_path = new_officing_poll_result_path(poll, oa: final_recount.officer_assignment.id, d: I18n.l(final_recount.date.to_date))
|
|
||||||
expect(page).to have_current_path(expected_path)
|
|
||||||
expect(page).to have_select('officer_assignment_id', selected: final_recount.booth_assignment.booth.name)
|
|
||||||
expect(page).to have_select('date', selected: I18n.l(final_recount.date.to_date, format: :long))
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user