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:
Bianca Nenciu
2024-07-10 10:43:11 +03:00
committed by GitHub
parent acc8b46d51
commit 6591a0654b
3 changed files with 45 additions and 11 deletions

View File

@@ -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