From a533f68c656901d882a35981f47a5445c1302b7b Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 26 Jun 2022 17:33:32 +0200 Subject: [PATCH] Adjust exporter and user count to match new ban system --- app/controllers/static_controller.rb | 18 ++++++++++++------ lib/exporter.rb | 4 ++-- spec/controllers/static_controller_spec.rb | 6 +++--- spec/lib/exporter_spec.rb | 7 ++----- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 6ca9c5e5..16958be3 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -17,13 +17,19 @@ 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') - .count + user_count = User + .where.not(confirmed_at: nil) + .where("answered_count > 0") + .count + current_ban_count = UserBan + .current + .joins(:user) + .where.not("users.confirmed_at": nil) + .where("users.answered_count > 0") + .count + + @users = user_count - current_ban_count @questions = Question.count @answers = Answer.count @comments = Comment.count diff --git a/lib/exporter.rb b/lib/exporter.rb index be446f7f..58191699 100644 --- a/lib/exporter.rb +++ b/lib/exporter.rb @@ -34,10 +34,10 @@ class Exporter private def collect_user_info - %i(answered_count asked_count ban_reason banned_until comment_smiled_count commented_count + %i(answered_count asked_count comment_smiled_count commented_count confirmation_sent_at confirmed_at created_at profile_header profile_header_h profile_header_w profile_header_x profile_header_y profile_picture_w profile_picture_h profile_picture_x profile_picture_y current_sign_in_at current_sign_in_ip - id last_sign_in_at last_sign_in_ip locale permanently_banned + id last_sign_in_at last_sign_in_ip locale privacy_allow_anonymous_questions privacy_allow_public_timeline privacy_allow_stranger_answers privacy_show_in_search profile_header_file_name profile_picture_file_name screen_name show_foreign_themes sign_in_count smiled_count updated_at).each do |f| diff --git a/spec/controllers/static_controller_spec.rb b/spec/controllers/static_controller_spec.rb index 125ddacc..4b43c7b1 100644 --- a/spec/controllers/static_controller_spec.rb +++ b/spec/controllers/static_controller_spec.rb @@ -5,12 +5,12 @@ require "rails_helper" describe StaticController, type: :controller do describe "#about" do subject { get :about } - + before(:each) { FactoryBot.create(:user, { confirmed_at: Time.current, answered_count: 1 }) - FactoryBot.create(:user, { permanently_banned: true }) - FactoryBot.create(:user, { banned_until: Time.current + 10.days }) + FactoryBot.create(:user, { confirmed_at: Time.current, answered_count: 1 }).ban FactoryBot.create(:user, { confirmed_at: Time.current }) + FactoryBot.create(:user, { confirmed_at: Time.current }).ban } it "shows the correct user count" do diff --git a/spec/lib/exporter_spec.rb b/spec/lib/exporter_spec.rb index dd7a4986..b86087b6 100644 --- a/spec/lib/exporter_spec.rb +++ b/spec/lib/exporter_spec.rb @@ -1,14 +1,12 @@ # frozen_string_literal: true -require 'rails_helper' -require 'exporter' +require "rails_helper" +require "exporter" RSpec.describe Exporter do let(:params) { { answered_count: 144, asked_count: 72, - ban_reason: nil, - banned_until: nil, comment_smiled_count: 15, commented_count: 12, confirmation_sent_at: 2.weeks.ago.utc, @@ -19,7 +17,6 @@ RSpec.describe Exporter do last_sign_in_at: 1.hour.ago, last_sign_in_ip: '192.0.2.14', locale: 'en', - permanently_banned: false, privacy_allow_anonymous_questions: true, privacy_allow_public_timeline: false, privacy_allow_stranger_answers: false,