mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 00:37:44 +08:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user