FIX: Return a 404 when the draft_key is missing

Previously if `draft_key` was missing you'd get a 500 error in the logs.
This commit is contained in:
Robin Ward 2020-02-14 10:48:56 -05:00
parent aad46a1aba
commit bfdd42c53a
2 changed files with 8 additions and 0 deletions

View File

@ -11,6 +11,8 @@ class DraftController < ApplicationController
end
def update
raise Discourse::NotFound.new if params[:draft_key].blank?
sequence =
begin
Draft.set(

View File

@ -21,6 +21,12 @@ describe DraftController do
expect(Draft.get(user, 'xyz', 0)).to eq(%q({"my":"data"}))
end
it "returns 404 when the key is missing" do
user = sign_in(Fabricate(:user))
post "/draft.json", params: { data: { my: "data" }.to_json, sequence: 0 }
expect(response.status).to eq(404)
end
it 'checks for an conflict on update' do
user = sign_in(Fabricate(:user))
post = Fabricate(:post, user: user)