Skip to content

Commit

Permalink
add ability to create a user
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed Oct 19, 2012
1 parent c44ec7d commit 89541c1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/gitlab/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ def user(id=nil)
id.to_i.zero? ? get("/user") : get("/users/#{id}")
end

# Creates a new user.
# Requires authentication from an admin account.
#
# @param [String] email The email of a user.
# @param [String] password The password of a user.
# @param [Hash] options A customizable set of options.
# @option options [String] :name The name of a user. Defaults to email.
# @option options [String] :skype The skype of a user.
# @option options [String] :linkedin The linkedin of a user.
# @option options [String] :twitter The twitter of a user.
# @option options [Integer] :projects_limit The limit of projects for a user.
# @return [Gitlab::ObjectifiedHash] Information about created user.
def create_user(email, password, options={})
body = {:email => email, :password => password, :name => email}.merge(options)
post("/users", :body => body)
end

# Creates a new user session.
#
# @example
Expand Down
20 changes: 18 additions & 2 deletions spec/gitlab/client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@
end
end

describe ".create_user" do
before do
stub_post("/users", "user")
@user = Gitlab.create_user("email", "pass")
end

it "should get the correct resource" do
body = {:email => "email", :password => "pass", :name => "email"}
a_post("/users").with(:body => body).should have_been_made
end

it "should return information about a created user" do
@user.email.should == "john@example.com"
end
end

describe ".session" do
before do
stub_post("/session", "session")
Expand Down Expand Up @@ -99,11 +115,11 @@
describe ".create_ssh_key" do
before do
stub_post("/user/keys", "key")
@key = Gitlab.create_ssh_key('title', 'body')
@key = Gitlab.create_ssh_key("title", "body")
end

it "should get the correct resource" do
body = {:title => 'title', :key => 'body'}
body = {:title => "title", :key => "body"}
a_post("/user/keys").with(:body => body).should have_been_made
end

Expand Down

0 comments on commit 89541c1

Please sign in to comment.