Files
nairobi/app/components/polls/access_status_component.rb
Javi Martín 1b9d321c4e Extract methods in poll status component
This way we remove duplication in the HTML.

We're also adding a test checking what happens when users can vote in
order to test the `render?` method we've added.
2025-08-22 13:09:49 +02:00

37 lines
814 B
Ruby

class Polls::AccessStatusComponent < ApplicationComponent
attr_reader :poll
use_helpers :cannot?, :current_user
def initialize(poll)
@poll = poll
end
def render?
attributes.present?
end
private
def text
attributes[:text]
end
def html_class
attributes[:class]
end
def attributes
if current_user
if current_user.unverified?
{ text: t("polls.index.unverified"), class: "unverified" }
elsif cannot?(:answer, poll)
{ text: t("polls.index.cant_answer"), class: "cant-answer" }
elsif !poll.votable_by?(current_user)
{ text: t("polls.index.already_answer"), class: "already-answer" }
end
else
{ text: t("polls.index.not_logged_in"), class: "not-logged-in" }
end
end
end