mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Destroy Drafts when increasing sequences (#27739)
Drafts used to be deleted instead of being destroyed. The callbacks that
clean up the upload references were not being called. As a result, the
upload references were not cleaned up and uploads were not deleted
either. This has been partially fixed in 9655bf3e
.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
RSpec.describe DraftSequence do
|
||||
fab!(:user)
|
||||
fab!(:upload)
|
||||
|
||||
describe ".next" do
|
||||
it "should produce next sequence for a key" do
|
||||
@@ -14,11 +15,29 @@ RSpec.describe DraftSequence do
|
||||
2.times { expect(DraftSequence.next!(user, "test")).to eq(0) }
|
||||
end
|
||||
|
||||
it "updates draft count" do
|
||||
Draft.create!(user: user, draft_key: "test", data: {})
|
||||
expect(user.reload.user_stat.draft_count).to eq(1)
|
||||
expect(DraftSequence.next!(user, "test")).to eq 1
|
||||
expect(user.reload.user_stat.draft_count).to eq(0)
|
||||
it "deletes old drafts and associated upload references" do
|
||||
Draft.set(
|
||||
user,
|
||||
Draft::NEW_TOPIC,
|
||||
0,
|
||||
{
|
||||
reply: "[#{upload.original_filename}|attachment](#{upload.short_url})",
|
||||
action: "createTopic",
|
||||
title: "New topic with an upload",
|
||||
categoryId: 1,
|
||||
tags: [],
|
||||
archetypeId: "regular",
|
||||
metaData: nil,
|
||||
composerTime: 10_000,
|
||||
typingTime: 10_000,
|
||||
}.to_json,
|
||||
)
|
||||
|
||||
expect { DraftSequence.next!(user, Draft::NEW_TOPIC) }.to change { Draft.count }.by(
|
||||
-1,
|
||||
).and change { UploadReference.count }.by(-1).and change {
|
||||
user.reload.user_stat.draft_count
|
||||
}.by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user