Commit c4b4e78b authored by Arturo Herrero's avatar Arturo Herrero

Merge branch 'fj-fix-api-when-snippet-does-not-exist' into 'master'

Fix snippet repository storage move API when snippet does not exist

See merge request gitlab-org/gitlab!53211
parents f8b9cc2f 3640bd78
---
title: Fix snippet repository storage move API when snippet does not exist
merge_request: 53211
author:
type: fixed
...@@ -58,9 +58,14 @@ module API ...@@ -58,9 +58,14 @@ module API
resource :snippets do resource :snippets do
helpers do helpers do
def user_snippet def user_snippet
Snippet.find_by(id: params[:id]) # rubocop: disable CodeReuse/ActiveRecord @user_snippet ||= Snippet.find_by(id: params[:id]) # rubocop: disable CodeReuse/ActiveRecord
end end
end end
before do
not_found!('Snippet') unless user_snippet
end
desc 'Get a list of all snippets repository storage moves' do desc 'Get a list of all snippets repository storage moves' do
detail 'This feature was introduced in GitLab 13.8.' detail 'This feature was introduced in GitLab 13.8.'
success Entities::SnippetRepositoryStorageMove success Entities::SnippetRepositoryStorageMove
......
...@@ -85,14 +85,37 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type| ...@@ -85,14 +85,37 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type|
end end
describe "GET /#{container_type}/:id/repository_storage_moves" do describe "GET /#{container_type}/:id/repository_storage_moves" do
it_behaves_like 'get container repository storage move list' do let(:container_id) { container.id }
let(:url) { "/#{container_type}/#{container.id}/repository_storage_moves" } let(:url) { "/#{container_type}/#{container_id}/repository_storage_moves" }
it_behaves_like 'get container repository storage move list'
context 'non-existent container' do
let(:container_id) { non_existing_record_id }
it 'returns not found' do
get api(url, user)
expect(response).to have_gitlab_http_status(:not_found)
end
end end
end end
describe "GET /#{container_type}/:id/repository_storage_moves/:repository_storage_move_id" do describe "GET /#{container_type}/:id/repository_storage_moves/:repository_storage_move_id" do
it_behaves_like 'get single container repository storage move' do let(:container_id) { container.id }
let(:url) { "/#{container_type}/#{container.id}/repository_storage_moves/#{repository_storage_move_id}" } let(:url) { "/#{container_type}/#{container_id}/repository_storage_moves/#{repository_storage_move_id}" }
it_behaves_like 'get single container repository storage move'
context 'non-existent container' do
let(:container_id) { non_existing_record_id }
let(:repository_storage_move_id) { storage_move.id }
it 'returns not found' do
get api(url, user)
expect(response).to have_gitlab_http_status(:not_found)
end
end end
end end
...@@ -109,7 +132,8 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type| ...@@ -109,7 +132,8 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type|
end end
describe "POST /#{container_type}/:id/repository_storage_moves" do describe "POST /#{container_type}/:id/repository_storage_moves" do
let(:url) { "/#{container_type}/#{container.id}/repository_storage_moves" } let(:container_id) { container.id }
let(:url) { "/#{container_type}/#{container_id}/repository_storage_moves" }
let(:destination_storage_name) { 'test_second_storage' } let(:destination_storage_name) { 'test_second_storage' }
def create_container_repository_storage_move def create_container_repository_storage_move
...@@ -154,6 +178,16 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type| ...@@ -154,6 +178,16 @@ RSpec.shared_examples 'repository_storage_moves API' do |container_type|
expect(json_response['destination_storage_name']).to be_present expect(json_response['destination_storage_name']).to be_present
end end
end end
context 'when container does not exist' do
let(:container_id) { non_existing_record_id }
it 'returns not found' do
create_container_repository_storage_move
expect(response).to have_gitlab_http_status(:not_found)
end
end
end end
describe "POST /#{container_type.singularize}_repository_storage_moves" do describe "POST /#{container_type.singularize}_repository_storage_moves" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment