Prevent offline budget vote after voting online
This commit is contained in:
@@ -72,10 +72,15 @@ class Poll < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def votable_by?(user)
|
||||
return false if user_has_an_online_ballot(user)
|
||||
answerable_by?(user) &&
|
||||
not_voted_by?(user)
|
||||
end
|
||||
|
||||
def user_has_an_online_ballot(user)
|
||||
budget.present? && budget.ballots.find_by(user: user)&.lines.present?
|
||||
end
|
||||
|
||||
def self.not_voted_by(user)
|
||||
where("polls.id not in (?)", poll_ids_voted_by(user))
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@ feature "BudgetPolls", :with_frozen_time do
|
||||
let(:booth) { create(:poll_booth) }
|
||||
let(:officer) { create(:poll_officer) }
|
||||
let(:admin) { create(:administrator) }
|
||||
let!(:user) { create(:user, :in_census) }
|
||||
|
||||
background do
|
||||
create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection)
|
||||
@@ -18,8 +19,6 @@ feature "BudgetPolls", :with_frozen_time do
|
||||
|
||||
context "Offline" do
|
||||
scenario "A citizen can cast a paper vote", :js do
|
||||
user = create(:user, :in_census)
|
||||
|
||||
login_through_form_as_officer(officer.user)
|
||||
|
||||
visit new_officing_residence_path
|
||||
@@ -51,8 +50,6 @@ feature "BudgetPolls", :with_frozen_time do
|
||||
end
|
||||
|
||||
scenario "A citizen cannot vote offline again", :js do
|
||||
user = create(:user, :in_census)
|
||||
|
||||
login_through_form_as_officer(officer.user)
|
||||
|
||||
visit new_officing_residence_path
|
||||
@@ -71,8 +68,6 @@ feature "BudgetPolls", :with_frozen_time do
|
||||
end
|
||||
|
||||
scenario "A citizen cannot vote online after voting offline", :js do
|
||||
user = create(:user, :in_census)
|
||||
|
||||
login_through_form_as_officer(officer.user)
|
||||
|
||||
visit new_officing_residence_path
|
||||
@@ -97,16 +92,54 @@ feature "BudgetPolls", :with_frozen_time do
|
||||
end
|
||||
|
||||
context "Online" do
|
||||
scenario "A citizen can cast vote online" do
|
||||
# Login as User
|
||||
# Cast a vote for an investment
|
||||
scenario "A citizen can cast vote online", :js do
|
||||
login_as(user)
|
||||
visit budget_investment_path(budget, investment)
|
||||
|
||||
within("#budget_investment_#{investment.id}") do
|
||||
find(".add a").click
|
||||
expect(page).to have_content "Remove"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "A citizen cannot vote offline after voting online" do
|
||||
# create scenario for an user that voted online
|
||||
scenario "A citizen cannot vote online again", :js do
|
||||
login_as(user)
|
||||
visit budget_investment_path(budget, investment)
|
||||
|
||||
# Login as Poll Officer
|
||||
# Check the citizen cannot vote offline
|
||||
within("#budget_investment_#{investment.id}") do
|
||||
find(".add a").click
|
||||
expect(page).to have_content "Remove"
|
||||
end
|
||||
|
||||
visit budget_investment_path(budget, investment)
|
||||
find("div.ballot").hover
|
||||
|
||||
within("#budget_investment_#{investment.id}") do
|
||||
expect(page).to have_content "Remove vote"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "A citizen cannot vote offline after voting online", :js do
|
||||
login_as(user)
|
||||
visit budget_investment_path(budget, investment)
|
||||
|
||||
within("#budget_investment_#{investment.id}") do
|
||||
find(".add a").click
|
||||
expect(page).to have_content "Remove"
|
||||
end
|
||||
|
||||
logout
|
||||
login_through_form_as_officer(officer.user)
|
||||
|
||||
visit new_officing_residence_path
|
||||
officing_verify_residence
|
||||
|
||||
expect(page).to have_content poll.name
|
||||
|
||||
within("#poll_#{poll.id}") do
|
||||
expect(page).not_to have_button("Confirm vote")
|
||||
expect(page).to have_content("Has already participated in this poll")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user