From 99d26cef1a21bc795b8b6a4d10c7a62acd7cd1d4 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 27 Aug 2014 15:58:05 -0400 Subject: [PATCH] FIX: uncategorized counts were always 0. topics_year, topics_month, topics_week, topics_day --- app/models/category.rb | 3 ++- spec/models/category_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/category.rb b/app/models/category.rb index 309ae428268..390f8f2d363 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -133,7 +133,8 @@ SQL # If you refactor this, test performance on a large database. Category.all.each do |c| - topics = c.topics.where(['topics.id <> ?', c.topic_id]).visible + topics = c.topics.visible + topics = topics.where(['topics.id <> ?', c.topic_id]) if c.topic_id c.topics_year = topics.created_since(1.year.ago).count c.topics_month = topics.created_since(1.month.ago).count c.topics_week = topics.created_since(1.week.ago).count diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index a71d78f4fee..700d5e32a6a 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -380,6 +380,26 @@ describe Category do @category.posts_week.should == 1 end end + + context 'for uncategorized category' do + before do + @uncategorized = Category.find(SiteSetting.uncategorized_category_id) + create_post(user: Fabricate(:user), category: @uncategorized.name) + Category.update_stats + @uncategorized.reload + end + + it 'updates topic stats' do + @uncategorized.topics_week.should == 1 + @uncategorized.topics_month.should == 1 + @uncategorized.topics_year.should == 1 + @uncategorized.topic_count.should == 1 + @uncategorized.post_count.should == 1 + @uncategorized.posts_year.should == 1 + @uncategorized.posts_month.should == 1 + @uncategorized.posts_week.should == 1 + end + end end describe "#url" do