From 78cc09cc5ab622353a84249b79e734f5b2be85b7 Mon Sep 17 00:00:00 2001 From: iagirre Date: Mon, 16 Oct 2017 17:25:04 +0200 Subject: [PATCH 1/6] Controllers and models to see the polls stats. Routes related also added. --- app/controllers/polls/stats_controller.rb | 20 +++++++++ app/models/abilities/everyone.rb | 1 + app/models/poll/stats.rb | 36 +++++++++++++++ app/views/polls/show.html.erb | 2 + app/views/polls/stats/show.html.erb | 53 +++++++++++++++++++++++ config/routes.rb | 2 + 6 files changed, 114 insertions(+) create mode 100644 app/controllers/polls/stats_controller.rb create mode 100644 app/models/poll/stats.rb create mode 100644 app/views/polls/stats/show.html.erb diff --git a/app/controllers/polls/stats_controller.rb b/app/controllers/polls/stats_controller.rb new file mode 100644 index 000000000..4d6a40ff3 --- /dev/null +++ b/app/controllers/polls/stats_controller.rb @@ -0,0 +1,20 @@ +class Polls::StatsController < ApplicationController + + before_action :load_poll + load_and_authorize_resource :poll + + def show + authorize! :read_stats, @poll + @stats = load_stats + end + + private + + def load_stats + Poll::Stats.new(@poll).generate + end + + def load_poll + @poll = Poll.find_by(id: params[:id]) + end +end \ No newline at end of file diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 3004ca8ad..73f3220ab 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -23,6 +23,7 @@ module Abilities can [:read], Legislation::Question can [:create], Legislation::Answer can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation + can :read_stats, Poll end end end diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb new file mode 100644 index 000000000..823724ade --- /dev/null +++ b/app/models/poll/stats.rb @@ -0,0 +1,36 @@ +class Poll + class Stats + + def initialize(poll) + @poll = poll + end + + def generate + stats = %w[total_participants total_participants_web total_participants_booth] + stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h + end + + private + + def total_participants + stats_cache('total_participants') { voters.uniq.count } + end + + def total_participants_web + stats_cache('total_participants_web') { voters.where(origin: 'web').count } + end + + def total_participants_booth + stats_cache('total_participants_booth') { voters.where(origin: 'booth').count } + end + + def voters + stats_cache('voters') { @poll.voters } + end + + def stats_cache(key, &block) + Rails.cache.fetch("polls_stats/#{@poll.id}/#{key}/v7", &block) + end + + end +end \ No newline at end of file diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 0a56ba237..2c541305d 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -28,6 +28,8 @@ + + <%= link_to "Estadísticas", custom_poll_stats_path(@poll.id) %>
diff --git a/app/views/polls/stats/show.html.erb b/app/views/polls/stats/show.html.erb new file mode 100644 index 000000000..6018708c9 --- /dev/null +++ b/app/views/polls/stats/show.html.erb @@ -0,0 +1,53 @@ +<% cache [@stats] do %> + <% provide :title do %> + <%= t("polls.stats.page_title", poll: @poll.name) %> + <% end %> + <% provide :social_media_meta_tags do %> + <%= render "shared/social_media_meta_tags", + social_url: poll_url(@poll), + social_title: @poll.name, + social_description: @poll.description %> + <% end %> + +
+
+
+
+ <%= back_link_to polls_path %> +

<%= t("polls.stats.title") %>
<%= @poll.name %>

+
+
+
+ + +
+
+
+ <%= t("polls.stats.total_participants") %> +

+ <%= @stats[:total_participants] %> +

+ + + + + + + + + + + + + +
WebBooth
<%= @stats[:total_participants_web] %><%= @stats[:total_participants_booth] %>
+ + <%= t("polls.stats.total_votes") %> +

+ <%= @stats[:total_votes] %> +

