AyuntamientoMadrid/participacion

View on GitHub
app/components/polls/questions/options_component.html.erb

Summary

Maintainability
Test Coverage
<div class="poll-question-options">
  <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
    <% question_options.each do |question_option| %>
      <% if already_answered?(question_option) %>
        <%= button_to question_option.title,
                      question_answer_path(question, user_answer(question_option)),
                      method: :delete,
                      remote: true,
                      title: t("poll_questions.show.voted", answer: question_option.title),
                      class: "button answered",
                      "aria-pressed": true %>
      <% else %>
        <%= button_to question_option.title,
                      question_answers_path(question, option_id: question_option.id),
                      remote: true,
                      title: t("poll_questions.show.vote_answer", answer: question_option.title),
                      class: "button secondary hollow",
                      "aria-pressed": false,
                      disabled: disable_option?(question_option) %>
      <% end %>
    <% end %>
  <% elsif !user_signed_in? %>
    <% question_options.each do |question_option| %>
      <%= link_to question_option.title, new_user_session_path, class: "button secondary hollow" %>
    <% end %>
  <% elsif !current_user.level_two_or_three_verified? %>
    <% question_options.each do |question_option| %>
      <%= link_to question_option.title, verification_path, class: "button secondary hollow" %>
    <% end %>
  <% else %>
    <% question_options.each do |question_option| %>
      <span class="button secondary hollow disabled"><%= question_option.title %></span>
    <% end %>
  <% end %>
</div>