FIX: Update draft count after creating a post (#13884)

When a post is created, the draft sequence is increased and then older
drafts are automatically executing a raw SQL query. This skipped the
Draft model callbacks and did not update user's draft count.

I fixed another problem related to a raw SQL query from Draft.cleanup!
method.
This commit is contained in:
Bianca Nenciu
2021-07-29 17:06:11 +03:00
committed by GitHub
parent 9b8c4d4790
commit 300db3d3fa
5 changed files with 36 additions and 14 deletions

View File

@@ -152,6 +152,7 @@ describe Draft do
Draft.set(user, key, 0, 'draft')
Draft.cleanup!
expect(Draft.count).to eq 1
expect(user.user_stat.draft_count).to eq(1)
seq = DraftSequence.next!(user, key)
@@ -161,6 +162,7 @@ describe Draft do
Draft.cleanup!
expect(Draft.count).to eq 0
expect(user.reload.user_stat.draft_count).to eq(0)
Draft.set(Fabricate(:user), Draft::NEW_TOPIC, 0, 'draft')