Commit f978a71f41d5546be2c0c6b33052979c06912bd1

Authored by Sebastian Ziebell
1 parent 3f4e215c

Creating MR comment without a note returns status code 400 (Bad request)

Creating a comment to an existing merge request via API without providing a note
returns a status code 400 now, suggesting a bad request. The reason for this
is the resource itself (MR) exists but the required property is not set.
lib/api/merge_requests.rb
... ... @@ -128,6 +128,9 @@ module Gitlab
128 128 if note.save
129 129 present note, with: Entities::MRNote
130 130 else
  131 + if note.errors[:note].any?
  132 + error!(note.errors[:note], 400)
  133 + end
131 134 not_found!
132 135 end
133 136 end
... ...
spec/requests/api/merge_requests_spec.rb
... ... @@ -87,6 +87,11 @@ describe Gitlab::API do
87 87 response.status.should == 201
88 88 json_response['note'].should == 'My comment'
89 89 end
  90 +
  91 + it "should return 400 if note is missing" do
  92 + post api("/projects/#{project.id}/merge_request/#{merge_request.id}/comments", user)
  93 + response.status.should == 400
  94 + end
90 95 end
91 96  
92 97 end
... ...