adds final recounting to poll officers' zone
This commit is contained in:
@@ -415,6 +415,10 @@ FactoryGirl.define do
|
||||
association :officer, factory: :poll_officer
|
||||
association :booth_assignment, factory: :poll_booth_assignment
|
||||
date Time.current.to_date
|
||||
|
||||
trait :final do
|
||||
final true
|
||||
end
|
||||
end
|
||||
|
||||
factory :poll_recount, class: 'Poll::Recount' do
|
||||
@@ -424,6 +428,13 @@ FactoryGirl.define do
|
||||
date (1.month.ago.to_datetime..1.month.from_now.to_datetime).to_a.sample
|
||||
end
|
||||
|
||||
factory :poll_final_recount, class: 'Poll::FinalRecount' do
|
||||
association :officer_assignment, factory: [:poll_officer_assignment, :final]
|
||||
association :booth_assignment, factory: :poll_booth_assignment
|
||||
count (1..100).to_a.sample
|
||||
date (1.month.ago.to_datetime..1.month.from_now.to_datetime).to_a.sample
|
||||
end
|
||||
|
||||
factory :poll_voter, class: 'Poll::Voter' do
|
||||
poll
|
||||
association :user, :level_two
|
||||
|
||||
@@ -30,7 +30,7 @@ feature 'Admin officer assignments in poll' do
|
||||
expect(page).to have_content booth_assignment.poll.name
|
||||
|
||||
within('#officer_assignment_form') do
|
||||
select I18n.l(booth_assignment.poll.ends_at.to_date), from: 'date'
|
||||
select I18n.l(booth_assignment.poll.ends_at.to_date, format: :long), from: 'date'
|
||||
select "#{booth_assignment.booth.name} (#{booth_assignment.booth.location})", from: 'booth_id'
|
||||
click_button 'Add shift'
|
||||
end
|
||||
|
||||
100
spec/features/officing/final_recount_spec.rb
Normal file
100
spec/features/officing/final_recount_spec.rb
Normal file
@@ -0,0 +1,100 @@
|
||||
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'
|
||||
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'
|
||||
end
|
||||
|
||||
click_link @poll.name
|
||||
|
||||
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 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
|
||||
end
|
||||
40
spec/models/poll/final_recount_spec.rb
Normal file
40
spec/models/poll/final_recount_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe :final_recount do
|
||||
|
||||
it "should update count_log if count changes" do
|
||||
final_recount = create(:poll_final_recount, count: 33)
|
||||
|
||||
expect(final_recount.count_log).to eq("")
|
||||
|
||||
final_recount.count = 33
|
||||
final_recount.save
|
||||
final_recount.count = 32
|
||||
final_recount.save
|
||||
final_recount.count = 34
|
||||
final_recount.save
|
||||
|
||||
expect(final_recount.count_log).to eq(":33:32")
|
||||
end
|
||||
|
||||
it "should update officer_assignment_id_log if count changes" do
|
||||
final_recount = create(:poll_final_recount, count: 33)
|
||||
|
||||
expect(final_recount.count_log).to eq("")
|
||||
|
||||
final_recount.count = 33
|
||||
final_recount.officer_assignment_id = 1
|
||||
final_recount.save
|
||||
|
||||
final_recount.count = 32
|
||||
final_recount.officer_assignment_id = 2
|
||||
final_recount.save
|
||||
|
||||
final_recount.count = 34
|
||||
final_recount.officer_assignment_id = 3
|
||||
final_recount.save
|
||||
|
||||
expect(final_recount.officer_assignment_id_log).to eq(":1:2")
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user