Add SnippetRepositoryStorageMove entity

In this commit we create the entity that will be used later
on in a follow-up by some new API REST endpoints.
parent 1643cf25
# frozen_string_literal: true
module API
module Entities
class BasicRepositoryStorageMove < Grape::Entity
expose :id
expose :created_at
expose :human_state_name, as: :state
expose :source_storage_name
expose :destination_storage_name
end
end
end
# frozen_string_literal: true
module API
module Entities
class BasicSnippet < Grape::Entity
expose :id, :title, :description, :visibility
expose :updated_at, :created_at
expose :project_id
expose :web_url do |snippet|
Gitlab::UrlBuilder.build(snippet)
end
expose :raw_url do |snippet|
Gitlab::UrlBuilder.build(snippet, raw: true)
end
expose :ssh_url_to_repo, :http_url_to_repo, if: ->(snippet) { snippet.repository_exists? }
end
end
end
......@@ -2,12 +2,7 @@
module API
module Entities
class ProjectRepositoryStorageMove < Grape::Entity
expose :id
expose :created_at
expose :human_state_name, as: :state
expose :source_storage_name
expose :destination_storage_name
class ProjectRepositoryStorageMove < BasicRepositoryStorageMove
expose :project, using: Entities::ProjectIdentity
end
end
......
......@@ -2,18 +2,8 @@
module API
module Entities
class Snippet < Grape::Entity
expose :id, :title, :description, :visibility
class Snippet < BasicSnippet
expose :author, using: Entities::UserBasic
expose :updated_at, :created_at
expose :project_id
expose :web_url do |snippet|
Gitlab::UrlBuilder.build(snippet)
end
expose :raw_url do |snippet|
Gitlab::UrlBuilder.build(snippet, raw: true)
end
expose :ssh_url_to_repo, :http_url_to_repo, if: ->(snippet) { snippet.repository_exists? }
expose :file_name do |snippet|
snippet.file_name_on_repo || snippet.file_name
end
......
# frozen_string_literal: true
module API
module Entities
class SnippetRepositoryStorageMove < BasicRepositoryStorageMove
expose :snippet, using: Entities::BasicSnippet
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Entities::SnippetRepositoryStorageMove do
describe '#as_json' do
subject { entity.as_json }
let(:default_storage) { 'default' }
let(:second_storage) { 'test_second_storage' }
let(:storage_move) { create(:snippet_repository_storage_move, :scheduled, destination_storage_name: second_storage) }
let(:entity) { described_class.new(storage_move) }
it 'includes basic fields' do
allow(Gitlab.config.repositories.storages).to receive(:keys).and_return(%W[#{default_storage} #{second_storage}])
is_expected.to include(
state: 'scheduled',
source_storage_name: default_storage,
destination_storage_name: second_storage,
snippet: a_kind_of(Hash)
)
end
end
end
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