+
+
+
+
+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1fb74aa53..e9ae237f0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,6 +112,8 @@ Rails.application.routes.draw do get :search, on: :collection end + get "polls/:id/stats", to: "polls/stats#show", as: 'custom_poll_stats' + resources :polls, only: [:show, :index] do resources :questions, controller: 'polls/questions', shallow: true do post :answer, on: :member From 6a292daf42b6df47766eef75c6148e476afb4909 Mon Sep 17 00:00:00 2001 From: iagirre Date: Tue, 17 Oct 2017 15:04:29 +0200 Subject: [PATCH 2/6] Partial to render the polls stats and model methods to get the information from DB --- app/controllers/polls/stats_controller.rb | 20 --- app/controllers/polls_controller.rb | 2 + app/models/poll/stats.rb | 101 ++++++++++++++- .../polls/_results_subnavigation.html.erb | 20 +++ app/views/polls/_show.html.erb | 111 ++++++++++++++++ app/views/polls/show.html.erb | 118 ++---------------- app/views/polls/stats/_show.html.erb | 85 +++++++++++++ app/views/polls/stats/show.html.erb | 53 -------- config/locales/en/general.yml | 11 ++ config/locales/es/general.yml | 11 ++ 10 files changed, 343 insertions(+), 189 deletions(-) delete mode 100644 app/controllers/polls/stats_controller.rb create mode 100644 app/views/polls/_results_subnavigation.html.erb create mode 100644 app/views/polls/_show.html.erb create mode 100644 app/views/polls/stats/_show.html.erb delete mode 100644 app/views/polls/stats/show.html.erb diff --git a/app/controllers/polls/stats_controller.rb b/app/controllers/polls/stats_controller.rb deleted file mode 100644 index 4d6a40ff3..000000000 --- a/app/controllers/polls/stats_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -class Polls::StatsController < ApplicationController - - before_action :load_poll - load_and_authorize_resource :poll - - def show - authorize! :read_stats, @poll - @stats = load_stats - end - - private - - def load_stats - Poll::Stats.new(@poll).generate - end - - def load_poll - @poll = Poll.find_by(id: params[:id]) - end -end \ No newline at end of file diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 338f72cc4..a13bfd33d 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -25,6 +25,8 @@ class PollsController < ApplicationController @commentable = @poll @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) + + @stats = Poll::Stats.new(@poll).generate end end diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index 823724ade..1eef537a0 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -6,26 +6,115 @@ class Poll end def generate - stats = %w[total_participants total_participants_web total_participants_booth] + stats = %w[total_participants total_participants_web total_web_valid total_web_white total_web_null + total_participants_booth total_booth_valid total_booth_white total_booth_null + total_valid_votes total_white_votes total_null_votes valid_percentage_web valid_percentage_booth + total_valid_percentage white_percentage_web white_percentage_booth total_white_percentage + null_percentage_web null_percentage_booth total_null_percentage total_participants_web_percentage + total_participants_booth_percentage] stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h end private - + def total_participants - stats_cache('total_participants') { voters.uniq.count } + total_participants_web + total_participants_booth end def total_participants_web - stats_cache('total_participants_web') { voters.where(origin: 'web').count } + total_web_valid + total_web_white + total_web_null + end + + def total_participants_web_percentage + total_participants_web * 100 / total_participants end def total_participants_booth - stats_cache('total_participants_booth') { voters.where(origin: 'booth').count } + voters.where(origin: 'booth').count + end + + def total_participants_booth_percentage + (total_participants) == 0 ? 0 : total_participants_booth * 100 / total_participants.to_f + end + + def total_web_valid + voters.where(origin: 'web').count + end + + def valid_percentage_web + (total_valid_votes) == 0 ? 0 : total_web_valid * 100 / total_valid_votes.to_f + end + + def total_web_white + 0 + end + + def white_percentage_web + 0 + end + + def total_web_null + 0 + end + + def null_percentage_web + 0 + end + + def total_booth_valid + recounts.sum(:total_amount) + end + + def valid_percentage_booth + (total_valid_votes) == 0 ? 0 : total_booth_valid * 100 / total_valid_votes.to_f + end + + def total_booth_white + recounts.sum(:white_amount) + end + + def white_percentage_booth + (total_white_votes) == 0 ? 0 : total_booth_white * 100 / total_white_votes.to_f + end + + def total_booth_null + recounts.sum(:null_amount) + end + + def null_percentage_booth + (total_null_votes == 0) ? 0 : total_booth_null * 100 / total_null_votes.to_f + end + + def total_valid_votes + total_web_valid + total_booth_valid + end + + def total_valid_percentage + (total_participants) == 0 ? 0 : total_valid_votes * 100 / total_participants.to_f + end + + def total_white_votes + total_web_white + total_booth_white + end + + def total_white_percentage + (total_participants) == 0 ? 0 : total_white_votes * 100 / total_participants.to_f + end + + def total_null_votes + total_web_null + total_booth_null + end + + def total_null_percentage + (total_participants) == 0 ? 0 : total_null_votes * 100 / total_participants.to_f end def voters - stats_cache('voters') { @poll.voters } + @poll.voters + end + + def recounts + @poll.recounts end def stats_cache(key, &block) diff --git a/app/views/polls/_results_subnavigation.html.erb b/app/views/polls/_results_subnavigation.html.erb new file mode 100644 index 000000000..afff4de03 --- /dev/null +++ b/app/views/polls/_results_subnavigation.html.erb @@ -0,0 +1,20 @@ +
+
+
    +
  • + <%= link_to "#tab-stats" do %> +

    + <%= "Estadísticas" %> +

    + <% end %> +
  • +
  • + <%= link_to "#tab-information" do %> +

    + <%= "Información" %> +

    + <% end %> +
  • +
