summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-07 18:07:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-07 18:07:50 +0000
commitec169c6384b44291551eb7998b4f7f1102a8af07 (patch)
treedb35206559e536f354e53d71365054062f43b7fc /spec
parentf3597fc9f048f07e717ac4cb743a083b219f6258 (diff)
downloadgitlab-ce-ec169c6384b44291551eb7998b4f7f1102a8af07.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/finders/group_projects_finder_spec.rb16
-rw-r--r--spec/models/project_spec.rb8
-rw-r--r--spec/requests/api/groups_spec.rb45
3 files changed, 69 insertions, 0 deletions
diff --git a/spec/finders/group_projects_finder_spec.rb b/spec/finders/group_projects_finder_spec.rb
index b291b5d4b90..0a7ca5211e1 100644
--- a/spec/finders/group_projects_finder_spec.rb
+++ b/spec/finders/group_projects_finder_spec.rb
@@ -168,4 +168,20 @@ describe GroupProjectsFinder do
end
end
end
+
+ describe 'limiting' do
+ context 'without limiting' do
+ it 'returns all projects' do
+ expect(subject.count).to eq(3)
+ end
+ end
+
+ context 'with limiting' do
+ let(:options) { { limit: 1 } }
+
+ it 'returns only the number of projects specified by the limit' do
+ expect(subject.count).to eq(1)
+ end
+ end
+ end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 37604a557ea..d06e87451bd 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -1349,6 +1349,14 @@ describe Project do
end
end
+ describe '.with_limit' do
+ it 'limits the number of projects returned' do
+ create_list(:project, 3)
+
+ expect(described_class.with_limit(1).count).to eq(1)
+ end
+ end
+
describe '.visible_to_user' do
let!(:project) { create(:project, :private) }
let!(:user) { create(:user) }
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index cb97398805a..c7b35d6f50d 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -488,6 +488,51 @@ describe API::Groups do
expect(response).to have_gitlab_http_status(404)
end
end
+
+ context 'limiting the number of projects and shared_projects in the response' do
+ let(:limit) { 1 }
+
+ before do
+ stub_const("GroupProjectsFinder::DEFAULT_PROJECTS_LIMIT", limit)
+
+ # creates 3 public projects
+ create_list(:project, 3, :public, namespace: group1)
+
+ # creates 3 shared projects
+ public_group = create(:group, :public)
+ projects_to_be_shared = create_list(:project, 3, :public, namespace: public_group)
+
+ projects_to_be_shared.each do |project|
+ create(:project_group_link, project: project, group: group1)
+ end
+ end
+
+ context 'when limiting feature is enabled' do
+ before do
+ stub_feature_flags(limit_projects_in_groups_api: true)
+ end
+
+ it 'limits projects and shared_projects' do
+ get api("/groups/#{group1.id}")
+
+ expect(json_response['projects'].count).to eq(limit)
+ expect(json_response['shared_projects'].count).to eq(limit)
+ end
+ end
+
+ context 'when limiting feature is not enabled' do
+ before do
+ stub_feature_flags(limit_projects_in_groups_api: false)
+ end
+
+ it 'does not limit projects and shared_projects' do
+ get api("/groups/#{group1.id}")
+
+ expect(json_response['projects'].count).to eq(3)
+ expect(json_response['shared_projects'].count).to eq(3)
+ end
+ end
+ end
end
describe 'PUT /groups/:id' do