mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Don't advance draft sequence when editing topic title (#16002)
This commit handles the edge case where a draft is lost with no warnings if the user edits the title (or category/tags) of a topic while they're replying.to the same topic. Repro steps are as follows: 1. Start replying to a topic and type enough to get a draft saved. 2. Scroll up to the topic title and click the pencil icon next to the topic title, change the title, category and/or tags, and then save the changes. 3. Reload the page and you'll see that the draft is gone. This happens because we only allow 1 draft per topic per user and when you edit the title of a topic that you're replying to, from the server perspective it'll look like as if you've submitted your reply so it will advance the draft sequence for the topic and delete the draft. The fix in this commit makes `PostRevisor` skip advancing the draft sequence when a topic's title is edited using the pencil button next to the title. Internal ticket: t60854. Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
@@ -1236,6 +1236,33 @@ describe PostRevisor do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with drafts' do
|
||||
it "does not advance draft sequence if keep_existing_draft option is true" do
|
||||
post = Fabricate(:post, user: user)
|
||||
topic = post.topic
|
||||
draft_key = "topic_#{topic.id}"
|
||||
data = { reply: "test 12222" }.to_json
|
||||
Draft.set(user, draft_key, 0, data)
|
||||
Draft.set(user, draft_key, 0, data)
|
||||
expect {
|
||||
PostRevisor.new(post).revise!(
|
||||
post.user,
|
||||
{ title: "updated title for my topic" },
|
||||
keep_existing_draft: true
|
||||
)
|
||||
}.to change { Draft.where(user: user, draft_key: draft_key).first.sequence }.by(0)
|
||||
.and change { DraftSequence.where(user_id: user.id, draft_key: draft_key).first.sequence }.by(0)
|
||||
|
||||
expect {
|
||||
PostRevisor.new(post).revise!(
|
||||
post.user,
|
||||
{ title: "updated title for my topic" },
|
||||
)
|
||||
}.to change { Draft.where(user: user, draft_key: draft_key).count }.from(1).to(0)
|
||||
.and change { DraftSequence.where(user_id: user.id, draft_key: draft_key).first.sequence }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the review_every_post setting is enabled' do
|
||||
|
||||
Reference in New Issue
Block a user