From 770ec3359d9c4bb3a53d7e44719cc4fa51b6b174 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 19 Oct 2012 03:09:34 -0700 Subject: [PATCH 1/6] fix ambiguous entry in changelog --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 69683756..c365a55b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,7 +4,7 @@ master - Fixed bug with gitolite keys - [API] list one project hook - [API] edit project hook - - [API] add project snippets list + - [API] list project snippets - [API] allow to authorize using private token in HTTP header - [API] add user creation From c61020632147e0855cf229bce81aa080ca1e5992 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 19 Oct 2012 03:23:10 -0700 Subject: [PATCH 2/6] fix mass-assignment error in user create API --- lib/api/users.rb | 4 ++-- spec/requests/api/users_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/api/users.rb b/lib/api/users.rb index 7f548aaa..108a3f12 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -23,7 +23,7 @@ module Gitlab @user = User.find(params[:id]) present @user, with: Entities::User end - + # Create user. Available only for admin # # Parameters: @@ -40,7 +40,7 @@ module Gitlab post do authenticated_as_admin! attrs = attributes_for_keys [:email, :name, :password, :password_confirmation, :skype, :linkedin, :twitter, :projects_limit] - user = User.new attrs + user = User.new attrs, as: :admin if user.save present user, with: Entities::User else diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index e3049e09..4c2e6ada 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -4,7 +4,7 @@ describe Gitlab::API do include ApiHelpers let(:user) { Factory :user } - let(:admin) {Factory :admin} + let(:admin) { Factory :admin } let(:key) { Factory :key, user: user } describe "GET /users" do @@ -42,9 +42,9 @@ describe Gitlab::API do end it "should create user" do - expect{ - post api("/users", admin), Factory.attributes(:user) - }.to change{User.count}.by(1) + expect { + post api("/users", admin), Factory.attributes(:user, projects_limit: 3) + }.to change { User.count }.by(1) end it "shouldn't available for non admin users" do From 2dc0f098fdfe1d07e557f7da92b3cff9d7351276 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 19 Oct 2012 03:25:39 -0700 Subject: [PATCH 3/6] fix typos in specs --- spec/requests/api/projects_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 51526f89..a6c270aa 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -46,7 +46,7 @@ describe Gitlab::API do response.status.should == 201 end - it "should repsond with 404 on failure" do + it "should respond with 404 on failure" do post api("/projects", user) response.status.should == 404 end @@ -188,7 +188,7 @@ describe Gitlab::API do }.to change {project.hooks.count}.by(1) end end - + describe "PUT /projects/:id/hooks/:hook_id" do it "should update an existing project hook" do put api("/projects/#{project.code}/hooks/#{hook.id}", user), @@ -197,7 +197,7 @@ describe Gitlab::API do json_response['url'].should == 'http://example.com' end end - + describe "DELETE /projects/:id/hooks" do it "should delete hook from project" do @@ -239,7 +239,7 @@ describe Gitlab::API do end describe "GET /projects/:id/snippets" do - it "should return a project snippet" do + it "should return an array of project snippets" do get api("/projects/#{project.code}/snippets", user) response.status.should == 200 json_response.should be_an Array From 0369c74e581ed7f3c2e6576be3f1afcd20b54022 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 19 Oct 2012 03:28:26 -0700 Subject: [PATCH 4/6] fix wrong test case --- spec/requests/api/projects_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index a6c270aa..5f9a587d 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -192,9 +192,9 @@ describe Gitlab::API do describe "PUT /projects/:id/hooks/:hook_id" do it "should update an existing project hook" do put api("/projects/#{project.code}/hooks/#{hook.id}", user), - url: 'http://example.com' + url: 'http://example.org' response.status.should == 200 - json_response['url'].should == 'http://example.com' + json_response['url'].should == 'http://example.org' end end From 00325a733a76d8388a64e4a38c8f4e70f2a49938 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 19 Oct 2012 03:34:18 -0700 Subject: [PATCH 5/6] name and password_confirmation not required to create a user via API --- lib/api/users.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/api/users.rb b/lib/api/users.rb index 108a3f12..57e0aa10 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -28,18 +28,17 @@ module Gitlab # # Parameters: # email (required) - Email - # name (required) - Name # password (required) - Password - # password_confirmation (required) - Password confirmation + # name - Name # skype - Skype ID # linkedin - Linkedin # twitter - Twitter account - # projects_limit - Limit projects wich user can create + # projects_limit - Number of projects user can create # Example Request: # POST /users post do authenticated_as_admin! - attrs = attributes_for_keys [:email, :name, :password, :password_confirmation, :skype, :linkedin, :twitter, :projects_limit] + attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit] user = User.new attrs, as: :admin if user.save present user, with: Entities::User From cf70439e0a61637a8ad12360c53df08320b937b9 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Fri, 19 Oct 2012 03:39:02 -0700 Subject: [PATCH 6/6] update API docs --- doc/api/users.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/api/users.md b/doc/api/users.md index 63271ee8..c116144d 100644 --- a/doc/api/users.md +++ b/doc/api/users.md @@ -74,14 +74,12 @@ POST /users Parameters: + `email` (required) - Email -+ `name` (required) - Name + `password` (required) - Password -+ `password_confirmation` (required) - Password confirmation ++ `name` - Name + `skype` - Skype ID + `linkedin` - Linkedin + `twitter` - Twitter account -+ `projects_limit` - Limit projects wich user can create - ++ `projects_limit` - Number of projects user can create Will return created user with status `201 Created` on success, or `404 Not found` on fail.