summaryrefslogtreecommitdiff
path: root/lib/api/notes.rb
diff options
context:
space:
mode:
authorSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-27 17:50:30 +0100
committerSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-27 17:50:30 +0100
commit7499f65014257989510da50505fa7c0f5a4fae88 (patch)
treeb8c9355b73ec48c12bfa9d6416fa91ba4c4444e6 /lib/api/notes.rb
parent43d75960303be538fb79804ca6e2a90241aee0df (diff)
downloadgitlab-ce-7499f65014257989510da50505fa7c0f5a4fae88.tar.gz
API: extracted helper method to validate required parameters, code clean up
Added a helper method to check if required parameters are given in an API call. Can be used to return a `400 Bad Request` return code if a required attribute is missing. Code clean up and fixed tests.
Diffstat (limited to 'lib/api/notes.rb')
-rw-r--r--lib/api/notes.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/api/notes.rb b/lib/api/notes.rb
index 953514b6f04..759fd3a9819 100644
--- a/lib/api/notes.rb
+++ b/lib/api/notes.rb
@@ -37,7 +37,7 @@ module Gitlab
# Example Request:
# POST /projects/:id/notes
post ":id/notes" do
- bad_request!(:body) unless params[:body].present?
+ required_attributes! [:body]
@note = user_project.notes.new(note: params[:body])
@note.author = current_user
@@ -93,8 +93,7 @@ module Gitlab
# POST /projects/:id/issues/:noteable_id/notes
# POST /projects/:id/snippets/:noteable_id/notes
post ":id/#{noteables_str}/:#{noteable_id_str}/notes" do
- bad_request!(:"#{noteable_id_str}") unless params[:"#{noteable_id_str}"].present?
- bad_request!(:body) unless params[:body].present?
+ required_attributes! [:"#{noteable_id_str}"]
@noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"])
@note = @noteable.notes.new(note: params[:body])