Merge pull request #2101 from consul/poll_results_and_stats_tests
Poll results and stats views
This commit is contained in:
@@ -3,8 +3,6 @@ class PollsController < ApplicationController
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
before_filter :set_poll, only: [:stats, :results]
|
||||
|
||||
has_filters %w{current expired incoming}
|
||||
has_orders %w{most_voted newest oldest}, only: :show
|
||||
|
||||
@@ -36,10 +34,4 @@ class PollsController < ApplicationController
|
||||
def results
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_poll
|
||||
@poll = Poll.find(params[:poll_id])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -7,8 +7,12 @@ module Abilities
|
||||
can [:read, :map, :summary, :share], Proposal
|
||||
can :read, Comment
|
||||
can :read, Poll
|
||||
cannot :results, Poll, results_enabled: false
|
||||
cannot :stats, Poll, stats_enabled: false
|
||||
can :results, Poll do |poll|
|
||||
poll.expired? && poll.results_enabled?
|
||||
end
|
||||
can :stats, Poll do |poll|
|
||||
poll.expired? && poll.stats_enabled?
|
||||
end
|
||||
can :read, Poll::Question
|
||||
can [:read, :welcome], Budget
|
||||
can :read, SpendingProposal
|
||||
|
||||
@@ -19,11 +19,27 @@
|
||||
<div class="dates"></div>
|
||||
<% if poll.questions.count == 1 %>
|
||||
<% poll.questions.each do |question| %>
|
||||
<h4><%= link_to question.title, poll %></h4>
|
||||
<h4>
|
||||
<% if poll.results_enabled? %>
|
||||
<%= link_to question.title, results_poll_path(poll) %>
|
||||
<% elsif poll.stats_enabled? %>
|
||||
<%= link_to question.title, stats_poll_path(poll) %>
|
||||
<% else %>
|
||||
<%= link_to question.title, poll %>
|
||||
<% end %>
|
||||
</h4>
|
||||
<%= poll_dates(poll) %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<h4><%= link_to poll.name, poll %></h4>
|
||||
<h4>
|
||||
<% if poll.results_enabled? %>
|
||||
<%= link_to poll.name, results_poll_path(poll) %>
|
||||
<% elsif poll.stats_enabled? %>
|
||||
<%= link_to poll.name, stats_poll_path(poll) %>
|
||||
<% else %>
|
||||
<%= link_to poll.name, poll %>
|
||||
<% end %>
|
||||
</h4>
|
||||
<%= poll_dates(poll) %>
|
||||
<ul class="margin-top">
|
||||
<% poll.questions.each do |question| %>
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
<% if current_user && current_user.administrator? ||
|
||||
<% if current_user && current_user.administrator? ||
|
||||
(@poll.expired? && (@poll.results_enabled? || @poll.stats_enabled?)) %>
|
||||
<div class="row margin-top">
|
||||
<div class="small-12 column">
|
||||
<ul class="menu simple clear">
|
||||
<% if current_user.administrator? || @poll.results_enabled? %>
|
||||
<% if current_user && current_user.administrator? || @poll.results_enabled? %>
|
||||
<% if controller_name == "polls" && action_name == "results" %>
|
||||
<li class="active">
|
||||
<h2><%= t("polls.show.results_menu") %></h2>
|
||||
</li>
|
||||
<% else %>
|
||||
<li><%= link_to t("polls.show.results_menu"), poll_results_path(@poll) %></li>
|
||||
<li><%= link_to t("polls.show.results_menu"), results_poll_path(@poll) %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if current_user.administrator? || @poll.stats_enabled? %>
|
||||
<% if current_user && current_user.administrator? || @poll.stats_enabled? %>
|
||||
<% if controller_name == "polls" && action_name == "stats" %>
|
||||
<li class="active">
|
||||
<h2><%= t("polls.show.stats_menu") %></h2>
|
||||
</li>
|
||||
<% else %>
|
||||
<li><%= link_to t("polls.show.stats_menu"), poll_stats_path(@poll) %></li>
|
||||
<li><%= link_to t("polls.show.stats_menu"), stats_poll_path(@poll) %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -113,8 +113,10 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
resources :polls, only: [:show, :index] do
|
||||
get :stats
|
||||
get :results
|
||||
member do
|
||||
get :stats
|
||||
get :results
|
||||
end
|
||||
resources :questions, controller: 'polls/questions', shallow: true do
|
||||
post :answer, on: :member
|
||||
end
|
||||
|
||||
@@ -546,6 +546,13 @@ poll = Poll.create(name: "Upcoming Poll",
|
||||
starts_at: 1.month.from_now,
|
||||
ends_at: 2.months.from_now)
|
||||
|
||||
puts " ✅"
|
||||
print "Recounting Poll"
|
||||
poll = Poll.create(name: "Recounting Poll",
|
||||
# slug: "recounting-poll",
|
||||
starts_at: 1.months.ago,
|
||||
ends_at: 5.days.ago)
|
||||
|
||||
puts " ✅"
|
||||
print "Expired Poll"
|
||||
poll = Poll.create(name: "Expired Poll",
|
||||
@@ -553,6 +560,15 @@ poll = Poll.create(name: "Expired Poll",
|
||||
starts_at: 2.months.ago,
|
||||
ends_at: 1.month.ago)
|
||||
|
||||
puts " ✅"
|
||||
print "Expired Poll with Stats & Results"
|
||||
poll = Poll.create(name: "Expired Poll with Stats & Results",
|
||||
# slug: "expired-poll-with-stats-and-results",
|
||||
starts_at: 2.months.ago,
|
||||
ends_at: 1.month.ago,
|
||||
results_enabled: true,
|
||||
stats_enabled: true)
|
||||
|
||||
puts " ✅"
|
||||
print "Creating Poll Questions"
|
||||
|
||||
|
||||
@@ -59,6 +59,22 @@ feature 'Polls' do
|
||||
expect(page).to have_link('Incoming')
|
||||
expect(page).to_not have_link('Expired')
|
||||
end
|
||||
|
||||
scenario "Poll title link to stats if enabled" do
|
||||
poll = create(:poll, name: "Poll with stats", stats_enabled: true)
|
||||
|
||||
visit polls_path
|
||||
|
||||
expect(page).to have_link("Poll with stats", href: stats_poll_path(poll))
|
||||
end
|
||||
|
||||
scenario "Poll title link to results if enabled" do
|
||||
poll = create(:poll, name: "Poll with results", stats_enabled: true, results_enabled: true)
|
||||
|
||||
visit polls_path
|
||||
|
||||
expect(page).to have_link("Poll with results", href: results_poll_path(poll))
|
||||
end
|
||||
end
|
||||
|
||||
context 'Show' do
|
||||
@@ -367,17 +383,74 @@ feature 'Polls' do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
context "Results and stats" do
|
||||
scenario "See polls statistics", :js do
|
||||
scenario "Show poll results and stats if enabled and poll expired" do
|
||||
poll = create(:poll, :expired, results_enabled: true, stats_enabled: true)
|
||||
user = create(:user)
|
||||
poll = create(:poll, summary: "Summary", description: "Description")
|
||||
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
click_link "Participation statistics"
|
||||
|
||||
expect(page).to have_content("Total participation")
|
||||
|
||||
expect(page).to have_content("Poll results")
|
||||
expect(page).to have_content("Participation statistics")
|
||||
|
||||
visit results_poll_path(poll)
|
||||
expect(page).to have_content("Questions")
|
||||
|
||||
visit stats_poll_path(poll)
|
||||
expect(page).to have_content("Participation data")
|
||||
end
|
||||
|
||||
scenario "Don't show poll results and stats if not enabled" do
|
||||
poll = create(:poll, :expired, results_enabled: false, stats_enabled: false)
|
||||
user = create(:user)
|
||||
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to_not have_content("Poll results")
|
||||
expect(page).to_not have_content("Participation statistics")
|
||||
|
||||
visit results_poll_path(poll)
|
||||
expect(page).to have_content("You do not have permission to carry out the action 'results' on poll.")
|
||||
|
||||
visit stats_poll_path(poll)
|
||||
expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.")
|
||||
end
|
||||
|
||||
scenario "Don't show poll results and stats if is not expired" do
|
||||
poll = create(:poll, :current, results_enabled: true, stats_enabled: true)
|
||||
user = create(:user)
|
||||
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to_not have_content("Poll results")
|
||||
expect(page).to_not have_content("Participation statistics")
|
||||
|
||||
visit results_poll_path(poll)
|
||||
expect(page).to have_content("You do not have permission to carry out the action 'results' on poll.")
|
||||
|
||||
visit stats_poll_path(poll)
|
||||
expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.")
|
||||
end
|
||||
|
||||
scenario "Show poll results and stats if user is administrator" do
|
||||
poll = create(:poll, :current, results_enabled: false, stats_enabled: false)
|
||||
user = create(:administrator).user
|
||||
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content("Poll results")
|
||||
expect(page).to have_content("Participation statistics")
|
||||
|
||||
visit results_poll_path(poll)
|
||||
expect(page).to have_content("Questions")
|
||||
|
||||
visit stats_poll_path(poll)
|
||||
expect(page).to have_content("Participation data")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ feature 'Poll Results' do
|
||||
user2 = create(:user, :level_two)
|
||||
user3 = create(:user, :level_two)
|
||||
|
||||
poll = create(:poll)
|
||||
poll = create(:poll, results_enabled: true)
|
||||
question1 = create(:poll_question, poll: poll)
|
||||
answer1 = create(:poll_question_answer, question: question1, title: 'Yes')
|
||||
answer2 = create(:poll_question_answer, question: question1, title: 'No')
|
||||
@@ -34,7 +34,9 @@ feature 'Poll Results' do
|
||||
expect(Poll::Voter.count).to eq(3)
|
||||
logout
|
||||
|
||||
visit poll_results_path(poll)
|
||||
poll.update(ends_at: 1.day.ago)
|
||||
|
||||
visit results_poll_path(poll)
|
||||
|
||||
expect(page).to have_content(question1.title)
|
||||
expect(page).to have_content(question2.title)
|
||||
|
||||
Reference in New Issue
Block a user