diff options
author | Sean McGivern <sean@gitlab.com> | 2016-11-17 15:41:48 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-11-17 21:37:52 +0300 |
commit | 79122896318ae50c835418888f7f781fa2e463f4 (patch) | |
tree | f429b92c3c4747d321d6c1cad0d7573c696f726e /spec | |
parent | 50585cddb53c8cc28135a8c7a11f2d1cf02b9593 (diff) |
Allow sorting groups in API
Allow `order_by` and `sort` parameters to `/api/v3/groups.json`. At
present, only ordering by name and path is supported, and the default
sort is name ascending (alphabetical order).
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/groups_spec.rb | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index d79b204a24e..d9fdafde05e 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -57,13 +57,48 @@ describe API::API, api: true do end context "when using all_available in request" do + let(:response_groups) { json_response.map { |group| group['name'] } } + it "returns all groups you have access to" do public_group = create :group, :public get api("/groups", user1), all_available: true expect(response).to have_http_status(200) expect(json_response).to be_an Array - expect(json_response.first['name']).to eq(public_group.name) + expect(response_groups).to contain_exactly(public_group.name, group1.name) + end + end + + context "when using sorting" do + let(:group3) { create(:group, name: "a#{group1.name}", path: "z#{group1.path}") } + let(:response_groups) { json_response.map { |group| group['name'] } } + + before do + group3.add_owner(user1) + end + + it "sorts by name ascending by default" do + get api("/groups", user1) + + expect(response).to have_http_status(200) + expect(json_response).to be_an Array + expect(response_groups).to eq([group3.name, group1.name]) + end + + it "sorts in descending order when passed" do + get api("/groups", user1), sort: "desc" + + expect(response).to have_http_status(200) + expect(json_response).to be_an Array + expect(response_groups).to eq([group1.name, group3.name]) + end + + it "sorts by the order_by param" do + get api("/groups", user1), order_by: "path" + + expect(response).to have_http_status(200) + expect(json_response).to be_an Array + expect(response_groups).to eq([group1.name, group3.name]) end end end |