FIX: Poll: ensure it is not possible to vote with all abstentions in Ranked Choice (#29601)

Make sure Cast Vote button is disabled when all abstain and remove any historic data that fails new zero rank vote validation
This commit is contained in:
Robert
2024-11-26 12:16:22 +00:00
committed by GitHub
parent c7e471d35a
commit a535798659
7 changed files with 190 additions and 1 deletions

View File

@ -43,6 +43,36 @@ RSpec.describe DiscoursePoll::Poll do
end.to raise_error(DiscoursePoll::Error, I18n.t("poll.one_vote_per_user"))
end
it "should not allow a ranked vote with all abstentions" do
poll = post_with_ranked_choice_poll.polls.first
poll_options = poll.poll_options
expect do
DiscoursePoll::Poll.vote(
user,
post_with_ranked_choice_poll.id,
"poll",
{
"0": {
digest: poll_options.first.digest,
rank: "0",
},
"1": {
digest: poll_options.second.digest,
rank: "0",
},
"2": {
digest: poll_options.third.digest,
rank: "0",
},
},
)
end.to raise_error(
DiscoursePoll::Error,
I18n.t("poll.requires_that_at_least_one_option_is_ranked"),
)
end
it "should clean up bad votes for a regular poll" do
poll = post_with_regular_poll.polls.first