Merge pull request #204 from Retrospring/feature/user-count

Only count active users on about page
This commit is contained in:
Karina Kwiatek 2021-10-03 21:56:07 +02:00 committed by GitHub
commit 256e41754e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 10 deletions

View File

@ -17,7 +17,18 @@ class StaticController < ApplicationController
end end
def about def about
@users = User
.where.not(confirmed_at: nil)
.where(permanently_banned: false)
.where(banned_until: nil)
.where('answered_count > 0')
.where('asked_count > 0')
.count
@questions = Question.count
@answers = Answer.count
@comments = Comment.count
@smiles = Smile.count + CommentSmile.count
end end
def faq def faq

View File

@ -48,21 +48,21 @@
%p= t('views.about.statistics.desc', app_title: APP_CONFIG['site_name']) %p= t('views.about.statistics.desc', app_title: APP_CONFIG['site_name'])
.col-md-3.col-sm-6.col-xs-6 .col-md-3.col-sm-6.col-xs-6
.entry.entry--statistics .entry.entry--statistics
%h2.entry__value#asked-count= Question.count %h2.entry__value#asked-count= @questions
%h4.entry__description= t('views.general.question').pluralize(Question.count) %h4.entry__description= t('views.general.question').pluralize(@questions)
.entry.entry--statistics .entry.entry--statistics
%h2.entry__value#answered-count= Answer.count %h2.entry__value#answered-count= @answers
%h4.entry__description= t('views.general.answer').pluralize(Answer.count) %h4.entry__description= t('views.general.answer').pluralize(@answers)
.col-md-3.col-sm-6.col-xs-6 .col-md-3.col-sm-6.col-xs-6
.entry.entry--statistics .entry.entry--statistics
%h2.entry__value#comment-count= Comment.count %h2.entry__value#comment-count= @comments
%h4.entry__description= t('views.general.comment').pluralize(Comment.count) %h4.entry__description= t('views.general.comment').pluralize(@comments)
.entry.entry--statistics .entry.entry--statistics
%h2.entry__value#smile-count= Smile.count + CommentSmile.count %h2.entry__value#smile-count= @smiles
%h4.entry__description= t('views.general.smile').pluralize(Smile.count) %h4.entry__description= t('views.general.smile').pluralize(@smiles)
.col-md-3.col-sm-12.col-xs-12 .col-md-3.col-sm-12.col-xs-12
.entry.entry--users .entry.entry--users
.entry__value#follower-count= User.count .entry__value#follower-count= @users
%h4.entry__description= t('views.general.user').pluralize(User.count) %h4.entry__description= t('views.general.user').pluralize(@users)
= render 'shared/links' = render 'shared/links'

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
require "rails_helper"
describe StaticController, type: :controller do
describe "#about" do
subject { get :about }
before(:each) {
FactoryBot.create(:user, { confirmed_at: Time.now, answered_count: 1, asked_count: 1 })
FactoryBot.create(:user, { permanently_banned: true })
FactoryBot.create(:user, { banned_until: Time.now + 10.days })
FactoryBot.create(:user, { confirmed_at: Time.now })
}
it "shows the correct user count" do
subject
expect(assigns(:users)).to eq(1)
end
end
end