Commit 55779d4b authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Bob Van Landuyt

Enable sub-groups repositories in parent group

- use finder instead of direct access
- update tests
Co-authored-by: default avatarSteve Abrams <sabrams@gitlab.com>
parent 1cba8539
...@@ -9,7 +9,7 @@ module Groups ...@@ -9,7 +9,7 @@ module Groups
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
@images = group.container_repositories.with_api_entity_associations @images = ContainerRepositoriesFinder.new(user: current_user, subject: group).execute.with_api_entity_associations
track_event(:list_repositories) track_event(:list_repositories)
......
---
title: Group level container registry show subgroups repos
merge_request: 29263
author:
type: fixed
...@@ -7,6 +7,13 @@ describe Groups::Registry::RepositoriesController do ...@@ -7,6 +7,13 @@ describe Groups::Registry::RepositoriesController do
let_it_be(:guest) { create(:user) } let_it_be(:guest) { create(:user) }
let_it_be(:group, reload: true) { create(:group) } let_it_be(:group, reload: true) { create(:group) }
subject do
get :index, params: {
group_id: group,
format: format
}
end
before do before do
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
group.add_owner(user) group.add_owner(user)
...@@ -15,51 +22,67 @@ describe Groups::Registry::RepositoriesController do ...@@ -15,51 +22,67 @@ describe Groups::Registry::RepositoriesController do
end end
shared_examples 'renders a list of repositories' do shared_examples 'renders a list of repositories' do
let_it_be(:repo) { create_project_with_repo(test_group) }
it 'returns a list of projects for json format' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_kind_of(Array)
expect(json_response.first).to include(
'id' => repo.id,
'name' => repo.name
)
end
end
shared_examples 'renders correctly' do
context 'when user has access to registry' do context 'when user has access to registry' do
it 'show index page' do let_it_be(:test_group) { group }
expect(Gitlab::Tracking).not_to receive(:event)
get :index, params: { context 'html format' do
group_id: group let(:format) { :html }
}
expect(response).to have_gitlab_http_status(:ok) it 'show index page' do
end expect(Gitlab::Tracking).not_to receive(:event)
it 'has the correct response schema' do subject
get :index, params: {
group_id: group,
format: :json
}
expect(response).to match_response_schema('registry/repositories') expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers end
end end
it 'returns a list of projects for json format' do context 'json format' do
project = create(:project, group: group) let(:format) { :json }
repo = create(:container_repository, project: project)
it 'has the correct response schema' do
get :index, params: { subject
group_id: group,
format: :json expect(response).to match_response_schema('registry/repositories')
} expect(response).to include_pagination_headers
end
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_kind_of(Array)
expect(json_response.first).to include(
'id' => repo.id,
'name' => repo.name
)
end
it 'tracks the event' do it_behaves_like 'renders a list of repositories'
expect(Gitlab::Tracking).to receive(:event).with(anything, 'list_repositories', {})
get :index, params: { it_behaves_like 'a gitlab tracking event', described_class.name, 'list_repositories'
group_id: group,
format: :json context 'with project in subgroup' do
} let_it_be(:test_group) { create(:group, parent: group ) }
it_behaves_like 'renders a list of repositories'
context 'with project in subgroup and group' do
let_it_be(:repo_in_test_group) { create_project_with_repo(test_group) }
let_it_be(:repo_in_group) { create_project_with_repo(group) }
it 'returns all the projects' do
subject
expect(json_response).to be_kind_of(Array)
expect(json_response.length).to eq 2
end
end
end
end end
end end
...@@ -69,20 +92,30 @@ describe Groups::Registry::RepositoriesController do ...@@ -69,20 +92,30 @@ describe Groups::Registry::RepositoriesController do
sign_in(guest) sign_in(guest)
end end
it 'renders not found' do context 'json format' do
get :index, params: { let(:format) { :json }
group_id: group
} it_behaves_like 'returning response status', :not_found
expect(response).to have_gitlab_http_status(:not_found) end
context 'html format' do
let(:format) { :html }
it_behaves_like 'returning response status', :not_found
end end
end end
end end
context 'GET #index' do context 'GET #index' do
it_behaves_like 'renders a list of repositories' it_behaves_like 'renders correctly'
end end
context 'GET #show' do context 'GET #show' do
it_behaves_like 'renders a list of repositories' it_behaves_like 'renders correctly'
end
def create_project_with_repo(group)
project = create(:project, group: test_group)
create(:container_repository, project: project)
end 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