Exclude open-ended questions from managing physical votes

Also make the :yes_no factory trait create a votation_type_unique
by default, since yes/no questions should always be unique.
This commit is contained in:
taitus
2025-08-22 14:26:25 +02:00
parent f3050a1aa5
commit b1cb6f8372
10 changed files with 55 additions and 5 deletions

View File

@@ -16,4 +16,13 @@ describe Officing::Results::FormComponent do
expect(page).to have_field "Invalid ballots", with: 0, type: :number
expect(page).to have_field "Valid ballots", with: 0, type: :number
end
it "does not render open-ended questions" do
create(:poll_question_open, poll: poll, title: "What do you want?")
render_inline Officing::Results::FormComponent.new(poll, Poll::OfficerAssignment.none)
expect(page).not_to have_content "What do you want?"
expect(page).to have_css "fieldset", text: "Agreed?"
end
end

View File

@@ -60,6 +60,7 @@ FactoryBot.define do
trait :yes_no do
after(:create) do |question|
create(:votation_type_unique, questionable: question)
create(:poll_question_option, question: question, title: "Yes")
create(:poll_question_option, question: question, title: "No")
end

View File

@@ -189,6 +189,21 @@ RSpec.describe Poll::Question do
end
end
describe "scopes" do
describe ".for_physical_votes" do
it "returns unique and multiple, but not open_ended" do
question_unique = create(:poll_question_unique)
question_multiple = create(:poll_question_multiple)
question_open_ended = create(:poll_question_open)
result = Poll::Question.for_physical_votes
expect(result).to match_array [question_unique, question_multiple]
expect(result).not_to include question_open_ended
end
end
end
context "open-ended results" do
let(:poll) { create(:poll) }
let!(:question_open) { create(:poll_question_open, poll: poll) }

View File

@@ -58,4 +58,20 @@ describe VotationType do
"because you've already defined possible valid answers for this question"
end
end
describe "scopes" do
describe ".accepts_options" do
it "includes unique and multiple, excludes open_ended" do
question_unique = create(:poll_question_unique)
question_multiple = create(:poll_question_multiple)
question_open_ended = create(:poll_question_open)
accepts_options = VotationType.accepts_options
expect(accepts_options).to match_array [question_unique.votation_type,
question_multiple.votation_type]
expect(accepts_options).not_to include question_open_ended.votation_type
end
end
end
end

View File

@@ -4,8 +4,8 @@ describe "Officing Results", :with_frozen_time do
let(:poll) { create(:poll, ends_at: 1.day.ago) }
let(:booth) { create(:poll_booth, polls: [poll]) }
let(:poll_officer) { create(:poll_officer) }
let(:question_1) { create(:poll_question, poll: poll) }
let(:question_2) { create(:poll_question, poll: poll) }
let(:question_1) { create(:poll_question_unique, poll: poll) }
let(:question_2) { create(:poll_question_unique, poll: poll) }
before do
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current)
@@ -15,6 +15,8 @@ describe "Officing Results", :with_frozen_time do
create(:poll_question_option, title: "Today", question: question_2, given_order: 1)
create(:poll_question_option, title: "Tomorrow", question: question_2, given_order: 2)
create(:poll_question_open, poll: poll, title: "What do you want?")
login_as(poll_officer.user)
set_officing_booth(booth)
end
@@ -69,6 +71,8 @@ describe "Officing Results", :with_frozen_time do
fill_in "Tomorrow", with: "444"
end
expect(page).not_to have_css "fieldset", text: "What do you want?"
fill_in "Totally blank ballots", with: "66"
fill_in "Invalid ballots", with: "77"
fill_in "Valid ballots", with: "88"
@@ -100,6 +104,7 @@ describe "Officing Results", :with_frozen_time do
booth_assignment_id: partial_result.booth_assignment_id)
within("#question_#{question_1.id}_0_result") { expect(page).to have_content("7777") }
expect(page).not_to have_content "What do you want?"
visit new_officing_poll_result_path(poll)
@@ -136,5 +141,6 @@ describe "Officing Results", :with_frozen_time do
within("#total_results") { expect(page).to have_content("8") }
within("#question_#{question_1.id}_0_result") { expect(page).to have_content("5555") }
within("#question_#{question_1.id}_1_result") { expect(page).to have_content("200") }
expect(page).not_to have_content "What do you want?"
end
end

View File

@@ -9,7 +9,7 @@ describe "Poll Votation Type" do
end
scenario "Unique, multiple and open answers" do
create(:poll_question_unique, :yes_no, poll: poll, title: "Is it that bad?")
create(:poll_question, :yes_no, poll: poll, title: "Is it that bad?")
create(:poll_question_multiple, :abcde, poll: poll, max_votes: 3, title: "Which ones do you prefer?")
create(:poll_question_open, poll: poll, title: "What do you think?")