Skip to content

Commit

Permalink
Add group_search method.
Browse files Browse the repository at this point in the history
  • Loading branch information
asedge committed May 28, 2015
1 parent 1d3d27e commit ac595af
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/gitlab/client/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,21 @@ def transfer_project_to_group(id, project_id)
body = {:id => id, :project_id => project_id}
post("/groups/#{id}/projects/#{project_id}", :body => body)
end

# Search for groups by name
#
# @example
# Gitlab.group_search('gitlab')
#
# @param [String] search A string to search for in group names and paths.
# @param [Hash] options A customizable set of options.
# @option options [String] :per_page Number of projects to return per page
# @option options [String] :page The page to retrieve
# @return [Array<Gitlab::ObjectifiedHash>]
def group_search(search, options={})
options[:search] = search
get("/groups", :query => options)
end

end
end
2 changes: 2 additions & 0 deletions spec/fixtures/group_search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[{"id": 5,"name": "Five-Group","path": "five-group","owner_id": 2},{"id": 8,"name": "Eight Group","path": "eight-group","owner_id": 6}
]
17 changes: 17 additions & 0 deletions spec/gitlab/client/groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,21 @@
end


describe ".group_search" do
before do
stub_get("/groups?search=Group", "group_search")
@groups = Gitlab.group_search('Group')
end

it "should get the correct resource" do
expect(a_get("/groups?search=Group")).to have_been_made
end

it "should return an array of groups found" do
expect(@groups.first.id).to eq(5)
expect(@groups.last.id).to eq(8)
end
end


end
2 changes: 1 addition & 1 deletion spec/gitlab/shell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
it "should return an Array of matching commands" do
completed_cmds = @comp.call 'group'
expect(completed_cmds).to be_a Array
expect(completed_cmds.sort).to eq(['group', 'group_members', 'groups'])
expect(completed_cmds.sort).to eq(['group', 'group_members', 'group_search', 'groups'])
end
end
end
Expand Down

0 comments on commit ac595af

Please sign in to comment.