diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 8854f0e4..c98501a2 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -17,7 +17,18 @@ class StaticController < ApplicationController end 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 def faq diff --git a/app/views/static/about.haml b/app/views/static/about.haml index f6ad2c21..34ba6762 100644 --- a/app/views/static/about.haml +++ b/app/views/static/about.haml @@ -48,21 +48,21 @@ %p= t('views.about.statistics.desc', app_title: APP_CONFIG['site_name']) .col-md-3.col-sm-6.col-xs-6 .entry.entry--statistics - %h2.entry__value#asked-count= Question.count - %h4.entry__description= t('views.general.question').pluralize(Question.count) + %h2.entry__value#asked-count= @questions + %h4.entry__description= t('views.general.question').pluralize(@questions) .entry.entry--statistics - %h2.entry__value#answered-count= Answer.count - %h4.entry__description= t('views.general.answer').pluralize(Answer.count) + %h2.entry__value#answered-count= @answers + %h4.entry__description= t('views.general.answer').pluralize(@answers) .col-md-3.col-sm-6.col-xs-6 .entry.entry--statistics - %h2.entry__value#comment-count= Comment.count - %h4.entry__description= t('views.general.comment').pluralize(Comment.count) + %h2.entry__value#comment-count= @comments + %h4.entry__description= t('views.general.comment').pluralize(@comments) .entry.entry--statistics - %h2.entry__value#smile-count= Smile.count + CommentSmile.count - %h4.entry__description= t('views.general.smile').pluralize(Smile.count) + %h2.entry__value#smile-count= @smiles + %h4.entry__description= t('views.general.smile').pluralize(@smiles) .col-md-3.col-sm-12.col-xs-12 .entry.entry--users - .entry__value#follower-count= User.count - %h4.entry__description= t('views.general.user').pluralize(User.count) + .entry__value#follower-count= @users + %h4.entry__description= t('views.general.user').pluralize(@users) = render 'shared/links' diff --git a/spec/controllers/static_controller_spec.rb b/spec/controllers/static_controller_spec.rb new file mode 100644 index 00000000..0a79ec39 --- /dev/null +++ b/spec/controllers/static_controller_spec.rb @@ -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 \ No newline at end of file