mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
category stats shouldn't include deleted topics.
This commit is contained in:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user