From c94fdcea38a49f3d3e68652b97fcb87425216358 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 21 Feb 2017 14:45:34 -0500 Subject: [PATCH] FIX: admin dashboard posts count should not include system posts and whispers --- app/models/report.rb | 2 +- spec/models/report_spec.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/report.rb b/app/models/report.rb index d5751ad3159..b568aec1eab 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -122,7 +122,7 @@ class Report def self.report_posts(report) basic_report_about report, Post, :public_posts_count_per_day, report.start_date, report.end_date, report.category_id - countable = Post.public_posts + countable = Post.public_posts.where(post_type: Post.types[:regular]) countable = countable.joins(:topic).where("topics.category_id = ?", report.category_id) if report.category_id add_counts report, countable, 'posts.created_at' end diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 8ea96c9cfcb..661cea8b2b8 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -209,5 +209,15 @@ describe Report do end end end -end + describe 'posts counts' do + it "only counts regular posts" do + post = Fabricate(:post) + Fabricate(:moderator_post, topic: post.topic) + Fabricate.build(:post, post_type: Post.types[:whisper], topic: post.topic) + post.topic.add_small_action(Fabricate(:admin), "invited_group", 'coolkids') + r = Report.find('posts') + expect(r.total).to eq(1) + end + end +end