Skip to content

Commit

Permalink
Include multiple choice questions in the polls exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Senen committed Aug 3, 2023
1 parent 359a381 commit 7371384
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/models/custom/poll/question/answer/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def csv_values(voter)
def value_of(answer)
if answer.question.single_choice?
answer.question_answer&.title
elsif answer.question.multiple_choice?
answer.question_answers.order(given_order: :asc).map(&:title).join(";")
else
answer.open_answer
end
Expand Down
12 changes: 9 additions & 3 deletions spec/system/custom/admin/poll/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@
question_3 = create(:poll_question, :yes_no, poll: poll, title: "Do you have environmental concerns?")
create(:poll_answer, question: question_3, question_answer: question_3.question_answers.first, author: user_1)
create(:poll_answer, question: question_3, question_answer: nil, author: user_2)
question_4 = create(:poll_question, :multiple_choice, poll: poll, title: "Choose many")
option_a = create(:poll_question_answer, question: question_4, title: "Option A")
option_b = create(:poll_question_answer, question: question_4, title: "Option B")
option_c = create(:poll_question_answer, question: question_4, title: "Option C")
create(:poll_answer, question: question_4, question_answers: [option_a, option_c], author: user_1)
create(:poll_answer, question: question_4, question_answers: [option_b], author: user_2)
create(:poll_voter, user: user_1, poll: poll)
create(:poll_voter, user: user_2, poll: poll)

Expand All @@ -185,9 +191,9 @@
header = page.response_headers["Content-Disposition"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="questions_to_citizens_questions_answers.csv"$/)
csv_contents = "What is your favourite color?,Do you agree?,Do you have environmental concerns?\n"\
"Red,Yes,Yes\n"\
"Blue,No,\n"\
csv_contents = "What is your favourite color?,Do you agree?,Do you have environmental concerns?,Choose many\n"\
"Red,Yes,Yes,Option A;Option C\n"\
"Blue,No,,Option B\n"\

expect(page.body).to eq(csv_contents)
end
Expand Down

0 comments on commit 7371384

Please sign in to comment.