From f978a71f41d5546be2c0c6b33052979c06912bd1 Mon Sep 17 00:00:00 2001
From: Sebastian Ziebell <sebastian.ziebell@asquera.de>
Date: Tue, 5 Feb 2013 18:37:44 +0100
Subject: [PATCH] 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                | 3 +++
 spec/requests/api/merge_requests_spec.rb | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index ec63b352474..a0ca3026acb 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -128,6 +128,9 @@ module Gitlab
         if note.save
           present note, with: Entities::MRNote
         else
+          if note.errors[:note].any?
+            error!(note.errors[:note], 400)
+          end
           not_found!
         end
       end
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index bf87ecbdc6f..531b56b8e53 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -87,6 +87,11 @@ describe Gitlab::API do
       response.status.should == 201
       json_response['note'].should == 'My comment'
     end
+
+    it "should return 400 if note is missing" do
+      post api("/projects/#{project.id}/merge_request/#{merge_request.id}/comments", user)
+      response.status.should == 400
+    end
   end
 
 end
-- 
GitLab