BigW Consortium Gitlab

repositories_controller_spec.rb 2.32 KB
Newer Older
1 2 3 4
require 'spec_helper'

describe Projects::Registry::RepositoriesController do
  let(:user)    { create(:user) }
5
  let(:project) { create(:project, :private) }
6 7 8

  before do
    sign_in(user)
9
    stub_container_registry_config(enabled: true)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  end

  context 'when user has access to registry' do
    before do
      project.add_developer(user)
    end

    describe 'GET index' do
      context 'when root container repository exists' do
        before do
          create(:container_repository, :root, project: project)
        end

        it 'does not create root container repository' do
          expect { go_to_index }.not_to change { ContainerRepository.all.count }
        end
      end

28
      context 'when root container repository is not created' do
29 30
        context 'when there are tags for this repository' do
          before do
31 32
            stub_container_registry_tags(repository: project.full_path,
                                         tags: %w[rc1 latest])
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
          end

          it 'successfully renders container repositories' do
            go_to_index

            expect(response).to have_http_status(:ok)
          end

          it 'creates a root container repository' do
            expect { go_to_index }.to change { ContainerRepository.all.count }.by(1)
            expect(ContainerRepository.first).to be_root_repository
          end
        end

        context 'when there are no tags for this repository' do
          before do
49
            stub_container_registry_tags(repository: :any, tags: [])
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
          end

          it 'successfully renders container repositories' do
            go_to_index

            expect(response).to have_http_status(:ok)
          end

          it 'does not ensure root container repository' do
            expect { go_to_index }.not_to change { ContainerRepository.all.count }
          end
        end
      end
    end
  end

  context 'when user does not have access to registry' do
    describe 'GET index' do
      it 'responds with 404' do
        go_to_index

        expect(response).to have_http_status(:not_found)
      end

      it 'does not ensure root container repository' do
        expect { go_to_index }.not_to change { ContainerRepository.all.count }
      end
    end
  end

  def go_to_index
    get :index, namespace_id: project.namespace,
                project_id: project
  end
end