category stats shouldn't include deleted topics.

This commit is contained in:
Dan Neumann
2013-02-16 14:57:16 -06:00
parent 921c3f016f
commit fac75401ef
4 changed files with 66 additions and 35 deletions

View File

@ -157,31 +157,57 @@ describe Category do
end
describe 'update_stats' do
# We're going to test with one topic. That's enough for stats!
before do
@category = Fabricate(:category)
# Create a non-invisible category to make sure count is 1
@topic = Fabricate(:topic, user: @category.user, category: @category)
Category.update_stats
@category.reload
end
context 'with regular topics' do
it 'updates topics_week' do
@category.topics_week.should == 1
before do
@category.topics << Fabricate(:topic,
user: @category.user)
Category.update_stats
@category.reload
end
it 'updates topics_week' do
@category.topics_week.should == 1
end
it 'updates topics_month' do
@category.topics_month.should == 1
end
it 'updates topics_year' do
@category.topics_year.should == 1
end
end
context 'with deleted topics' do
it 'updates topics_month' do
@category.topics_month.should == 1
end
before do
@category.topics << Fabricate(:deleted_topic,
user: @category.user)
Category.update_stats
@category.reload
end
it 'does not count deleted topics for topics_week' do
@category.topics_week.should == 0
end
it 'does not count deleted topics for topics_month' do
@category.topics_month.should == 0
end
it 'does not count deleted topics for topics_year' do
@category.topics_year.should == 0
end
it 'updates topics_year' do
@category.topics_year.should == 1
end
end
end