Commit f978a71f41d5546be2c0c6b33052979c06912bd1
1 parent
3f4e215c
Exists in
master
and in
4 other branches
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.
Showing
2 changed files
with
8 additions
and
0 deletions
Show diff stats
lib/api/merge_requests.rb
@@ -128,6 +128,9 @@ module Gitlab | @@ -128,6 +128,9 @@ module Gitlab | ||
128 | if note.save | 128 | if note.save |
129 | present note, with: Entities::MRNote | 129 | present note, with: Entities::MRNote |
130 | else | 130 | else |
131 | + if note.errors[:note].any? | ||
132 | + error!(note.errors[:note], 400) | ||
133 | + end | ||
131 | not_found! | 134 | not_found! |
132 | end | 135 | end |
133 | end | 136 | end |
spec/requests/api/merge_requests_spec.rb
@@ -87,6 +87,11 @@ describe Gitlab::API do | @@ -87,6 +87,11 @@ describe Gitlab::API do | ||
87 | response.status.should == 201 | 87 | response.status.should == 201 |
88 | json_response['note'].should == 'My comment' | 88 | json_response['note'].should == 'My comment' |
89 | end | 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 | end | 95 | end |
91 | 96 | ||
92 | end | 97 | end |