Commit c1173e27071b83399cd92406b229be7f0eca59f1

Authored by Alex Denisov
1 parent 65abd8b2

API on Projects creation implemented

lib/api/projects.rb
... ... @@ -23,6 +23,27 @@ module Gitlab
23 23 present user_project, with: Entities::Project
24 24 end
25 25  
  26 + # Create new project
  27 + #
  28 + # Parameters:
  29 + # name (required) - name for new project
  30 + # code (optional) - code for new project, if not set used name
  31 + # path (optional) - oath for new project, if not set used name
  32 + # Example Request
  33 + # POST /projects
  34 + post do
  35 + project = {}
  36 + project[:name] = params[:name]
  37 + project[:code] = params[:code] || project[:name]
  38 + project[:path] = params[:path] || project[:name]
  39 + @project = Project.create_by_user(project, current_user)
  40 + if @project.saved?
  41 + present @project, with: Entities::Project
  42 + else
  43 + error!({'message' => '404 Not found'}, 404)
  44 + end
  45 + end
  46 +
26 47 # Get a project repository branches
27 48 #
28 49 # Parameters:
... ...
spec/requests/api/projects_spec.rb
... ... @@ -25,6 +25,43 @@ describe Gitlab::API do
25 25 end
26 26 end
27 27  
  28 + describe "POST /projects" do
  29 + it "should create new project without code and path" do
  30 + lambda {
  31 + name = "foo"
  32 + post api("/projects", user), {
  33 + name: name
  34 + }
  35 + response.status.should == 201
  36 + json_response["name"].should == name
  37 + json_response["code"].should == name
  38 + json_response["path"].should == name
  39 + }.should change{Project.count}.by(1)
  40 + end
  41 + it "should create new project" do
  42 + lambda {
  43 + name = "foo"
  44 + path = "bar"
  45 + code = "bazz"
  46 + post api("/projects", user), {
  47 + code: code,
  48 + path: path,
  49 + name: name
  50 + }
  51 + response.status.should == 201
  52 + json_response["name"].should == name
  53 + json_response["path"].should == path
  54 + json_response["code"].should == code
  55 + }.should change{Project.count}.by(1)
  56 + end
  57 + it "should not create project without name" do
  58 + lambda {
  59 + post api("/projects", user)
  60 + response.status.should == 404
  61 + }.should_not change{Project.count}
  62 + end
  63 + end
  64 +
28 65 describe "GET /projects/:id" do
29 66 it "should return a project by id" do
30 67 get api("/projects/#{project.id}", user)
... ...