diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 20899c081..3e95997df 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -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 diff --git a/spec/features/polls/results_spec.rb b/spec/features/polls/results_spec.rb index 7db289ae6..f0b4d19d4 100644 --- a/spec/features/polls/results_spec.rb +++ b/spec/features/polls/results_spec.rb @@ -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