Use a loop instead of with_collection to render questions

This is what we usually do in components.
This commit is contained in:
Javi Martín
2025-06-23 13:16:09 +02:00
parent eccf906e45
commit 6c5b908ef5
3 changed files with 5 additions and 3 deletions

View File

@@ -1 +1,3 @@
<%= render Polls::Questions::QuestionComponent.with_collection(questions) %> <% questions.each do |question| %>
<%= render Polls::Questions::QuestionComponent.new(question) %>
<% end %>

View File

@@ -1,7 +1,7 @@
class Polls::Questions::QuestionComponent < ApplicationComponent class Polls::Questions::QuestionComponent < ApplicationComponent
attr_reader :question attr_reader :question
def initialize(question:) def initialize(question)
@question = question @question = question
end end

View File

@@ -7,7 +7,7 @@ describe Polls::Questions::QuestionComponent do
option_b = create(:poll_question_option, question: question, title: "Answer B") option_b = create(:poll_question_option, question: question, title: "Answer B")
allow_any_instance_of(Poll::Question::Option).to receive(:with_read_more?).and_return(true) allow_any_instance_of(Poll::Question::Option).to receive(:with_read_more?).and_return(true)
render_inline Polls::Questions::QuestionComponent.new(question: question) render_inline Polls::Questions::QuestionComponent.new(question)
poll_question = page.find("#poll_question_#{question.id}") poll_question = page.find("#poll_question_#{question.id}")
expect(poll_question).to have_content("Read more about") expect(poll_question).to have_content("Read more about")