From dc522718812600cea12695ba17a77428affe851a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 26 Sep 2015 13:07:21 +0200 Subject: [PATCH 1/4] displays stats summary --- app/controllers/admin/stats_controller.rb | 16 ++++++++++++++++ app/views/admin/stats/show.html.erb | 23 ++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 3bcb50a86..ec5c2d19d 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -2,6 +2,22 @@ class Admin::StatsController < Admin::BaseController def show @event_types = Ahoy::Event.group(:name).count + + @visits = Visit.count + @debates = Debate.with_hidden.count + @proposals = Proposal.with_hidden.count + @comments = Comment.with_hidden.count + + @debate_votes = Vote.where(votable_type: 'Debate').count + @proposal_votes = Vote.where(votable_type: 'Proposal').count + @comment_votes = Vote.where(votable_type: 'Comment').count + @votes = Vote.count + + @user_level_two = User.with_hidden.level_two_verified.count + @user_level_three = User.with_hidden.level_three_verified.count + @verified_users = User.with_hidden.level_two_or_three_verified.count + @unverified_users = User.with_hidden.unverified.count + @users = User.with_hidden.count end end diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 42c7e6726..1f6c39327 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -4,15 +4,32 @@
-

Stats

+

<%= t "admin.stats.show.stats_title" %>

+ +

<%= t "admin.stats.show.summary_title" %>

+
    +
  • <%= t "admin.stats.show.summary.visits" %>: <%= @visits %>
  • +
  • <%= t "admin.stats.show.summary.debates" %>: <%= @debates %>
  • +
  • <%= t "admin.stats.show.summary.proposals" %>: <%= @proposals %>
  • +
  • <%= t "admin.stats.show.summary.comments" %>: <%= @comments %>
  • +
  • <%= t "admin.stats.show.summary.debate_votes" %>: <%= @debate_votes %>
  • +
  • <%= t "admin.stats.show.summary.proposal_votes" %>: <%= @proposal_votes %>
  • +
  • <%= t "admin.stats.show.summary.comment_votes" %>: <%= @comment_votes %>
  • +
  • <%= t "admin.stats.show.summary.votes" %>: <%= @votes %>
  • +
  • <%= t "admin.stats.show.summary.user_level_two" %>: <%= @user_level_two %>
  • +
  • <%= t "admin.stats.show.summary.user_level_three" %>: <%= @user_level_three %>
  • +
  • <%= t "admin.stats.show.summary.verified_users" %>: <%= @verified_users %>
  • +
  • <%= t "admin.stats.show.summary.unverified_users" %>: <%= @unverified_users %>
  • +
  • <%= t "admin.stats.show.summary.users" %>: <%= @users %>
  • +
-

Visits

+

<%= t "admin.stats.show.combined_title" %>

<%= visits_chart_tag id: "visits" %>
-

Combined

+

<%= t "admin.stats.show.visits_title" %>

