Merge pull request #600 from kubabrecka/consistent_topic_count

make sure Category.topic_count is consistent with week/year stats
This commit is contained in:
Robin Ward 2013-04-01 07:37:07 -07:00
commit f9ea1a448d
2 changed files with 11 additions and 1 deletions

View File

@ -61,11 +61,13 @@ class Category < ActiveRecord::Base
.where("categories.topic_id <> topics.id") .where("categories.topic_id <> topics.id")
.visible .visible
topic_count = topics.to_sql
topics_year = topics.created_since(1.year.ago).to_sql topics_year = topics.created_since(1.year.ago).to_sql
topics_month = topics.created_since(1.month.ago).to_sql topics_month = topics.created_since(1.month.ago).to_sql
topics_week = topics.created_since(1.week.ago).to_sql topics_week = topics.created_since(1.week.ago).to_sql
Category.update_all("topics_year = (#{topics_year}), Category.update_all("topic_count = (#{topic_count}),
topics_year = (#{topics_year}),
topics_month = (#{topics_month}), topics_month = (#{topics_month}),
topics_week = (#{topics_week})") topics_week = (#{topics_week})")
end end

View File

@ -177,6 +177,10 @@ describe Category do
it 'updates topics_year' do it 'updates topics_year' do
@category.topics_year.should == 1 @category.topics_year.should == 1
end end
it 'updates topic_count' do
@category.topic_count.should == 1
end
end end
context 'with deleted topics' do context 'with deleted topics' do
@ -198,6 +202,10 @@ describe Category do
it 'does not count deleted topics for topics_year' do it 'does not count deleted topics for topics_year' do
@category.topics_year.should == 0 @category.topics_year.should == 0
end end
it 'does not count deleted topics for topic_count' do
@category.topic_count.should == 0
end
end end
end end
end end