Commit d6a5e3dad7a8d5aa1eb2220c2c60f068455dbaed

Authored by Valeriy Sizov
2 parents 10d881c9 cf70439e

Merge pull request #1735 from NARKOZ/api

API fixes
CHANGELOG
... ... @@ -28,7 +28,7 @@ v 3.0.0
28 28 - Reject ssh keys that break gitolite
29 29 - [API] list one project hook
30 30 - [API] edit project hook
31   - - [API] add project snippets list
  31 + - [API] list project snippets
32 32 - [API] allow to authorize using private token in HTTP header
33 33 - [API] add user creation
34 34  
... ...
doc/api/users.md
... ... @@ -74,14 +74,12 @@ POST /users
74 74  
75 75 Parameters:
76 76 + `email` (required) - Email
77   -+ `name` (required) - Name
78 77 + `password` (required) - Password
79   -+ `password_confirmation` (required) - Password confirmation
  78 ++ `name` - Name
80 79 + `skype` - Skype ID
81 80 + `linkedin` - Linkedin
82 81 + `twitter` - Twitter account
83   -+ `projects_limit` - Limit projects wich user can create
84   -
  82 ++ `projects_limit` - Number of projects user can create
85 83  
86 84 Will return created user with status `201 Created` on success, or `404 Not
87 85 found` on fail.
... ...
lib/api/users.rb
... ... @@ -23,24 +23,23 @@ module Gitlab
23 23 @user = User.find(params[:id])
24 24 present @user, with: Entities::User
25 25 end
26   -
  26 +
27 27 # Create user. Available only for admin
28 28 #
29 29 # Parameters:
30 30 # email (required) - Email
31   - # name (required) - Name
32 31 # password (required) - Password
33   - # password_confirmation (required) - Password confirmation
  32 + # name - Name
34 33 # skype - Skype ID
35 34 # linkedin - Linkedin
36 35 # twitter - Twitter account
37   - # projects_limit - Limit projects wich user can create
  36 + # projects_limit - Number of projects user can create
38 37 # Example Request:
39 38 # POST /users
40 39 post do
41 40 authenticated_as_admin!
42   - attrs = attributes_for_keys [:email, :name, :password, :password_confirmation, :skype, :linkedin, :twitter, :projects_limit]
43   - user = User.new attrs
  41 + attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit]
  42 + user = User.new attrs, as: :admin
44 43 if user.save
45 44 present user, with: Entities::User
46 45 else
... ...
spec/requests/api/projects_spec.rb
... ... @@ -46,7 +46,7 @@ describe Gitlab::API do
46 46 response.status.should == 201
47 47 end
48 48  
49   - it "should repsond with 404 on failure" do
  49 + it "should respond with 404 on failure" do
50 50 post api("/projects", user)
51 51 response.status.should == 404
52 52 end
... ... @@ -188,16 +188,16 @@ describe Gitlab::API do
188 188 }.to change {project.hooks.count}.by(1)
189 189 end
190 190 end
191   -
  191 +
192 192 describe "PUT /projects/:id/hooks/:hook_id" do
193 193 it "should update an existing project hook" do
194 194 put api("/projects/#{project.code}/hooks/#{hook.id}", user),
195   - url: 'http://example.com'
  195 + url: 'http://example.org'
196 196 response.status.should == 200
197   - json_response['url'].should == 'http://example.com'
  197 + json_response['url'].should == 'http://example.org'
198 198 end
199 199 end
200   -
  200 +
201 201  
202 202 describe "DELETE /projects/:id/hooks" do
203 203 it "should delete hook from project" do
... ...
spec/requests/api/users_spec.rb
... ... @@ -4,7 +4,7 @@ describe Gitlab::API do
4 4 include ApiHelpers
5 5  
6 6 let(:user) { Factory :user }
7   - let(:admin) {Factory :admin}
  7 + let(:admin) { Factory :admin }
8 8 let(:key) { Factory :key, user: user }
9 9  
10 10 describe "GET /users" do
... ... @@ -42,9 +42,9 @@ describe Gitlab::API do
42 42 end
43 43  
44 44 it "should create user" do
45   - expect{
46   - post api("/users", admin), Factory.attributes(:user)
47   - }.to change{User.count}.by(1)
  45 + expect {
  46 + post api("/users", admin), Factory.attributes(:user, projects_limit: 3)
  47 + }.to change { User.count }.by(1)
48 48 end
49 49  
50 50 it "shouldn't available for non admin users" do
... ...