Update category's topic_count immediately when trashing or recovering a topic; this ensures that a category can be deleted without waiting for the category_stats job to run.

This commit is contained in:
Neil Lalonde
2013-07-08 15:23:20 -04:00
parent d3fe8f65a2
commit 806bd98f99
2 changed files with 42 additions and 0 deletions

View File

@ -1293,4 +1293,36 @@ describe Topic do
Topic.new(:category => nil).should_not be_secure_category
end
end
describe 'trash!' do
context "its category's topic count" do
let(:category) { Fabricate(:category) }
it "subtracts 1 if topic is being deleted" do
topic = Fabricate(:topic, category: category)
expect { topic.trash! }.to change { category.reload.topic_count }.by(-1)
end
it "doesn't subtract 1 if topic is already deleted" do
topic = Fabricate(:topic, category: category, deleted_at: 1.day.ago)
expect { topic.trash! }.to_not change { category.reload.topic_count }
end
end
end
describe 'recover!' do
context "its category's topic count" do
let(:category) { Fabricate(:category) }
it "adds 1 if topic is deleted" do
topic = Fabricate(:topic, category: category, deleted_at: 1.day.ago)
expect { topic.recover! }.to change { category.reload.topic_count }.by(1)
end
it "doesn't add 1 if topic is not deleted" do
topic = Fabricate(:topic, category: category)
expect { topic.recover! }.to_not change { category.reload.topic_count }
end
end
end
end