2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 09:10:25 +08:00

FIX: ensure_consistency was able to create corrupt category topics

- Correct create_category_definition to skip validations and use a
transaction, no longer able to create corrupt topics

- ensure_consistency now clears topic_id if pointing at deleted or missing
topic_id

- Stop creating category definition topics for uncategorized
This commit is contained in:
Sam Saffron 2019-06-07 11:19:57 +10:00
parent 9db1fef4e3
commit c05b617067
2 changed files with 49 additions and 7 deletions

View file

@ -892,6 +892,12 @@ describe Category do
describe "#ensure_consistency!" do
it "creates category topic" do
# corrupt a category topic
uncategorized = Category.find(SiteSetting.uncategorized_category_id)
uncategorized.create_category_definition
uncategorized.topic.posts.first.destroy!
category = Fabricate(:category)
category_destroyed = Fabricate(:category)
category_trashed = Fabricate(:category)
@ -901,6 +907,12 @@ describe Category do
category_trashed.topic.trash!
Category.ensure_consistency!
# step one fix corruption
expect(uncategorized.reload.topic_id).to eq(nil)
Category.ensure_consistency!
# step two don't create a category definition for uncategorized
expect(uncategorized.reload.topic_id).to eq(nil)
expect(category.reload.topic_id).to eq(category_topic_id)
expect(category_destroyed.reload.topic).to_not eq(nil)