Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/gitlab/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def delete_email(id, user_id = nil)
delete(url)
end

# Search for groups by name
# Search for users by name
#
# @example
# Gitlab.user_search('gitlab')
Expand All @@ -313,6 +313,19 @@ def user_search(search, options = {})
get('/users', query: options)
end

# Get user by username
#
# @example
# Gitlab.user_by_username('gitlab')
#
# @param [String] username A username to get.
# @param [Hash] options A customizable set of options.
# @return [Array<Gitlab::ObjectifiedHash>]
def user_by_username(username, options = {})
options[:username] = username
get('/users', query: options)
end

# Gets user custom_attributes.
#
# @example
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/empty_array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions spec/fixtures/user_by_username.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":1,"email":"[email protected]","name":"John Smith","username":"john.smith","bio":null,"skype":"","linkedin":"","twitter":"john","dark_scheme":false,"theme_id":1,"blocked":false,"created_at":"2012-09-17T09:41:56Z"}]
28 changes: 28 additions & 0 deletions spec/gitlab/client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,34 @@
end
end

describe '.user_by_username' do
context 'with a valid username' do
before do
stub_get('/users?username=User', 'user_by_username')
@user = Gitlab.user_by_username('User')
end

it 'gets the correct resource' do
expect(a_get('/users?username=User')).to have_been_made
end

it 'returns information about a user' do
expect(@user.first.email).to eq('[email protected]')
end
end

context 'with an invalid username' do
before do
stub_get('/users?username=InvalidUser', 'empty_array')
@user = Gitlab.user_by_username('InvalidUser')
end

it 'returns an empty array' do
expect(@user).to eq([])
end
end
end

describe '.user_custom_attributes' do
before do
stub_get('/users/2/custom_attributes', 'user_custom_attributes')
Expand Down