summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2017-06-27 17:35:35 -0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2017-06-28 15:50:29 -0300
commitda3e4f412846b754d31439da0d884181653bced0 (patch)
treee1c6da18204cf5c7990c350c5b9c01501ff60192 /spec
parent9f44687a14d57fec596b9736584bf8718df75a2e (diff)
downloadgitlab-ce-da3e4f412846b754d31439da0d884181653bced0.tar.gz
Add "members_count" and "parent_id" data on namespaces API
Diffstat (limited to 'spec')
-rw-r--r--spec/models/namespace_spec.rb19
-rw-r--r--spec/requests/api/namespaces_spec.rb16
2 files changed, 35 insertions, 0 deletions
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index e7c3acf19eb..d4f898f6d9f 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -323,6 +323,25 @@ describe Namespace, models: true do
end
end
+ describe '#users_with_descendants', :nested_groups do
+ let(:user_a) { create(:user) }
+ let(:user_b) { create(:user) }
+
+ let(:group) { create(:group) }
+ let(:nested_group) { create(:group, parent: group) }
+ let(:deep_nested_group) { create(:group, parent: nested_group) }
+
+ it 'returns member users on every nest level without duplication' do
+ group.add_developer(user_a)
+ nested_group.add_developer(user_b)
+ deep_nested_group.add_developer(user_a)
+
+ expect(group.users_with_descendants).to contain_exactly(user_a, user_b)
+ expect(nested_group.users_with_descendants).to contain_exactly(user_a, user_b)
+ expect(deep_nested_group.users_with_descendants).to contain_exactly(user_a)
+ end
+ end
+
describe '#user_ids_for_project_authorizations' do
it 'returns the user IDs for which to refresh authorizations' do
expect(namespace.user_ids_for_project_authorizations)
diff --git a/spec/requests/api/namespaces_spec.rb b/spec/requests/api/namespaces_spec.rb
index 3bf16a3ae27..03b1f549ce0 100644
--- a/spec/requests/api/namespaces_spec.rb
+++ b/spec/requests/api/namespaces_spec.rb
@@ -15,6 +15,14 @@ describe API::Namespaces do
end
context "when authenticated as admin" do
+ it "returns correct attributes" do
+ get api("/namespaces", admin)
+
+ expect(response).to have_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response.first).to include('id', 'name', 'path', 'full_path', 'parent_id', 'members_count')
+ end
+
it "admin: returns an array of all namespaces" do
get api("/namespaces", admin)
@@ -37,6 +45,14 @@ describe API::Namespaces do
end
context "when authenticated as a regular user" do
+ it "returns correct attributes" do
+ get api("/namespaces", user)
+
+ expect(response).to have_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response.first).to include('id', 'name', 'path', 'full_path', 'parent_id', 'members_count')
+ end
+
it "user: returns an array of namespaces" do
get api("/namespaces", user)