+
+
\ No newline at end of file diff --git a/app/views/polls/_show.html.erb b/app/views/polls/_show.html.erb new file mode 100644 index 000000000..6350048ef --- /dev/null +++ b/app/views/polls/_show.html.erb @@ -0,0 +1,111 @@ +
+
+ <%= render "callout" %> + + <% if @poll.voted_in_booth?(current_user) %> +
+ <%= t("polls.show.already_voted_in_booth") %> +
+ <% else %> + + <% if current_user && !@poll.votable_by?(current_user) %> +
+ <%= t("polls.show.already_voted_in_web") %> +
+ <% end %> + <% end %> + + <% @questions.each do |question| %> + <%= render 'polls/questions/question', question: question, token: @token %> + <% end %> + + <% if poll_voter_token(@poll, current_user).empty? %> + + <% end %> + + <%= link_to t("polls.show.participate_in_other_polls"), polls_path, class: "button hollow" %> +
+
+ +
+
+
+

<%= t("polls.show.more_info_title") %>

+ <%= safe_html_with_links simple_format(@poll.description) %> +
+ + <% if false %> + + <% end %> +
+
+ +
+
+ + <% @poll_questions_answers.each do |answer| %> +
+ + <% if answer.description.present? %> +

<%= answer.title %>

+ <% end %> + + <% if answer.images.any? %> + <%= render "gallery", answer: answer %> + <% end %> + + <% if answer.description.present? %> + + <% end %> + + <% if answer.documents.present? %> + + <% end %> +
+ <% end %> +
+ +
+ +
+ <%= render "filter_subnav" %> + +
+ <%= render "comments" %> +
+
\ No newline at end of file diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 2c541305d..e7e22124e 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -28,118 +28,16 @@
- - <%= link_to "Estadísticas", custom_poll_stats_path(@poll.id) %> + +
+ <%= render "results_subnavigation" %> -
-
- <%= render "callout" %> - - <% if @poll.voted_in_booth?(current_user) %> -
- <%= t("polls.show.already_voted_in_booth") %> -
- <% else %> - - <% if current_user && !@poll.votable_by?(current_user) %> -
- <%= t("polls.show.already_voted_in_web") %> -
- <% end %> - <% end %> - - <% @questions.each do |question| %> - <%= render 'polls/questions/question', question: question, token: @token %> - <% end %> - - <% if poll_voter_token(@poll, current_user).empty? %> - - <% end %> - - <%= link_to t("polls.show.participate_in_other_polls"), polls_path, class: "button hollow" %> +
+ <%= render "polls/stats/show" %>
-
- -
-
-
-

<%= t("polls.show.more_info_title") %>

- <%= safe_html_with_links simple_format(@poll.description) %> -
- - <% if false %> - - <% end %> -
-
- -
-
- - <% @poll_questions_answers.each do |answer| %> -
- - <% if answer.description.present? %> -

<%= answer.title %>

