From 6c5b908ef5e19660882b1bca183de460e22b10e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 23 Jun 2025 13:16:09 +0200 Subject: [PATCH] Use a loop instead of with_collection to render questions This is what we usually do in components. --- app/components/polls/form_component.html.erb | 4 +++- app/components/polls/questions/question_component.rb | 2 +- spec/components/polls/questions/question_component_spec.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/components/polls/form_component.html.erb b/app/components/polls/form_component.html.erb index bd1704133..6516b9152 100644 --- a/app/components/polls/form_component.html.erb +++ b/app/components/polls/form_component.html.erb @@ -1 +1,3 @@ -<%= render Polls::Questions::QuestionComponent.with_collection(questions) %> +<% questions.each do |question| %> + <%= render Polls::Questions::QuestionComponent.new(question) %> +<% end %> diff --git a/app/components/polls/questions/question_component.rb b/app/components/polls/questions/question_component.rb index ba52796b5..627abc6e9 100644 --- a/app/components/polls/questions/question_component.rb +++ b/app/components/polls/questions/question_component.rb @@ -1,7 +1,7 @@ class Polls::Questions::QuestionComponent < ApplicationComponent attr_reader :question - def initialize(question:) + def initialize(question) @question = question end diff --git a/spec/components/polls/questions/question_component_spec.rb b/spec/components/polls/questions/question_component_spec.rb index 607906ad6..aba98dd94 100644 --- a/spec/components/polls/questions/question_component_spec.rb +++ b/spec/components/polls/questions/question_component_spec.rb @@ -7,7 +7,7 @@ describe Polls::Questions::QuestionComponent do 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) - render_inline Polls::Questions::QuestionComponent.new(question: question) + render_inline Polls::Questions::QuestionComponent.new(question) poll_question = page.find("#poll_question_#{question.id}") expect(poll_question).to have_content("Read more about")