summaryrefslogtreecommitdiff
path: root/spec/policies
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-14 15:08:59 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-14 15:08:59 +0000
commit9b762f50fee09b50b97b5ab208a9a62522447c8c (patch)
tree4dbd16c66f6aeacc1b88c1e3350df09ce4f91183 /spec/policies
parent9769ccf613ec45634ee32efaf1c39763a759a917 (diff)
downloadgitlab-ce-9b762f50fee09b50b97b5ab208a9a62522447c8c.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/policies')
-rw-r--r--spec/policies/alert_management/alert_policy_spec.rb52
1 files changed, 49 insertions, 3 deletions
diff --git a/spec/policies/alert_management/alert_policy_spec.rb b/spec/policies/alert_management/alert_policy_spec.rb
index 3e08d8b4ccc..2027c205c7b 100644
--- a/spec/policies/alert_management/alert_policy_spec.rb
+++ b/spec/policies/alert_management/alert_policy_spec.rb
@@ -3,9 +3,10 @@
require 'spec_helper'
RSpec.describe AlertManagement::AlertPolicy, :models do
- let(:alert) { create(:alert_management_alert) }
- let(:project) { alert.project }
- let(:user) { create(:user) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:alert) { create(:alert_management_alert, project: project, issue: incident) }
+ let_it_be(:incident) { nil }
subject(:policy) { described_class.new(user, alert) }
@@ -21,5 +22,50 @@ RSpec.describe AlertManagement::AlertPolicy, :models do
it { is_expected.to be_allowed :read_alert_management_alert }
it { is_expected.to be_allowed :update_alert_management_alert }
end
+
+ shared_examples 'does not allow metric image reads' do
+ it { expect(policy).to be_disallowed(:read_alert_management_metric_image) }
+ end
+
+ shared_examples 'does not allow metric image updates' do
+ specify do
+ expect(policy).to be_disallowed(:upload_alert_management_metric_image)
+ expect(policy).to be_disallowed(:destroy_alert_management_metric_image)
+ end
+ end
+
+ shared_examples 'allows metric image reads' do
+ it { expect(policy).to be_allowed(:read_alert_management_metric_image) }
+ end
+
+ shared_examples 'allows metric image updates' do
+ specify do
+ expect(policy).to be_allowed(:upload_alert_management_metric_image)
+ expect(policy).to be_allowed(:destroy_alert_management_metric_image)
+ end
+ end
+
+ context 'when user is not a member' do
+ include_examples 'does not allow metric image reads'
+ include_examples 'does not allow metric image updates'
+ end
+
+ context 'when user is a guest' do
+ before do
+ project.add_guest(user)
+ end
+
+ include_examples 'does not allow metric image reads'
+ include_examples 'does not allow metric image updates'
+ end
+
+ context 'when user is a developer' do
+ before do
+ project.add_developer(user)
+ end
+
+ include_examples 'allows metric image reads'
+ include_examples 'allows metric image updates'
+ end
end
end