Refactors polls_controller using answerable_by. Implements more specs
This commit is contained in:
@@ -9,7 +9,10 @@ class PollsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
@questions = @poll.questions.sort_for_list.for_render
|
||||
questions = @poll.questions.sort_for_list.for_render
|
||||
|
||||
@answerable_questions = questions.answerable_by(current_user)
|
||||
@non_answerable_questions = questions.where.not(id: @answerable_questions.pluck(:id))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<% if current_user.nil? %>
|
||||
<div class="small-12 column">
|
||||
<div class="callout primary">
|
||||
<%= t("polls.show.cant_answer_not_logged_in",
|
||||
signin: link_to(t("polls.show.signin"), new_user_session_path, class: "probe-message"),
|
||||
signup: link_to(t("polls.show.signup"), new_user_registration_path, class: "probe-message")).html_safe %>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif current_user.unverified? %>
|
||||
<div class="small-12 column">
|
||||
<div class="callout warning">
|
||||
<%= t('polls.show.cant_answer_verify_html',
|
||||
verify_link: link_to(t('polls.show.verify_link'), verification_path)) %>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif @poll.incoming? %>
|
||||
<div class="small-12 column">
|
||||
<div class="callout primary">
|
||||
<%= t('polls.show.cant_answer_incoming') %>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif @poll.expired? %>
|
||||
<div class="small-12 column">
|
||||
<div class="callout alert">
|
||||
<%= t('polls.show.cant_answer_expired') %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1,23 +1,53 @@
|
||||
<%= @poll.name %>
|
||||
|
||||
<%= render 'warnings' %>
|
||||
|
||||
<% @questions.each do |question| %>
|
||||
<div id="<%= dom_id(question) %>">
|
||||
<%= question.title %>
|
||||
|
||||
<%= question.valid_answers.each do |valid_answer| %>
|
||||
<% if can? :answer, @poll %>
|
||||
<%= link_to valid_answer %>
|
||||
<% else %>
|
||||
<span><%= valid_answer %></span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if false #wrong geozone %>
|
||||
<% unless can?(:answer, @poll) %>
|
||||
<div class="small-12 column">
|
||||
<% if current_user.nil? %>
|
||||
<div class="callout primary">
|
||||
<%= t("polls.show.cant_answer_not_logged_in",
|
||||
signin: link_to(t("polls.show.signin"), new_user_session_path, class: "probe-message"),
|
||||
signup: link_to(t("polls.show.signup"), new_user_registration_path, class: "probe-message")).html_safe %>
|
||||
</div>
|
||||
<% elsif current_user.unverified? %>
|
||||
<div class="callout warning">
|
||||
<%= t('polls.show.cant_answer_wrong_geozone') %>
|
||||
<%= t('polls.show.cant_answer_verify_html',
|
||||
verify_link: link_to(t('polls.show.verify_link'), verification_path)) %>
|
||||
</div>
|
||||
<% elsif @poll.incoming? %>
|
||||
<div class="callout primary">
|
||||
<%= t('polls.show.cant_answer_incoming') %>
|
||||
</div>
|
||||
<% elsif @poll.expired? %>
|
||||
<div class="callout alert">
|
||||
<%= t('polls.show.cant_answer_expired') %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% @answerable_questions.each do |question| %>
|
||||
<div id="<%= dom_id(question) %>">
|
||||
<%= question.title %>
|
||||
|
||||
<% question.valid_answers.each do |valid_answer| %>
|
||||
<%= link_to valid_answer %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if can?(:answer, @poll) &&
|
||||
@non_answerable_questions.present? %>
|
||||
<div class="callout warning">
|
||||
<%= t('polls.show.cant_answer_wrong_geozone') %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% @non_answerable_questions.each do |question| %>
|
||||
<div id="<%= dom_id(question) %>">
|
||||
<%= question.title %>
|
||||
|
||||
<% question.valid_answers.each do |valid_answer| %>
|
||||
<span><%= valid_answer %></span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -384,7 +384,7 @@ en:
|
||||
verify_link: "verify your account"
|
||||
cant_answer_incoming: "This poll has not yet started."
|
||||
cant_answer_expired: "This poll has finished."
|
||||
cant_answer_wrong_geozone: "This enquiry is not available on your geozone."
|
||||
cant_answer_wrong_geozone: "The following questions are not available in your geozone."
|
||||
proposal_ballots:
|
||||
title: "Votings"
|
||||
description_html: "The following citizen proposals that have reached the <strong>required supports</strong> and will be voted."
|
||||
|
||||
@@ -86,9 +86,10 @@ feature 'Polls' do
|
||||
login_as(create(:user, geozone: geozone))
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content('You must verify your account in order to answer')
|
||||
|
||||
expect(page).to have_content('Han Solo')
|
||||
expect(page).to have_content('Chewbacca')
|
||||
expect(page).to have_content('You must verify your account in order to answer')
|
||||
|
||||
expect(page).to_not have_link('Han Solo')
|
||||
expect(page).to_not have_link('Chewbacca')
|
||||
@@ -124,12 +125,14 @@ feature 'Polls' do
|
||||
expect(page).to have_content('This poll has finished')
|
||||
end
|
||||
|
||||
xscenario 'Level 2 users in an question for a geozone which is not theirs' do
|
||||
scenario 'Level 2 users in a poll with questions for a geozone which is not theirs' do
|
||||
create(:poll_question, poll: poll, geozone_ids: [], valid_answers: 'Vader, Palpatine')
|
||||
login_as(create(:user, :level_two))
|
||||
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content('The following questions are not available in your geozone')
|
||||
|
||||
expect(page).to have_content('Vader')
|
||||
expect(page).to have_content('Palpatine')
|
||||
expect(page).to_not have_link('Vader')
|
||||
|
||||
Reference in New Issue
Block a user