adds system recounting to admin booth_assignments

This commit is contained in:
Juanjo Bazán
2017-01-27 15:19:03 +01:00
parent 3d28b317e2
commit e634e80113
4 changed files with 86 additions and 9 deletions

View File

@@ -24,7 +24,8 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController
def show def show
@poll = ::Poll.find(params[:poll_id]) @poll = ::Poll.find(params[:poll_id])
@booth_assignment = @poll.booth_assignments.includes(:recounts, officer_assignments: [officer: [:user]]).find(params[:id]) @booth_assignment = @poll.booth_assignments.includes(:recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id])
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
end end
private private

View File

@@ -0,0 +1,7 @@
module PollRecountsHelper
def recount_for_date(recounts, date)
recounts.select {|r| r.date.to_date == date}.first
end
end

View File

@@ -59,12 +59,22 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @booth_assignment.recounts.sort_by{|r| r.date}.each do |recount| %> <% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %>
<tr id="recount_<%= recount.id %>" class="<%= 'count-error' if recount.count != 0 %>"> <% recount = recount_for_date(@booth_assignment.recounts, voting_date) %>
<td><%= l recount.date.to_date %></td> <% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %>
<% if recount.present? %>
<tr id="recount_<%= recount.id %>" class="<%= 'count-error' if recount.count != system_count %>">
<td><%= l voting_date %></td>
<td class="text-center" title="<%= recount.officer_assignment.officer.name %>"><%= recount.count %></td> <td class="text-center" title="<%= recount.officer_assignment.officer.name %>"><%= recount.count %></td>
<td class="text-center">0</td> <td class="text-center"><%= system_count %></td>
</tr> </tr>
<% else %>
<tr id="recount_<%= voting_date.strftime('%Y%m%d') %>">
<td><%= l voting_date %></td>
<td class="text-center" title=""> - </td>
<td class="text-center"><%= system_count %></td>
</tr>
<% end %>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>

View File

@@ -92,10 +92,22 @@ feature 'Admin booths assignments' do
poll = create(:poll) poll = create(:poll)
booth = create(:poll_booth) booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
recount = create(:poll_recount, booth_assignment: booth_assignment, count: 33) officer_assignment_1 = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.starts_at)
officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.ends_at)
recount_1 = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment_1,
date: officer_assignment_1.date,
count: 33)
recount_2 = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment_2,
date: officer_assignment_2.date,
count: 1)
booth_assignment_2 = create(:poll_booth_assignment, poll: poll) booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
recount_2 = create(:poll_recount, booth_assignment: booth_assignment_2, count: 100) other_recount = create(:poll_recount, booth_assignment: booth_assignment_2, count: 100)
visit admin_poll_path(poll) visit admin_poll_path(poll)
click_link 'Booths (2)' click_link 'Booths (2)'
@@ -104,9 +116,56 @@ feature 'Admin booths assignments' do
click_link 'Recounts' click_link 'Recounts'
within('#recounts_list') do within('#recounts_list') do
expect(page).to_not have_content other_recount.count
within("#recount_#{recount_1.id}") do
expect(page).to have_content recount_1.count
end
within("#recount_#{recount_2.id}") do
expect(page).to have_content recount_2.count
end
end
end
scenario 'Marks recount values with count-errors' do
poll = create(:poll)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
today = Time.current.to_date
officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: today)
recount = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment,
date: officer_assignment.date,
count: 1)
visit admin_poll_booth_assignment_path(poll, booth_assignment)
click_link 'Recounts'
within('#recounts_list') do
expect(page).to have_css("#recount_#{recount.id}.count-error")
within("#recount_#{recount.id}") do
expect(page).to have_content recount.count expect(page).to have_content recount.count
expect(page).to_not have_content recount_2.count expect(page).to have_content 0
end
end
create(:poll_voter, :valid_document, poll: poll, booth_assignment: booth_assignment)
visit admin_poll_booth_assignment_path(poll, booth_assignment)
click_link 'Recounts'
within('#recounts_list') do
expect(page).to_not have_css('.count-error')
within("#recount_#{recount.id}") do
expect(page).to have_content(recount.count)
end end
end end
end end
end
end end