Merge pull request #3617 from consul/fix_poll_results_exception

Avoid error for polls results
This commit is contained in:
Javier Martín
2019-11-01 12:05:40 +01:00
committed by GitHub
2 changed files with 10 additions and 1 deletions

View File

@@ -67,7 +67,7 @@ class Poll::Question < ApplicationRecord
end
def most_voted_answer_id
question_answers.max_by(&:total_votes).id
question_answers.max_by(&:total_votes)&.id
end
def possible_answers

View File

@@ -52,4 +52,13 @@ describe "Poll Results" do
expect(find("#answer_#{answer5.id}_result")).to have_content("1 (33.33%)")
end
end
scenario "Results for polls with questions but without answers" do
poll = create(:poll, :expired, results_enabled: true)
question = create(:poll_question, poll: poll)
visit results_poll_path(poll)
expect(page).to have_content question.title
end
end