Simplify setting up poll geozones in test/dev data
This commit is contained in:
@@ -181,6 +181,11 @@ class Poll < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def geozone_restricted_to=(geozones)
|
||||||
|
self.geozone_restricted = true
|
||||||
|
self.geozones = geozones
|
||||||
|
end
|
||||||
|
|
||||||
def generate_slug?
|
def generate_slug?
|
||||||
slug.nil?
|
slug.nil?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ section "Creating polls" do
|
|||||||
slug: I18n.t("seeds.polls.current_poll_geozone_restricted").parameterize,
|
slug: I18n.t("seeds.polls.current_poll_geozone_restricted").parameterize,
|
||||||
starts_at: 5.days.ago,
|
starts_at: 5.days.ago,
|
||||||
ends_at: 5.days.from_now,
|
ends_at: 5.days.from_now,
|
||||||
geozone_restricted: true,
|
geozone_restricted_to: Geozone.sample(3))
|
||||||
geozones: Geozone.sample(3))
|
|
||||||
|
|
||||||
create_poll!(name: I18n.t("seeds.polls.recounting_poll"),
|
create_poll!(name: I18n.t("seeds.polls.recounting_poll"),
|
||||||
slug: I18n.t("seeds.polls.recounting_poll").parameterize,
|
slug: I18n.t("seeds.polls.recounting_poll").parameterize,
|
||||||
|
|||||||
@@ -35,11 +35,11 @@ describe Abilities::Common do
|
|||||||
|
|
||||||
let(:current_poll) { create(:poll) }
|
let(:current_poll) { create(:poll) }
|
||||||
let(:expired_poll) { create(:poll, :expired) }
|
let(:expired_poll) { create(:poll, :expired) }
|
||||||
let(:expired_poll_from_own_geozone) { create(:poll, :expired, geozone_restricted: true, geozones: [geozone]) }
|
let(:expired_poll_from_own_geozone) { create(:poll, :expired, geozone_restricted_to: [geozone]) }
|
||||||
let(:expired_poll_from_other_geozone) { create(:poll, :expired, geozone_restricted: true, geozones: [create(:geozone)]) }
|
let(:expired_poll_from_other_geozone) { create(:poll, :expired, geozone_restricted_to: [create(:geozone)]) }
|
||||||
let(:poll) { create(:poll, geozone_restricted: false) }
|
let(:poll) { create(:poll, geozone_restricted: false) }
|
||||||
let(:poll_from_own_geozone) { create(:poll, geozone_restricted: true, geozones: [geozone]) }
|
let(:poll_from_own_geozone) { create(:poll, geozone_restricted_to: [geozone]) }
|
||||||
let(:poll_from_other_geozone) { create(:poll, geozone_restricted: true, geozones: [create(:geozone)]) }
|
let(:poll_from_other_geozone) { create(:poll, geozone_restricted_to: [create(:geozone)]) }
|
||||||
|
|
||||||
let(:poll_question_from_own_geozone) { create(:poll_question, poll: poll_from_own_geozone) }
|
let(:poll_question_from_own_geozone) { create(:poll_question, poll: poll_from_own_geozone) }
|
||||||
let(:poll_question_from_other_geozone) { create(:poll_question, poll: poll_from_other_geozone) }
|
let(:poll_question_from_other_geozone) { create(:poll_question, poll: poll_from_other_geozone) }
|
||||||
|
|||||||
@@ -195,10 +195,8 @@ describe Poll do
|
|||||||
let!(:current_poll) { create(:poll) }
|
let!(:current_poll) { create(:poll) }
|
||||||
let!(:expired_poll) { create(:poll, :expired) }
|
let!(:expired_poll) { create(:poll, :expired) }
|
||||||
|
|
||||||
let!(:current_restricted_poll) { create(:poll, geozone_restricted: true, geozones: [geozone]) }
|
let!(:current_restricted_poll) { create(:poll, geozone_restricted_to: [geozone]) }
|
||||||
let!(:expired_restricted_poll) do
|
let!(:expired_restricted_poll) { create(:poll, :expired, geozone_restricted_to: [geozone]) }
|
||||||
create(:poll, :expired, geozone_restricted: true, geozones: [geozone])
|
|
||||||
end
|
|
||||||
|
|
||||||
let!(:all_polls) { [current_poll, expired_poll, current_poll, expired_restricted_poll] }
|
let!(:all_polls) { [current_poll, expired_poll, current_poll, expired_restricted_poll] }
|
||||||
let(:non_current_polls) { [expired_poll, expired_restricted_poll] }
|
let(:non_current_polls) { [expired_poll, expired_restricted_poll] }
|
||||||
@@ -490,8 +488,8 @@ describe Poll do
|
|||||||
poll1 = create(:poll, geozone_restricted: true)
|
poll1 = create(:poll, geozone_restricted: true)
|
||||||
poll2 = create(:poll, geozone_restricted: true)
|
poll2 = create(:poll, geozone_restricted: true)
|
||||||
poll3 = create(:poll)
|
poll3 = create(:poll)
|
||||||
poll_geozone_1 = create(:poll, geozone_restricted: true, geozones: [geozone])
|
poll_geozone_1 = create(:poll, geozone_restricted_to: [geozone])
|
||||||
poll_geozone_2 = create(:poll, geozone_restricted: true, geozones: [geozone])
|
poll_geozone_2 = create(:poll, geozone_restricted_to: [geozone])
|
||||||
geozone_user = create(:user, :level_two, geozone: geozone)
|
geozone_user = create(:user, :level_two, geozone: geozone)
|
||||||
|
|
||||||
expect(Poll.sort_for_list).to eq [poll3, poll1, poll2, poll_geozone_1, poll_geozone_2]
|
expect(Poll.sort_for_list).to eq [poll3, poll1, poll2, poll_geozone_1, poll_geozone_2]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ describe "Admin poll questions", :admin do
|
|||||||
|
|
||||||
scenario "Show" do
|
scenario "Show" do
|
||||||
geozone = create(:geozone)
|
geozone = create(:geozone)
|
||||||
poll = create(:poll, geozone_restricted: true, geozone_ids: [geozone.id])
|
poll = create(:poll, geozone_restricted_to: [geozone])
|
||||||
question = create(:poll_question, poll: poll)
|
question = create(:poll_question, poll: poll)
|
||||||
|
|
||||||
visit admin_poll_path(poll)
|
visit admin_poll_path(poll)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ describe "Voters" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Cannot vote" do
|
scenario "Cannot vote" do
|
||||||
unvotable_poll = create(:poll, geozone_restricted: true, geozones: [create(:geozone, census_code: "02")])
|
unvotable_poll = create(:poll, geozone_restricted_to: [create(:geozone, census_code: "02")])
|
||||||
create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth)
|
create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth)
|
||||||
|
|
||||||
set_officing_booth(booth)
|
set_officing_booth(booth)
|
||||||
@@ -96,7 +96,7 @@ describe "Voters" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Display polls that the user can vote" do
|
scenario "Display polls that the user can vote" do
|
||||||
votable_poll = create(:poll, geozone_restricted: true, geozones: [Geozone.first])
|
votable_poll = create(:poll, geozone_restricted_to: [Geozone.first])
|
||||||
create(:poll_officer_assignment, officer: officer, poll: votable_poll, booth: booth)
|
create(:poll_officer_assignment, officer: officer, poll: votable_poll, booth: booth)
|
||||||
|
|
||||||
set_officing_booth(booth)
|
set_officing_booth(booth)
|
||||||
@@ -108,7 +108,7 @@ describe "Voters" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Display polls that the user cannot vote" do
|
scenario "Display polls that the user cannot vote" do
|
||||||
unvotable_poll = create(:poll, geozone_restricted: true, geozones: [create(:geozone, census_code: "02")])
|
unvotable_poll = create(:poll, geozone_restricted_to: [create(:geozone, census_code: "02")])
|
||||||
create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth)
|
create(:poll_officer_assignment, officer: officer, poll: unvotable_poll, booth: booth)
|
||||||
|
|
||||||
set_officing_booth(booth)
|
set_officing_booth(booth)
|
||||||
|
|||||||
@@ -215,8 +215,7 @@ describe "Polls" do
|
|||||||
visit polls_path
|
visit polls_path
|
||||||
expect(page).not_to have_selector(".already-answer")
|
expect(page).not_to have_selector(".already-answer")
|
||||||
|
|
||||||
poll.update!(geozone_restricted: true)
|
poll.update!(geozone_restricted_to: [geozone])
|
||||||
poll.geozones << geozone
|
|
||||||
|
|
||||||
create(:poll_question, :yes_no, poll: poll)
|
create(:poll_question, :yes_no, poll: poll)
|
||||||
|
|
||||||
@@ -238,8 +237,7 @@ describe "Polls" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Level 2 users answering" do
|
scenario "Level 2 users answering" do
|
||||||
poll.update!(geozone_restricted: true)
|
poll.update!(geozone_restricted_to: [geozone])
|
||||||
poll.geozones << geozone
|
|
||||||
|
|
||||||
question = create(:poll_question, :yes_no, poll: poll)
|
question = create(:poll_question, :yes_no, poll: poll)
|
||||||
user = create(:user, :level_two, geozone: geozone)
|
user = create(:user, :level_two, geozone: geozone)
|
||||||
@@ -256,8 +254,7 @@ describe "Polls" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Level 2 users changing answer" do
|
scenario "Level 2 users changing answer" do
|
||||||
poll.update!(geozone_restricted: true)
|
poll.update!(geozone_restricted_to: [geozone])
|
||||||
poll.geozones << geozone
|
|
||||||
|
|
||||||
question = create(:poll_question, :yes_no, poll: poll)
|
question = create(:poll_question, :yes_no, poll: poll)
|
||||||
user = create(:user, :level_two, geozone: geozone)
|
user = create(:user, :level_two, geozone: geozone)
|
||||||
@@ -293,7 +290,7 @@ describe "Polls" do
|
|||||||
scenario "Polls with users same-geozone listed first" do
|
scenario "Polls with users same-geozone listed first" do
|
||||||
create(:poll, geozone_restricted: true, name: "A Poll")
|
create(:poll, geozone_restricted: true, name: "A Poll")
|
||||||
create(:poll, name: "Not restricted")
|
create(:poll, name: "Not restricted")
|
||||||
create(:poll, geozone_restricted: true, geozones: [geozone], name: "Geozone Poll")
|
create(:poll, geozone_restricted_to: [geozone], name: "Geozone Poll")
|
||||||
|
|
||||||
login_as(create(:user, :level_two, geozone: geozone))
|
login_as(create(:user, :level_two, geozone: geozone))
|
||||||
visit polls_path(poll)
|
visit polls_path(poll)
|
||||||
|
|||||||
Reference in New Issue
Block a user