diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-04 18:59:17 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-06-04 18:59:17 +0300 |
commit | b9219469f759f387a35bec39c3dc59477793ef1b (patch) | |
tree | c6f97d7545fd6d44d041b3192974e325dee01854 /spec/requests | |
parent | 1d945945bb66871dcebefef5824740c823fd7b09 (diff) | |
parent | 67992b9be6fc19ef4cc06de48995d1ee9617049a (diff) |
Merge branch 'make-namespaces-api-available-to-all-users' into 'master'
Make namespace API available to all users
### What does this MR do?
This MR makes it possible for a user to query namespaces to which he/she has access. Also, it adds documentation for the existing API.
### Why was this MR needed?
Even though the `groups` API exists, it might still be useful to have an endpoint that tells the namespace type (e.g. `user` vs. `group`), especially if a user has access to a number of different projects.
### What are the relevant issue numbers?
Closes https://github.com/gitlabhq/gitlabhq/issues/9328
See merge request !708
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/namespaces_spec.rb | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/spec/requests/api/namespaces_spec.rb b/spec/requests/api/namespaces_spec.rb index 6ddaaa0a6dd..21787fdd895 100644 --- a/spec/requests/api/namespaces_spec.rb +++ b/spec/requests/api/namespaces_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe API::API, api: true do include ApiHelpers let(:admin) { create(:admin) } + let(:user) { create(:user) } let!(:group1) { create(:group) } let!(:group2) { create(:group) } @@ -14,7 +15,7 @@ describe API::API, api: true do end end - context "when authenticated as admin" do + context "when authenticated as admin" do it "admin: should return an array of all namespaces" do get api("/namespaces", admin) expect(response.status).to eq(200) @@ -22,6 +23,32 @@ describe API::API, api: true do expect(json_response.length).to eq(Namespace.count) end + + it "admin: should return an array of matched namespaces" do + get api("/namespaces?search=#{group1.name}", admin) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + + expect(json_response.length).to eq(1) + end + end + + context "when authenticated as a regular user" do + it "user: should return an array of namespaces" do + get api("/namespaces", user) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + + expect(json_response.length).to eq(1) + end + + it "admin: should return an array of matched namespaces" do + get api("/namespaces?search=#{user.username}", user) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + + expect(json_response.length).to eq(1) + end end end end |