diff options
Diffstat (limited to 'spec/controllers/groups')
6 files changed, 96 insertions, 76 deletions
diff --git a/spec/controllers/groups/children_controller_spec.rb b/spec/controllers/groups/children_controller_spec.rb index 04cf7785f1e..f05551432fa 100644 --- a/spec/controllers/groups/children_controller_spec.rb +++ b/spec/controllers/groups/children_controller_spec.rb @@ -277,7 +277,7 @@ RSpec.describe Groups::ChildrenController do context 'with only projects' do let!(:other_project) { create(:project, :public, namespace: group) } - let!(:first_page_projects) { create_list(:project, per_page, :public, namespace: group ) } + let!(:first_page_projects) { create_list(:project, per_page, :public, namespace: group) } it 'has projects on the first page' do get :index, params: { group_id: group.to_param, sort: 'id_desc' }, format: :json diff --git a/spec/controllers/groups/group_members_controller_spec.rb b/spec/controllers/groups/group_members_controller_spec.rb index a3659ae9163..4e5dc01f466 100644 --- a/spec/controllers/groups/group_members_controller_spec.rb +++ b/spec/controllers/groups/group_members_controller_spec.rb @@ -342,6 +342,41 @@ RSpec.describe Groups::GroupMembersController do end end + context 'with owners from a parent' do + context 'when top-level group' do + context 'with group sharing' do + let!(:subgroup) { create(:group, parent: group) } + + before do + create(:group_group_link, :owner, shared_group: group, shared_with_group: subgroup) + create(:group_member, :owner, group: subgroup) + end + + it 'does not allow removal of last direct group owner' do + delete :leave, params: { group_id: group } + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + end + + context 'when subgroup' do + let!(:subgroup) { create(:group, parent: group) } + + before do + subgroup.add_owner(user) + end + + it 'allows removal of last direct group owner', :aggregate_failures do + delete :leave, params: { group_id: subgroup } + + expect(controller).to set_flash.to "You left the \"#{subgroup.human_name}\" group." + expect(response).to redirect_to(dashboard_groups_path) + expect(subgroup.users).not_to include user + end + end + end + context 'and there is another owner' do before do create(:group_member, :owner, source: group) diff --git a/spec/controllers/groups/registry/repositories_controller_spec.rb b/spec/controllers/groups/registry/repositories_controller_spec.rb index 9ac19b06718..62c15201a95 100644 --- a/spec/controllers/groups/registry/repositories_controller_spec.rb +++ b/spec/controllers/groups/registry/repositories_controller_spec.rb @@ -117,7 +117,7 @@ RSpec.describe Groups::Registry::RepositoriesController do it_behaves_like 'a package tracking event', described_class.name, 'list_repositories' context 'with project in subgroup' do - let_it_be(:test_group) { create(:group, parent: group ) } + let_it_be(:test_group) { create(:group, parent: group) } it_behaves_like 'renders a list of repositories' diff --git a/spec/controllers/groups/releases_controller_spec.rb b/spec/controllers/groups/releases_controller_spec.rb index 7dd0bc6206a..40e8cb4efc5 100644 --- a/spec/controllers/groups/releases_controller_spec.rb +++ b/spec/controllers/groups/releases_controller_spec.rb @@ -42,7 +42,7 @@ RSpec.describe Groups::ReleasesController do end it 'does not return any releases' do - expect(json_response.map { |r| r['tag'] } ).to be_empty + expect(json_response.map { |r| r['tag'] }).to be_empty end it 'returns OK' do @@ -56,7 +56,7 @@ RSpec.describe Groups::ReleasesController do index - expect(json_response.map { |r| r['tag'] } ).to match_array(%w(p2 p1 v2 v1)) + expect(json_response.map { |r| r['tag'] }).to match_array(%w(p2 p1 v2 v1)) end end diff --git a/spec/controllers/groups/runners_controller_spec.rb b/spec/controllers/groups/runners_controller_spec.rb index 6dbf0803892..2add3cd3b18 100644 --- a/spec/controllers/groups/runners_controller_spec.rb +++ b/spec/controllers/groups/runners_controller_spec.rb @@ -168,7 +168,7 @@ RSpec.describe Groups::RunnersController do new_desc = runner.description.swapcase expect do - post :update, params: params.merge(runner: { description: new_desc } ) + post :update, params: params.merge(runner: { description: new_desc }) end.to change { runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:found) @@ -179,7 +179,7 @@ RSpec.describe Groups::RunnersController do new_desc = instance_runner.description.swapcase expect do - post :update, params: params_runner_instance.merge(runner: { description: new_desc } ) + post :update, params: params_runner_instance.merge(runner: { description: new_desc }) end.to not_change { instance_runner.ensure_runner_queue_value } .and not_change { instance_runner.description } @@ -190,7 +190,7 @@ RSpec.describe Groups::RunnersController do new_desc = project_runner.description.swapcase expect do - post :update, params: params_runner_project.merge(runner: { description: new_desc } ) + post :update, params: params_runner_project.merge(runner: { description: new_desc }) end.to change { project_runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:found) @@ -207,7 +207,7 @@ RSpec.describe Groups::RunnersController do old_desc = runner.description expect do - post :update, params: params.merge(runner: { description: old_desc.swapcase } ) + post :update, params: params.merge(runner: { description: old_desc.swapcase }) end.not_to change { runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:not_found) @@ -218,7 +218,7 @@ RSpec.describe Groups::RunnersController do old_desc = instance_runner.description expect do - post :update, params: params_runner_instance.merge(runner: { description: old_desc.swapcase } ) + post :update, params: params_runner_instance.merge(runner: { description: old_desc.swapcase }) end.not_to change { instance_runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:not_found) @@ -229,7 +229,7 @@ RSpec.describe Groups::RunnersController do old_desc = project_runner.description expect do - post :update, params: params_runner_project.merge(runner: { description: old_desc.swapcase } ) + post :update, params: params_runner_project.merge(runner: { description: old_desc.swapcase }) end.not_to change { project_runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:not_found) diff --git a/spec/controllers/groups/settings/repository_controller_spec.rb b/spec/controllers/groups/settings/repository_controller_spec.rb index cbf55218b94..73a205069f5 100644 --- a/spec/controllers/groups/settings/repository_controller_spec.rb +++ b/spec/controllers/groups/settings/repository_controller_spec.rb @@ -13,88 +13,73 @@ RSpec.describe Groups::Settings::RepositoryController do end describe 'POST create_deploy_token' do - context 'when ajax_new_deploy_token feature flag is disabled for the project' do - before do - stub_feature_flags(ajax_new_deploy_token: false) - entity.add_owner(user) - end + let(:good_deploy_token_params) do + { + name: 'name', + expires_at: 1.day.from_now.to_s, + username: 'deployer', + read_repository: '1', + deploy_token_type: DeployToken.deploy_token_types[:group_type] + } + end - it_behaves_like 'a created deploy token' do - let(:entity) { group } - let(:create_entity_params) { { group_id: group } } - let(:deploy_token_type) { DeployToken.deploy_token_types[:group_type] } - end + let(:request_params) do + { + group_id: group.to_param, + deploy_token: deploy_token_params + } end - context 'when ajax_new_deploy_token feature flag is enabled for the project' do - let(:good_deploy_token_params) do - { - name: 'name', - expires_at: 1.day.from_now.to_s, - username: 'deployer', - read_repository: '1', - deploy_token_type: DeployToken.deploy_token_types[:group_type] - } - end + before do + group.add_owner(user) + end + + subject { post :create_deploy_token, params: request_params, format: :json } - let(:request_params) do + context('a good request') do + let(:deploy_token_params) { good_deploy_token_params } + let(:expected_response) do { - group_id: group.to_param, - deploy_token: deploy_token_params + 'id' => be_a(Integer), + 'name' => deploy_token_params[:name], + 'username' => deploy_token_params[:username], + 'expires_at' => Time.zone.parse(deploy_token_params[:expires_at]), + 'token' => be_a(String), + 'expired' => false, + 'revoked' => false, + 'scopes' => deploy_token_params.inject([]) do |scopes, kv| + key, value = kv + key.to_s.start_with?('read_') && value.to_i != 0 ? scopes << key.to_s : scopes + end } end - before do - group.add_owner(user) - end + it 'creates the deploy token' do + subject - subject { post :create_deploy_token, params: request_params, format: :json } - - context('a good request') do - let(:deploy_token_params) { good_deploy_token_params } - let(:expected_response) do - { - 'id' => be_a(Integer), - 'name' => deploy_token_params[:name], - 'username' => deploy_token_params[:username], - 'expires_at' => Time.zone.parse(deploy_token_params[:expires_at]), - 'token' => be_a(String), - 'expired' => false, - 'revoked' => false, - 'scopes' => deploy_token_params.inject([]) do |scopes, kv| - key, value = kv - key.to_s.start_with?('read_') && value.to_i != 0 ? scopes << key.to_s : scopes - end - } - end - - it 'creates the deploy token' do - subject - - expect(response).to have_gitlab_http_status(:created) - expect(response).to match_response_schema('public_api/v4/deploy_token') - expect(json_response).to match(expected_response) - end + expect(response).to have_gitlab_http_status(:created) + expect(response).to match_response_schema('public_api/v4/deploy_token') + expect(json_response).to match(expected_response) end + end - context('a bad request') do - let(:deploy_token_params) { good_deploy_token_params.except(:read_repository) } - let(:expected_response) { { 'message' => "Scopes can't be blank" } } + context('a bad request') do + let(:deploy_token_params) { good_deploy_token_params.except(:read_repository) } + let(:expected_response) { { 'message' => "Scopes can't be blank" } } - it 'does not create the deploy token' do - subject + it 'does not create the deploy token' do + subject - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response).to match(expected_response) - end + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response).to match(expected_response) end + end - context('an invalid request') do - let(:deploy_token_params) { good_deploy_token_params.except(:name) } + context('an invalid request') do + let(:deploy_token_params) { good_deploy_token_params.except(:name) } - it 'raises a validation error' do - expect { subject }.to raise_error(ActiveRecord::StatementInvalid) - end + it 'raises a validation error' do + expect { subject }.to raise_error(ActiveRecord::StatementInvalid) end end end |