Simplify creating officer assignments in specs
Note we usually cannot make it simple because officer assignments are usually assigned to both a poll and a booth, and on a certain date. However, in the few cases where the booth nor the date don't matter, we can make the code a bit easier to read.
This commit is contained in:
@@ -42,6 +42,14 @@ FactoryBot.define do
|
||||
trait :with_image do
|
||||
after(:create) { |poll| create(:image, imageable: poll) }
|
||||
end
|
||||
|
||||
transient { officers { [] } }
|
||||
|
||||
after(:create) do |poll, evaluator|
|
||||
evaluator.officers.each do |officer|
|
||||
create(:poll_officer_assignment, poll: poll, officer: officer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
factory :poll_question, class: "Poll::Question" do
|
||||
|
||||
@@ -115,6 +115,13 @@ FactoryBot.define do
|
||||
|
||||
transient do
|
||||
sequence(:name) { |n| "Officer #{n}" }
|
||||
polls { [] }
|
||||
end
|
||||
|
||||
after(:create) do |officer, evaluator|
|
||||
evaluator.polls.each do |poll|
|
||||
create(:poll_officer_assignment, poll: poll, officer: officer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -157,9 +157,7 @@ describe "Admin booths assignments" do
|
||||
booth = create(:poll_booth)
|
||||
officer_assignment = create(:poll_officer_assignment, poll: poll, booth: booth)
|
||||
officer = officer_assignment.officer
|
||||
|
||||
officer_assignment_2 = create(:poll_officer_assignment, poll: poll)
|
||||
officer_2 = officer_assignment_2.officer
|
||||
officer_2 = create(:poll_officer, polls: [poll])
|
||||
|
||||
visit admin_poll_path(poll)
|
||||
click_link "Booths (2)"
|
||||
|
||||
@@ -10,12 +10,9 @@ describe "Officer Assignments" do
|
||||
scenario "Index" do
|
||||
poll = create(:poll)
|
||||
|
||||
officer1 = create(:poll_officer, name: "Bubbles")
|
||||
officer2 = create(:poll_officer, name: "Blossom")
|
||||
officer3 = create(:poll_officer, name: "Buttercup")
|
||||
|
||||
officer_assignment = create(:poll_officer_assignment, poll: poll, officer: officer1)
|
||||
officer_assignment_2 = create(:poll_officer_assignment, poll: poll, officer: officer2)
|
||||
create(:poll_officer, name: "Bubbles", polls: [poll])
|
||||
create(:poll_officer, name: "Blossom", polls: [poll])
|
||||
create(:poll_officer, name: "Buttercup")
|
||||
|
||||
visit admin_poll_path(poll)
|
||||
|
||||
@@ -31,12 +28,9 @@ describe "Officer Assignments" do
|
||||
scenario "Search", :js do
|
||||
poll = create(:poll)
|
||||
|
||||
officer1 = create(:poll_officer, name: "John Snow")
|
||||
officer2 = create(:poll_officer, name: "John Silver")
|
||||
officer3 = create(:poll_officer, name: "John Edwards")
|
||||
|
||||
officer_assignment = create(:poll_officer_assignment, poll: poll, officer: officer1)
|
||||
officer_assignment_2 = create(:poll_officer_assignment, poll: poll, officer: officer2)
|
||||
create(:poll_officer, name: "John Snow", polls: [poll])
|
||||
create(:poll_officer, name: "John Silver", polls: [poll])
|
||||
create(:poll_officer, name: "John Edwards")
|
||||
|
||||
visit admin_poll_path(poll)
|
||||
|
||||
|
||||
@@ -19,13 +19,9 @@ describe "Officing Results", :with_frozen_time do
|
||||
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)
|
||||
|
||||
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
|
||||
not_allowed_poll_2 = create(:poll, officers: [poll_officer], ends_at: 1.day.ago)
|
||||
not_allowed_poll_3 = create(:poll, officers: [poll_officer])
|
||||
|
||||
visit root_path
|
||||
click_link "Polling officers"
|
||||
|
||||
@@ -65,13 +65,9 @@ describe Poll::Officer do
|
||||
it "returns polls ordered by end date (desc)" do
|
||||
officer = create(:poll_officer)
|
||||
|
||||
poll_1 = create(:poll, ends_at: 1.day.ago)
|
||||
poll_2 = create(:poll, ends_at: 10.days.from_now)
|
||||
poll_3 = create(:poll, ends_at: 10.days.ago)
|
||||
|
||||
[poll_1, poll_2, poll_3].each do |poll|
|
||||
create(:poll_officer_assignment, officer: officer, poll: poll)
|
||||
end
|
||||
poll_1 = create(:poll, ends_at: 1.day.ago, officers: [officer])
|
||||
poll_2 = create(:poll, ends_at: 10.days.from_now, officers: [officer])
|
||||
poll_3 = create(:poll, ends_at: 10.days.ago, officers: [officer])
|
||||
|
||||
assigned_polls = officer.voting_days_assigned_polls
|
||||
|
||||
|
||||
Reference in New Issue
Block a user