2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-02 16:53:14 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe ContainerRepositoryEntity do
|
2020-02-24 22:08:49 -05:00
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:repository) { create(:container_repository, project: project) }
|
|
|
|
let(:entity) { described_class.new(repository, request: request) }
|
2017-10-02 16:53:14 -04:00
|
|
|
let(:request) { double('request') }
|
|
|
|
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: true)
|
2020-05-25 17:08:00 -04:00
|
|
|
stub_container_registry_tags(repository: :any,
|
|
|
|
tags: %w[stable latest])
|
2017-10-02 16:53:14 -04:00
|
|
|
allow(request).to receive(:project).and_return(project)
|
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
2019-01-16 07:09:29 -05:00
|
|
|
it 'exposes required informations' do
|
2020-05-25 17:08:00 -04:00
|
|
|
expect(subject).to include(:id, :path, :location, :tags_path, :tags_count)
|
2017-10-02 16:53:14 -04:00
|
|
|
end
|
|
|
|
|
2019-10-17 08:07:33 -04:00
|
|
|
context 'when project is not preset in the request' do
|
|
|
|
before do
|
|
|
|
allow(request).to receive(:respond_to?).and_return(false)
|
|
|
|
allow(request).to receive(:project).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses project from the object' do
|
|
|
|
expect(request.project).not_to equal(project)
|
|
|
|
expect(subject).to include(:tags_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-02 16:53:14 -04:00
|
|
|
context 'when user can manage repositories' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes destroy_path' do
|
|
|
|
expect(subject).to include(:destroy_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot manage repositories' do
|
|
|
|
it 'does not expose destroy_path' do
|
|
|
|
expect(subject).not_to include(:destroy_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|