debian-mirror-gitlab/spec/serializers/container_repository_entity_spec.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
describe ContainerRepositoryEntity do
let(:entity) do
described_class.new(repository, request: request)
end
set(:project) { create(:project) }
set(:user) { create(:user) }
set(:repository) { create(:container_repository, project: project) }
let(:request) { double('request') }
subject { entity.as_json }
before do
stub_container_registry_config(enabled: true)
allow(request).to receive(:project).and_return(project)
allow(request).to receive(:current_user).and_return(user)
end
2019-03-02 22:35:43 +05:30
it 'exposes required informations' do
2018-03-17 18:26:18 +05:30
expect(subject).to include(:id, :path, :location, :tags_path)
end
2019-12-21 20:55:43 +05:30
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
2018-03-17 18:26:18 +05:30
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