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.
This commit is contained in:
Sebastian Ziebell 2013-02-27 17:50:30 +01:00
parent 43d7596030
commit 7499f65014
10 changed files with 35 additions and 42 deletions

View file

@ -29,9 +29,7 @@ module Gitlab
# POST /groups
post do
authenticated_as_admin!
bad_request!(:name) unless params[:name].present?
bad_request!(:path) unless params[:path].present?
required_attributes! [:name, :path]
attrs = attributes_for_keys [:name, :path]
@group = Group.new(attrs)