diff options
Diffstat (limited to 'spec/requests/api/projects_spec.rb')
-rw-r--r-- | spec/requests/api/projects_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 2f1760a570e..59c394d8d8d 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1751,6 +1751,27 @@ describe API::Projects do subject { get api("/projects/#{project.id}", user) } end + + describe 'repository_storage attribute' do + before do + get api("/projects/#{project.id}", user) + end + + context 'when authenticated as an admin' do + let(:user) { create(:admin) } + + it 'returns repository_storage attribute' do + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['repository_storage']).to eq(project.repository_storage) + end + end + + context 'when authenticated as a regular user' do + it 'does not return repository_storage attribute' do + expect(json_response).not_to have_key('repository_storage') + end + end + end end describe 'GET /projects/:id/users' do @@ -2402,6 +2423,50 @@ describe API::Projects do expect(response).to have_gitlab_http_status(:forbidden) end end + + context 'when updating repository storage' do + let(:unknown_storage) { 'new-storage' } + let(:new_project) { create(:project, :repository, namespace: user.namespace) } + + context 'as a user' do + it 'returns 200 but does not change repository_storage' do + expect do + Sidekiq::Testing.fake! do + put(api("/projects/#{new_project.id}", user), params: { repository_storage: unknown_storage, issues_enabled: false }) + end + end.not_to change(ProjectUpdateRepositoryStorageWorker.jobs, :size) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['issues_enabled']).to eq(false) + expect(new_project.reload.repository.storage).to eq('default') + end + end + + context 'as an admin' do + include_context 'custom session' + + let(:admin) { create(:admin) } + + it 'returns 500 when repository storage is unknown' do + put(api("/projects/#{new_project.id}", admin), params: { repository_storage: unknown_storage }) + + expect(response).to have_gitlab_http_status(:internal_server_error) + expect(json_response['message']).to match('ArgumentError') + end + + it 'returns 200 when repository storage has changed' do + stub_storage_settings('test_second_storage' => { 'path' => 'tmp/tests/second_storage' }) + + expect do + Sidekiq::Testing.fake! do + put(api("/projects/#{new_project.id}", admin), params: { repository_storage: 'test_second_storage' }) + end + end.to change(ProjectUpdateRepositoryStorageWorker.jobs, :size).by(1) + + expect(response).to have_gitlab_http_status(:ok) + end + end + end end describe 'POST /projects/:id/archive' do |