Improve officing result specs

This commit is contained in:
Bertocq
2017-10-23 22:37:14 +02:00
committed by Javi Martín
parent dbe404d9ad
commit ba9346162c

View File

@@ -1,27 +1,27 @@
require "rails_helper"
feature "Officing Results", :with_frozen_time do
let(:poll) { create(:poll, ends_at: 1.day.ago) }
let(:booth) { create(:poll_booth) }
let(:poll_officer) { create(:poll_officer) }
background do
@poll_officer = create(:poll_officer)
@officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
create(:poll_shift, officer: @poll_officer, booth: @officer_assignment.booth, date: Date.current)
@poll = @officer_assignment.booth_assignment.poll
@poll.update(ends_at: 1.day.ago)
@question_1 = create(:poll_question, poll: @poll)
create(:poll_booth_assignment, poll: poll, booth: booth)
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current)
@question_1 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Yes", question: @question_1, given_order: 1)
create(:poll_question_answer, title: "No", question: @question_1, given_order: 2)
@question_2 = create(:poll_question, poll: @poll)
@question_2 = create(:poll_question, poll: poll)
create(:poll_question_answer, title: "Today", question: @question_2, given_order: 1)
create(:poll_question_answer, title: "Tomorrow", question: @question_2, given_order: 2)
login_as(@poll_officer.user)
set_officing_booth(@officer_assignment.booth)
login_as(poll_officer.user)
set_officing_booth(booth)
end
scenario "Only polls where user is officer for results 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)
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
@@ -40,7 +40,7 @@ feature "Officing Results", :with_frozen_time do
expect(page).not_to have_content(not_allowed_poll_1.name)
expect(page).not_to have_content(not_allowed_poll_2.name)
expect(page).not_to have_content(not_allowed_poll_3.name)
expect(page).to have_content(@poll.name)
expect(page).to have_content(poll.name)
visit new_officing_poll_result_path(not_allowed_poll_1)
expect(page).to have_content("You are not allowed to add results for this poll")
@@ -53,15 +53,14 @@ feature "Officing Results", :with_frozen_time do
click_link "Total recounts and results"
end
within("#poll_#{@poll.id}") do
expect(page).to have_content(@poll.name)
within("#poll_#{poll.id}") do
expect(page).to have_content(poll.name)
click_link "Add results"
end
expect(page).not_to have_content("Your results")
booth_name = @officer_assignment.booth_assignment.booth.name
select booth_name, from: "officer_assignment_id"
select booth.name, from: "officer_assignment_id"
fill_in "questions[#{@question_1.id}][0]", with: "100"
fill_in "questions[#{@question_1.id}][1]", with: "200"
@@ -77,27 +76,27 @@ feature "Officing Results", :with_frozen_time do
expect(page).to have_content("Your results")
within("#results_#{@officer_assignment.booth_assignment_id}_#{Date.current.strftime("%Y%m%d")}") do
within("#results_#{poll_officer.officer_assignments.first.booth_assignment_id}_#{Date.current.strftime("%Y%m%d")}") do
expect(page).to have_content(I18n.l(Date.current, format: :long))
expect(page).to have_content(booth_name)
expect(page).to have_content(booth.name)
end
end
scenario "Edit result" do
partial_result = create(:poll_partial_result,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
officer_assignment: poll_officer.officer_assignments.first,
booth_assignment: poll_officer.officer_assignments.first.booth_assignment,
date: Date.current,
question: @question_1,
answer: @question_1.question_answers.first.title,
author: @poll_officer.user,
author: poll_officer.user,
amount: 7777)
visit officing_poll_results_path(@poll, date: I18n.l(partial_result.date), booth_assignment_id: partial_result.booth_assignment_id)
visit officing_poll_results_path(poll, date: I18n.l(partial_result.date), booth_assignment_id: partial_result.booth_assignment_id)
within("#question_#{@question_1.id}_0_result") { expect(page).to have_content("7777") }
visit new_officing_poll_result_path(@poll)
visit new_officing_poll_result_path(poll)
booth_name = partial_result.booth_assignment.booth.name
select booth_name, from: "officer_assignment_id"
@@ -126,25 +125,25 @@ feature "Officing Results", :with_frozen_time do
scenario "Index lists all questions and answers" do
partial_result = create(:poll_partial_result,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.ends_at,
officer_assignment: poll_officer.officer_assignments.first,
booth_assignment: poll_officer.officer_assignments.first.booth_assignment,
date: poll.ends_at,
question: @question_1,
amount: 33)
poll_recount = create(:poll_recount,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.ends_at,
officer_assignment: poll_officer.officer_assignments.first,
booth_assignment: poll_officer.officer_assignments.first.booth_assignment,
date: poll.ends_at,
white_amount: 21,
null_amount: 44,
total_amount: 66)
visit officing_poll_results_path(@poll,
date: I18n.l(@poll.ends_at.to_date),
booth_assignment_id: @officer_assignment.booth_assignment_id)
visit officing_poll_results_path(poll,
date: I18n.l(poll.ends_at.to_date),
booth_assignment_id: poll_officer.officer_assignments.first.booth_assignment_id)
expect(page).to have_content(I18n.l(@poll.ends_at.to_date, format: :long))
expect(page).to have_content(@officer_assignment.booth_assignment.booth.name)
expect(page).to have_content(I18n.l(poll.ends_at.to_date, format: :long))
expect(page).to have_content(poll_officer.officer_assignments.first.booth_assignment.booth.name)
expect(page).to have_content(@question_1.title)
@question_1.question_answers.each_with_index do |answer, i|