Use checkboxes and radio buttons on poll forms
Our original interface to vote in a poll had a few issues: * Since there was no button to send the form, it wasn't clear that selecting an option would automatically store it in the database. * The interface was almost identical for single-choice questions and multiple-choice questions, which made it hard to know which type of question we were answering. * Adding other type of questions, like open answers, was hard since we would have to add a different submit button for each answer. So we're now using radio buttons for single-choice questions and checkboxes for multiple-choice questions, which are the native controls designed for these purposes, and a button to send the whole form. Since we don't have a database table for poll ballots like we have for budget ballots, we're adding a new `Poll::WebVote` model to manage poll ballots. We're using WebVote instead of Ballot or Vote because they could be mistaken with other vote classes. Note that browsers don't allow removing answers with radio buttons, so once somebody has voted in a single-choice question, they can't remove the vote unless they manually edit their HTML. This is the same behavior we had before commit7df0e9a96. As mentioned inc2010f975, we're now adding the `ChangeByZero` rubocop rule, since we've removed the test that used `and change`.
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Polls::AnswersController do
|
||||
describe "POST create" do
|
||||
it "doesn't create duplicate records on simultaneous requests", :race_condition do
|
||||
question = create(:poll_question_multiple, :abc)
|
||||
sign_in(create(:user, :level_two))
|
||||
|
||||
2.times.map do
|
||||
Thread.new do
|
||||
post :create, params: {
|
||||
question_id: question.id,
|
||||
option_id: question.question_options.find_by(title: "Answer A").id,
|
||||
format: :js
|
||||
}
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
end
|
||||
end.each(&:join)
|
||||
|
||||
expect(Poll::Answer.count).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,4 +8,25 @@ describe PollsController do
|
||||
expect { get :index }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST answer" do
|
||||
it "doesn't create duplicate records on simultaneous requests", :race_condition do
|
||||
question = create(:poll_question_multiple, :abc)
|
||||
sign_in(create(:user, :level_two))
|
||||
|
||||
2.times.map do
|
||||
Thread.new do
|
||||
post :answer, params: {
|
||||
id: question.poll.id,
|
||||
web_vote: {
|
||||
question.id.to_s => { option_id: question.question_options.find_by(title: "Answer A").id }
|
||||
}
|
||||
}
|
||||
rescue AbstractController::DoubleRenderError
|
||||
end
|
||||
end.each(&:join)
|
||||
|
||||
expect(Poll::Answer.count).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user