Do not show answers without additional information
This commit is contained in:
committed by
Senén Rodero Rodríguez
parent
d70a0bf1d1
commit
4fba76f64f
@@ -1,5 +1,5 @@
|
||||
<h2><%= question.title %></h2>
|
||||
<% question.question_answers.each do |answer| %>
|
||||
<% question.answers_with_read_more.each do |answer| %>
|
||||
<div class="small-12 medium-6 column end answer <%= cycle("first", "") %>" id="answer_<%= answer.id %>">
|
||||
<h3><%= answer.title %></h3>
|
||||
|
||||
|
||||
@@ -6,4 +6,8 @@ class Polls::Questions::ReadMoreAnswerComponent < ApplicationComponent
|
||||
def initialize(question:)
|
||||
@question = question
|
||||
end
|
||||
|
||||
def render?
|
||||
question.answers_with_read_more?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,4 +74,12 @@ class Poll::Question < ApplicationRecord
|
||||
def possible_answers
|
||||
question_answers.joins(:translations).pluck("poll_question_answer_translations.title")
|
||||
end
|
||||
|
||||
def answers_with_read_more?
|
||||
answers_with_read_more.any?
|
||||
end
|
||||
|
||||
def answers_with_read_more
|
||||
question_answers.select(&:with_read_more?)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,4 +40,8 @@ class Poll::Question::Answer < ApplicationRecord
|
||||
def total_votes_percentage
|
||||
question.answers_total_votes.zero? ? 0 : (total_votes * 100.0) / question.answers_total_votes
|
||||
end
|
||||
|
||||
def with_read_more?
|
||||
description.present? || images.any? || documents.any? || videos.any?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,8 @@ describe Polls::Questions::ReadMoreAnswerComponent do
|
||||
let(:answer) { create(:poll_question_answer, question: question) }
|
||||
|
||||
it "renders question title" do
|
||||
create(:poll_question_answer, question: question, description: "Question answer description")
|
||||
|
||||
render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
|
||||
|
||||
expect(page).to have_content "Question title?"
|
||||
@@ -21,6 +23,14 @@ describe Polls::Questions::ReadMoreAnswerComponent do
|
||||
expect("Answer B").to appear_before("Answer A")
|
||||
end
|
||||
|
||||
it "does not render when answers does not have more information" do
|
||||
answer.update!(description: nil)
|
||||
|
||||
render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
|
||||
|
||||
expect(page).not_to be_rendered
|
||||
end
|
||||
|
||||
it "renders answers with videos" do
|
||||
create(:poll_answer_video, answer: answer, title: "Awesome video", url: "youtube.com/watch?v=123")
|
||||
|
||||
|
||||
@@ -34,4 +34,30 @@ describe Poll::Question::Answer do
|
||||
expect(Poll::Question::Answer.with_content).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "#with_read_more?" do
|
||||
it "returns false when the answer does not have description, images, videos nor documents" do
|
||||
poll_question_answer = build(:poll_question_answer, description: nil)
|
||||
|
||||
expect(poll_question_answer.with_read_more?).to be_falsy
|
||||
end
|
||||
|
||||
it "returns true when the answer has description, images, videos or documents" do
|
||||
poll_question_answer = build(:poll_question_answer, description: "Answer description")
|
||||
|
||||
expect(poll_question_answer.with_read_more?).to be_truthy
|
||||
|
||||
poll_question_answer = build(:poll_question_answer, :with_image)
|
||||
|
||||
expect(poll_question_answer.with_read_more?).to be_truthy
|
||||
|
||||
poll_question_answer = build(:poll_question_answer, :with_document)
|
||||
|
||||
expect(poll_question_answer.with_read_more?).to be_truthy
|
||||
|
||||
poll_question_answer = build(:poll_question_answer, :with_video)
|
||||
|
||||
expect(poll_question_answer.with_read_more?).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user