diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-20 00:08:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-20 00:08:32 +0300 |
commit | 60082b335c09b27ebee3452a36cc62eb76df3480 (patch) | |
tree | 8a34e789590856679bca7955cda7fda06e257590 /spec/requests | |
parent | ce493944f48fb2ad08a5381a7ed1f37ced637bd1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/projects_spec.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index bdbaa178caa..6f0fe181991 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -584,6 +584,85 @@ describe API::Projects do end end + context 'sorting by project statistics' do + %w(repository_size storage_size wiki_size).each do |order_by| + context "sorting by #{order_by}" do + before do + ProjectStatistics.update_all(order_by => 100) + project4.statistics.update_columns(order_by => 10) + project.statistics.update_columns(order_by => 200) + end + + context 'admin user' do + let(:current_user) { admin } + + context "when sorting by #{order_by} ascendingly" do + it 'returns a properly sorted list of projects' do + get api('/projects', current_user), params: { order_by: order_by, sort: :asc } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['id']).to eq(project4.id) + end + end + + context "when sorting by #{order_by} descendingly" do + it 'returns a properly sorted list of projects' do + get api('/projects', current_user), params: { order_by: order_by, sort: :desc } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['id']).to eq(project.id) + end + end + end + + context 'non-admin user' do + let(:current_user) { user } + let(:projects) { [public_project, project, project2, project3] } + + it 'returns projects ordered normally' do + get api('/projects', current_user), params: { order_by: order_by } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.map { |project| project['id'] }).to eq(projects.map(&:id).reverse) + end + end + end + end + end + + context 'filtering by repository_storage' do + before do + [project, project3].each { |proj| proj.update_columns(repository_storage: 'nfs-11') } + # Since we don't actually have Gitaly configured with an nfs-11 storage, an error would be raised + # when we present the projects in a response, as we ask Gitaly for stuff like default branch and Gitaly + # is not configured for a nfs-11 storage. So we trick Rails into thinking the storage for these projects + # is still default (in reality, it is). + allow_any_instance_of(Project).to receive(:repository_storage).and_return('default') + end + + context 'admin user' do + it_behaves_like 'projects response' do + let(:filter) { { repository_storage: 'nfs-11' } } + let(:current_user) { admin } + let(:projects) { [project, project3] } + end + end + + context 'non-admin user' do + it_behaves_like 'projects response' do + let(:filter) { { repository_storage: 'nfs-11' } } + let(:current_user) { user } + let(:projects) { [public_project, project, project2, project3] } + end + end + end + context 'with keyset pagination' do let(:current_user) { user } let(:projects) { [public_project, project, project2, project3] } |