- <% end %> - - <% if answer.images.any? %> - <%= render "gallery", answer: answer %> - <% end %> - - <% if answer.description.present? %> - - <% end %> - - <% if answer.documents.present? %> - - <% end %> -
- <% end %> -
- +
+ <%= render "show" %> +
-
- <%= render "filter_subnav" %> - -
- <%= render "comments" %> -
-
diff --git a/app/views/polls/stats/_show.html.erb b/app/views/polls/stats/_show.html.erb new file mode 100644 index 000000000..1aeb7cf69 --- /dev/null +++ b/app/views/polls/stats/_show.html.erb @@ -0,0 +1,85 @@ +
+ +
+

<%= t("polls.show.stats.total_participation") %>

+ +

+ <%= t("polls.show.stats.total_votes") %>
+ <%= @stats[:total_participants] %> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<%= t("polls.show.stats.votes") %><%= t("polls.show.stats.web") %><%= t("polls.show.stats.booth") %><%= t("polls.show.stats.total") %>
<%= t("polls.show.stats.valid") %><%= @stats[:total_web_valid] %> + (<%= number_to_percentage(@stats[:valid_percentage_web], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_booth_valid] %> + (<%= number_to_percentage(@stats[:valid_percentage_booth], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_valid_votes] %> + (<%= number_to_percentage(@stats[:total_valid_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)
<%= t("polls.show.stats.white") %><%= @stats[:total_web_white] %> + (<%= number_to_percentage(@stats[:white_percentage_web], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_booth_white] %> + (<%= number_to_percentage(@stats[:white_percentage_booth], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_white_votes] %> + (<%= number_to_percentage(@stats[:total_white_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)
<%= t("polls.show.stats.null_votes") %><%= @stats[:total_web_null] %> + (<%= number_to_percentage(@stats[:null_percentage_web], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_booth_null] %> + (<%= number_to_percentage(@stats[:null_percentage_booth], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_null_votes] %> + (<%= number_to_percentage(@stats[:total_null_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)
<%= t("polls.show.stats.total") %><%= @stats[:total_participants_web] %> + (<%= number_to_percentage(@stats[:total_participants_web_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_participants_booth] %> + (<%= number_to_percentage(@stats[:total_participants_booth_percentage], + strip_insignificant_zeros: true, + precision: 2) %>)<%= @stats[:total_participants_web] + @stats[:total_participants_booth] %>
+
+
\ No newline at end of file diff --git a/app/views/polls/stats/show.html.erb b/app/views/polls/stats/show.html.erb deleted file mode 100644 index 6018708c9..000000000 --- a/app/views/polls/stats/show.html.erb +++ /dev/null @@ -1,53 +0,0 @@ -<% cache [@stats] do %> - <% provide :title do %> - <%= t("polls.stats.page_title", poll: @poll.name) %> - <% end %> - <% provide :social_media_meta_tags do %> - <%= render "shared/social_media_meta_tags", - social_url: poll_url(@poll), - social_title: @poll.name, - social_description: @poll.description %> - <% end %> - -
-
-
-
- <%= back_link_to polls_path %> -

<%= t("polls.stats.title") %>
<%= @poll.name %>

-
-
-
- - -
-
-
- <%= t("polls.stats.total_participants") %> -

- <%= @stats[:total_participants] %> -

- - - - - - - - - - - - - -
WebBooth
<%= @stats[:total_participants_web] %><%= @stats[:total_participants_booth] %>
- - <%= t("polls.stats.total_votes") %> -

- <%= @stats[:total_votes] %> -

-
-
-
-
-<% end %> \ No newline at end of file diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 77579a7ea..e39d1aa07 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -497,6 +497,17 @@ en: read_more: "Read more about %{answer}" read_less: "Read less about %{answer}" participate_in_other_polls: Participate in other polls + stats: + title: "Participation data" + total_participation: "Total participation" + total_votes: "Total amount of given votes" + votes: "VOTES" + web: "WEB" + booth: "BOOTH" + total: "TOTAL" + valid: "Valid" + white: "White votes" + null_votes: "Invalid" poll_questions: create_question: "Create question" default_valid_answers: "Yes, No" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 11e5e252a..8ba167a05 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -497,6 +497,17 @@ es: read_more: "Leer más sobre %{answer}" read_less: "Leer menos sobre %{answer}" participate_in_other_polls: Participar en otras votaciones + stats: + title: "Datos de participación" + total_participation: "Participación total" + total_votes: "Nº total de votos emitidos" + votes: "VOTOS" + web: "WEB" + booth: "URNAS" + total: "TOTAL" + valid: "Válidos" + white: "En blanco" + null_votes: "Nulos" poll_questions: create_question: "Crear pregunta para votación" default_valid_answers: "Sí, No" From 0f73b787b2fda47f95130df2395511ade1fbaca8 Mon Sep 17 00:00:00 2001 From: iagirre Date: Tue, 17 Oct 2017 16:07:44 +0200 Subject: [PATCH 3/6] Fixed views and Poll::Stats model to pass the specs --- app/models/poll/stats.rb | 2 +- app/views/polls/_results_subnavigation.html.erb | 4 ++-- app/views/polls/show.html.erb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index 1eef537a0..1df281434 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -26,7 +26,7 @@ class Poll end def total_participants_web_percentage - total_participants_web * 100 / total_participants + (total_participants) == 0 ? 0 : total_participants_web * 100 / total_participants end def total_participants_booth diff --git a/app/views/polls/_results_subnavigation.html.erb b/app/views/polls/_results_subnavigation.html.erb index afff4de03..43aa95b40 100644 --- a/app/views/polls/_results_subnavigation.html.erb +++ b/app/views/polls/_results_subnavigation.html.erb @@ -1,14 +1,14 @@
    -
  • +
  • <%= link_to "#tab-stats" do %>

    <%= "Estadísticas" %>

    <% end %>
  • -
  • +
  • <%= link_to "#tab-information" do %>

    <%= "Información" %> diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index e7e22124e..e4e11af6f 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -32,10 +32,10 @@
    <%= render "results_subnavigation" %> -
    +
    <%= render "polls/stats/show" %>
    -
    +
    <%= render "show" %>
    From 73365ad9d2fa1483244994df7ecef535b9dd9aa3 Mon Sep 17 00:00:00 2001 From: iagirre Date: Wed, 18 Oct 2017 09:34:17 +0200 Subject: [PATCH 4/6] Added spects to check de stats model and view --- .../polls/_results_subnavigation.html.erb | 4 +- config/locales/en/general.yml | 2 + config/locales/es/general.yml | 2 + spec/features/polls/polls_spec.rb | 13 ++++++ spec/models/poll/stats_spec.rb | 45 +++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 spec/models/poll/stats_spec.rb diff --git a/app/views/polls/_results_subnavigation.html.erb b/app/views/polls/_results_subnavigation.html.erb index 43aa95b40..9c2a7e8b0 100644 --- a/app/views/polls/_results_subnavigation.html.erb +++ b/app/views/polls/_results_subnavigation.html.erb @@ -4,14 +4,14 @@
  • <%= link_to "#tab-stats" do %>

    - <%= "Estadísticas" %> + <%= t("polls.show.stats_menu") %>

    <% end %>
  • <%= link_to "#tab-information" do %>

    - <%= "Información" %> + <%= t("polls.show.info_menu") %>

    <% end %>
  • diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index e39d1aa07..6867a1aa1 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -497,6 +497,8 @@ en: read_more: "Read more about %{answer}" read_less: "Read less about %{answer}" participate_in_other_polls: Participate in other polls + info_menu: "Information" + stats_menu: "Participation statistics" stats: title: "Participation data" total_participation: "Total participation" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 8ba167a05..38f4077c7 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -497,6 +497,8 @@ es: read_more: "Leer más sobre %{answer}" read_less: "Leer menos sobre %{answer}" participate_in_other_polls: Participar en otras votaciones + info_menu: "Información" + stats_menu: "Estadísticas de participación" stats: title: "Datos de participación" total_participation: "Participación total" diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 90deca711..223aa9e9d 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -357,4 +357,17 @@ feature 'Polls' do end end + + context "Results and stats" do + scenario "See polls statistics", :js do + 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") + end + end end diff --git a/spec/models/poll/stats_spec.rb b/spec/models/poll/stats_spec.rb new file mode 100644 index 000000000..ee431fa97 --- /dev/null +++ b/spec/models/poll/stats_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +describe Poll::Stats do + + describe "Calculate stats" do + it "Generate the correct stats" do + poll = create(:poll) + booth = create(:poll_booth) + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + create(:poll_voter, poll: poll, origin: 'web') + 3.times {create(:poll_voter, poll: poll, origin: 'booth')} + create(:poll_voter, poll: poll) + create(:poll_recount, origin: 'booth', white_amount: 1, null_amount: 0, total_amount: 2, booth_assignment_id: booth_assignment.id) + stats = Poll::Stats.new(poll).generate + + expect(stats[:total_participants]).to eq(5) + expect(stats[:total_participants_web]).to eq(2) + expect(stats[:total_participants_booth]).to eq(3) + expect(stats[:total_valid_votes]).to eq(4) + expect(stats[:total_white_votes]).to eq(1) + expect(stats[:total_null_votes]).to eq(0) + + expect(stats[:total_web_valid]).to eq(2) + expect(stats[:total_web_white]).to eq(0) + expect(stats[:total_web_null]).to eq(0) + + expect(stats[:total_booth_valid]).to eq(2) + expect(stats[:total_booth_white]).to eq(1) + expect(stats[:total_booth_null]).to eq(0) + + expect(stats[:total_participants_web_percentage]).to eq(40) + expect(stats[:total_participants_booth_percentage]).to eq(60) + expect(stats[:valid_percentage_web]).to eq(50) + expect(stats[:white_percentage_web]).to eq(0) + expect(stats[:null_percentage_web]).to eq(0) + expect(stats[:valid_percentage_booth]).to eq(50) + expect(stats[:white_percentage_booth]).to eq(100) + expect(stats[:null_percentage_booth]).to eq(0) + expect(stats[:total_valid_percentage]).to eq(80) + expect(stats[:total_white_percentage]).to eq(20) + expect(stats[:total_null_percentage]).to eq(0) + end + end + +end \ No newline at end of file From c896800325b5eb21ac1271e98aa41ca51b8887a1 Mon Sep 17 00:00:00 2001 From: iagirre Date: Wed, 18 Oct 2017 09:53:03 +0200 Subject: [PATCH 5/6] Removed added and unused route --- config/routes.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index e9ae237f0..ae4f7280c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,8 +111,6 @@ Rails.application.routes.draw do resources :annotations do get :search, on: :collection end - - get "polls/:id/stats", to: "polls/stats#show", as: 'custom_poll_stats' resources :polls, only: [:show, :index] do resources :questions, controller: 'polls/questions', shallow: true do From 81b1fb1a72b749ec16a843b963850d555922c2ce Mon Sep 17 00:00:00 2001 From: iagirre Date: Wed, 18 Oct 2017 10:27:41 +0200 Subject: [PATCH 6/6] Fixed some conflicts automatically merged that didn't realised before they were there --- app/views/polls/_show.html.erb | 21 ++++++++++++++++++--- app/views/polls/show.html.erb | 21 ++------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/views/polls/_show.html.erb b/app/views/polls/_show.html.erb index 6350048ef..ee75ea5e3 100644 --- a/app/views/polls/_show.html.erb +++ b/app/views/polls/_show.html.erb @@ -8,7 +8,7 @@
    <% else %> - <% if current_user && !@poll.votable_by?(current_user) %> + <% if current_user && @poll.voted_in_web?(current_user) %>
    <%= t("polls.show.already_voted_in_web") %>
    @@ -49,8 +49,7 @@
    <% @poll_questions_answers.each do |answer| %> -
    +
    <% if answer.description.present? %>

    <%= answer.title %>

    @@ -96,6 +95,22 @@ <% end %>
    <% end %> + + <% if answer.videos.present? %> + + <% end %>
    <% end %>
    diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 9f3e36c75..880d0d421 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -31,28 +31,11 @@
    <%= render "results_subnavigation" %> - <% if current_user && @poll.voted_in_web?(current_user) %> -
    - <%= render "polls/stats/show" %> - target: "_blank", - rel: "nofollow" %>
    - <% end %> -
    - <% end %> - - <% if answer.videos.present? %> - +
    <%= render "show" %>