diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-12 09:10:10 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-12 09:10:10 +0300 |
commit | 09acddd7fd2b59afa69eca95b1e34739e1f1b31b (patch) | |
tree | 3376c27fb8183ad2af565706677736d267281c83 /spec/helpers | |
parent | bb01b338bfbc6e17996696145e6c495694b8f745 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/packages_helper_spec.rb | 111 |
1 files changed, 110 insertions, 1 deletions
diff --git a/spec/helpers/packages_helper_spec.rb b/spec/helpers/packages_helper_spec.rb index ae8a7f0c14c..6d6b8e4c707 100644 --- a/spec/helpers/packages_helper_spec.rb +++ b/spec/helpers/packages_helper_spec.rb @@ -132,7 +132,6 @@ RSpec.describe PackagesHelper, feature_category: :package_registry do describe '#show_container_registry_settings' do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } - let_it_be(:admin) { create(:admin) } before do allow(helper).to receive(:current_user) { user } @@ -252,4 +251,114 @@ RSpec.describe PackagesHelper, feature_category: :package_registry do end end end + + describe '#can_delete_packages?' do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + before do + allow(helper).to receive(:current_user) { user } + end + + subject { helper.can_delete_packages?(project) } + + context 'with package registry config enabled' do + before do + stub_config(packages: { enabled: true }) + end + + context 'when user has permission' do + before do + allow(Ability).to receive(:allowed?).with(user, :destroy_package, project).and_return(true) + end + + it { is_expected.to be(true) } + end + + context 'when user does not have permission' do + before do + allow(Ability).to receive(:allowed?).with(user, :destroy_package, project).and_return(false) + end + + it { is_expected.to be(false) } + end + end + + context 'with package registry config disabled' do + before do + stub_config(packages: { enabled: false }) + end + + context 'when user has permission' do + before do + allow(Ability).to receive(:allowed?).with(user, :destroy_package, project).and_return(true) + end + + it { is_expected.to be(false) } + end + + context 'when user does not have permission' do + before do + allow(Ability).to receive(:allowed?).with(user, :destroy_package, project).and_return(false) + end + + it { is_expected.to be(false) } + end + end + end + + describe '#can_delete_group_packages?' do + let_it_be(:group) { create(:group) } + let_it_be(:user) { create(:user) } + + before do + allow(helper).to receive(:current_user) { user } + end + + subject { helper.can_delete_group_packages?(group) } + + context 'with package registry config enabled' do + before do + stub_config(packages: { enabled: true }) + end + + context 'when user has permission' do + before do + allow(Ability).to receive(:allowed?).with(user, :destroy_package, group).and_return(true) + end + + it { is_expected.to be(true) } + end + + context 'when user does not have permission' do + before do + allow(Ability).to receive(:allowed?).with(user, :destroy_package, group).and_return(false) + end + + it { is_expected.to be(false) } + end + end + + context 'with package registry config disabled' do + before do + stub_config(packages: { enabled: false }) + end + + context 'when user has permission' do + before do + allow(Ability).to receive(:allowed?).with(user, :destroy_package, group).and_return(true) + end + + it { is_expected.to be(false) } + end + + context 'when user does not have permission' do + before do + allow(Ability).to receive(:allowed?).with(user, :destroy_package, group).and_return(false) + end + + it { is_expected.to be(false) } + end + end + end end |