" id="answer_<%= answer.id %>">
+
<%= answer.title %>
- <% if answer.images.any? %>
- <%= render "polls/gallery", answer: answer %>
- <% end %>
+ <% if answer.images.any? %>
+ <%= render "polls/gallery", answer: answer %>
+ <% end %>
- <% if answer.description.present? %>
-
-
- <%= wysiwyg(answer.description) %>
+ <% if answer.description.present? %>
+
+
+ <%= wysiwyg(answer.description) %>
+
+
+
+
+
-
-
-
+ <% end %>
+
+ <% if answer.documents.present? %>
+
+
+
+ <%= t("polls.show.documents") %>
+
+
+ <% answer.documents.each do |document| %>
+ <%= link_to document.title,
+ document.attachment,
+ target: "_blank",
+ rel: "nofollow" %>
+ <% end %>
-
- <% end %>
+ <% end %>
- <% if answer.documents.present? %>
-
-
-
- <%= t("polls.show.documents") %>
-
+ <% if answer.videos.present? %>
+
+
+
+ <%= t("polls.show.videos") %>
+
- <% answer.documents.each do |document| %>
- <%= link_to document.title,
- document.attachment,
- target: "_blank",
- rel: "nofollow" %>
- <% end %>
-
- <% end %>
-
- <% if answer.videos.present? %>
-
-
-
- <%= t("polls.show.videos") %>
-
-
- <% answer.videos.each do |video| %>
- <%= link_to video.title,
- video.url,
- target: "_blank",
- rel: "nofollow" %>
- <% end %>
-
- <% end %>
-
+ <% answer.videos.each do |video| %>
+ <%= link_to video.title,
+ video.url,
+ target: "_blank",
+ rel: "nofollow" %>
+ <% end %>
+
+ <% end %>
+
+<% end %>
diff --git a/app/components/polls/questions/read_more_answer_component.rb b/app/components/polls/questions/read_more_answer_component.rb
index edb34180c..a88801581 100644
--- a/app/components/polls/questions/read_more_answer_component.rb
+++ b/app/components/polls/questions/read_more_answer_component.rb
@@ -1,9 +1,9 @@
class Polls::Questions::ReadMoreAnswerComponent < ApplicationComponent
- with_collection_parameter :answer
- attr_reader :answer
+ with_collection_parameter :question
+ attr_reader :question
delegate :wysiwyg, to: :helpers
- def initialize(answer:)
- @answer = answer
+ def initialize(question:)
+ @question = question
end
end
diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb
index af2dc563a..0828fc9fb 100644
--- a/app/controllers/polls_controller.rb
+++ b/app/controllers/polls_controller.rb
@@ -19,8 +19,6 @@ class PollsController < ApplicationController
def show
@questions = @poll.questions.for_render.sort_for_list
- @poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
- .with_content.order(:given_order)
@commentable = @poll
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
end
diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb
index 906595616..b911e3391 100644
--- a/app/views/polls/show.html.erb
+++ b/app/views/polls/show.html.erb
@@ -46,7 +46,7 @@
- <%= render Polls::Questions::ReadMoreAnswerComponent.with_collection(@poll_questions_answers) %>
+ <%= render Polls::Questions::ReadMoreAnswerComponent.with_collection(@questions) %>
diff --git a/spec/components/polls/questions/read_more_answer_component_spec.rb b/spec/components/polls/questions/read_more_answer_component_spec.rb
index 4e4902a81..6c441e878 100644
--- a/spec/components/polls/questions/read_more_answer_component_spec.rb
+++ b/spec/components/polls/questions/read_more_answer_component_spec.rb
@@ -3,13 +3,28 @@ require "rails_helper"
describe Polls::Questions::ReadMoreAnswerComponent do
include Rails.application.routes.url_helpers
let(:poll) { create(:poll) }
- let(:question) { create(:poll_question, poll: poll) }
+ let(:question) { create(:poll_question, poll: poll, title: "Question title?") }
let(:answer) { create(:poll_question_answer, question: question) }
+ it "renders question title" do
+ render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
+
+ expect(page).to have_content "Question title?"
+ end
+
+ it "renders answers in the given order" do
+ create(:poll_question_answer, title: "Answer A", question: question, given_order: 2)
+ create(:poll_question_answer, title: "Answer B", question: question, given_order: 1)
+
+ render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
+
+ expect("Answer B").to appear_before("Answer A")
+ end
+
it "renders answers with videos" do
create(:poll_answer_video, answer: answer, title: "Awesome video", url: "youtube.com/watch?v=123")
- render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer)
+ render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
expect(page).to have_link("Awesome video", href: "youtube.com/watch?v=123")
end
@@ -17,7 +32,7 @@ describe Polls::Questions::ReadMoreAnswerComponent do
it "renders answers with images" do
create(:image, imageable: answer, title: "The yes movement")
- render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer)
+ render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
expect(page).to have_css "img[alt='The yes movement']"
end
@@ -25,7 +40,7 @@ describe Polls::Questions::ReadMoreAnswerComponent do
it "renders answers with documents" do
create(:document, documentable: answer, title: "The yes movement")
- render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer)
+ render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
expect(page).to have_link("The yes movement")
end
diff --git a/spec/system/polls/polls_spec.rb b/spec/system/polls/polls_spec.rb
index 78cfae471..743b342b1 100644
--- a/spec/system/polls/polls_spec.rb
+++ b/spec/system/polls/polls_spec.rb
@@ -183,18 +183,6 @@ describe "Polls" do
expect("Second question").to appear_before("Third question")
end
- scenario "More info answers appear in the given order" do
- question = create(:poll_question, poll: poll)
- answer1 = create(:poll_question_answer, title: "First", question: question, given_order: 2)
- answer2 = create(:poll_question_answer, title: "Second", question: question, given_order: 1)
-
- visit poll_path(poll)
-
- within("div.poll-more-info-answers") do
- expect(answer2.title).to appear_before(answer1.title)
- end
- end
-
scenario "Buttons to slide through images work back and forth" do
question = create(:poll_question, :yes_no, poll: poll)
create(:image, imageable: question.question_answers.last, title: "The no movement")