<%= events_chart_tag @event_types.keys, id: 'combined' %>
From d39fc60f929e9e659463cbd14651aa55eeb94611 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 26 Sep 2015 13:08:09 +0200 Subject: [PATCH 2/4] fixes unverified user's scope --- app/models/concerns/verification.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/verification.rb b/app/models/concerns/verification.rb index fe5172c65..a859b4c46 100644 --- a/app/models/concerns/verification.rb +++ b/app/models/concerns/verification.rb @@ -5,7 +5,7 @@ module Verification scope :level_three_verified, -> { where.not(verified_at: nil) } scope :level_two_verified, -> { where("users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL") } scope :level_two_or_three_verified, -> { where("users.verified_at IS NOT NULL OR (users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL)") } - scope :unverified, -> { where("users.verified_at IS NULL AND (users.confirmed_phone IS NULL OR users.residence_verified_at IS NOT NULL)") } + scope :unverified, -> { where("users.verified_at IS NULL AND (users.residence_verified_at IS NULL OR users.confirmed_phone IS NULL)") } end def verification_email_sent? From 50a410786c37b2c6b61418cf5b2d7c86c62f0aa3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 26 Sep 2015 13:08:22 +0200 Subject: [PATCH 3/4] adds translations --- config/locales/admin.en.yml | 20 ++++++++++++++++++++ config/locales/admin.es.yml | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index c5d5616a4..0de19481f 100644 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -147,3 +147,23 @@ en: hide: Hidden restore: Restored block: Blocked + stats: + show: + summary_title: Summary + stats_title: Stats + visits_title: Visits + combined_title: Combined + summary: + visits: Visits + debates: Debates + proposals: Proposals + comments: Comments + debate_votes: Debate votes + proposal_votes: Proposal votes + comment_votes: Comment votes + votes: Total votes + user_level_three: Level three users + user_level_two: Level two users + unverified_users: Unverified users + verified_users: Verified users + users: Total users \ No newline at end of file diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 0e7903934..1f6e1ac7e 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -147,3 +147,23 @@ es: hide: Ocultado restore: Restaurado block: Bloqueado + stats: + show: + summary_title: Resumen + stats_title: Estadísticas + visits_title: Visitas + combined_title: Combinado + summary: + visits: Visitas + debates: Debates + proposals: Propuestas + comments: Comentarios + debate_votes: Votes en debates + proposal_votes: Votos en propuestas + comment_votes: Votso en comentarios + votes: Votos + user_level_three: Usuarios de nivel tres + user_level_two: Usuarios de nivel dos + unverified_users: Usuarios sin verificar + verified_users: Usuarios verificados + users: Usuarios From 2cc02ff41df17f9dc208b7c8b8d33122d76989d2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 26 Sep 2015 13:08:38 +0200 Subject: [PATCH 4/4] adds specs --- spec/features/stats_spec.rb | 64 ++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/spec/features/stats_spec.rb b/spec/features/stats_spec.rb index d56b8f2c3..ee06b9c79 100644 --- a/spec/features/stats_spec.rb +++ b/spec/features/stats_spec.rb @@ -2,17 +2,73 @@ require 'rails_helper' feature 'Stats' do - scenario 'Level 2 user' do + background do admin = create(:administrator) - user = create(:user) - login_as(user) + login_as(admin.user) + end + context 'Summary' do + + scenario 'General' do + create(:debate) + 2.times { create(:proposal) } + 3.times { create(:comment, commentable: Debate.first) } + 4.times { create(:visit) } + + visit admin_stats_path + + expect(page).to have_content "Debates: 1" + expect(page).to have_content "Proposals: 2" + expect(page).to have_content "Comments: 3" + expect(page).to have_content "Visits: 4" + end + + scenario 'Votes' do + debate = create(:debate) + create(:vote, votable: debate) + + proposal = create(:proposal) + 2.times { create(:vote, votable: proposal) } + + comment = create(:comment) + 3.times { create(:vote, votable: comment) } + + visit admin_stats_path + + expect(page).to have_content "Debate votes: 1" + expect(page).to have_content "Proposal votes: 2" + expect(page).to have_content "Comment votes: 3" + expect(page).to have_content "Total votes: 6" + end + + scenario 'Users' do + Administrator.destroy_all + User.all.map(&:really_destroy!) + + 1.times { create(:user, :level_three) } + 2.times { create(:user, :level_two) } + 3.times { create(:user) } + + admin = create(:administrator) + login_as(admin.user) + + visit admin_stats_path + + expect(page).to have_content "Level three users: 1" + expect(page).to have_content "Level two users: 2" + expect(page).to have_content "Verified users: 3" + expect(page).to have_content "Unverified users: 4" + expect(page).to have_content "Total users: 7" + end + + end + + scenario 'Level 2 user' do visit account_path click_link 'Verify my account' verify_residence confirm_phone - login_as(admin.user) visit admin_stats_path expect(page).to have_content "Level 2 User (1)"