debian-mirror-gitlab/spec/policies/metrics/dashboard/annotation_policy_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.9 KiB
Ruby
Raw Permalink Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Metrics::Dashboard::AnnotationPolicy, :models do
2020-11-24 15:15:51 +05:30
let(:policy) { described_class.new(user, annotation) }
let_it_be(:user) { create(:user) }
2020-04-22 19:07:51 +05:30
shared_examples 'metrics dashboard annotation policy' do
context 'when guest' do
before do
project.add_guest(user)
end
it { expect(policy).to be_disallowed :read_metrics_dashboard_annotation }
2023-05-27 22:25:52 +05:30
it { expect(policy).to be_disallowed :admin_metrics_dashboard_annotation }
2020-04-22 19:07:51 +05:30
end
context 'when reporter' do
before do
project.add_reporter(user)
end
it { expect(policy).to be_allowed :read_metrics_dashboard_annotation }
2023-05-27 22:25:52 +05:30
it { expect(policy).to be_disallowed :admin_metrics_dashboard_annotation }
2020-04-22 19:07:51 +05:30
end
context 'when developer' do
before do
project.add_developer(user)
end
it { expect(policy).to be_allowed :read_metrics_dashboard_annotation }
2023-05-27 22:25:52 +05:30
it { expect(policy).to be_allowed :admin_metrics_dashboard_annotation }
2020-04-22 19:07:51 +05:30
end
context 'when maintainer' do
before do
project.add_maintainer(user)
end
it { expect(policy).to be_allowed :read_metrics_dashboard_annotation }
2023-05-27 22:25:52 +05:30
it { expect(policy).to be_allowed :admin_metrics_dashboard_annotation }
2020-04-22 19:07:51 +05:30
end
end
describe 'rules' do
context 'environments annotation' do
2020-11-24 15:15:51 +05:30
let_it_be(:environment) { create(:environment) }
let_it_be(:annotation) { create(:metrics_dashboard_annotation, environment: environment) }
2020-04-22 19:07:51 +05:30
2020-11-24 15:15:51 +05:30
it_behaves_like 'metrics dashboard annotation policy' do
let(:project) { environment.project }
end
2020-04-22 19:07:51 +05:30
end
context 'cluster annotation' do
2020-11-24 15:15:51 +05:30
let_it_be(:cluster) { create(:cluster, :project) }
let_it_be(:annotation) { create(:metrics_dashboard_annotation, environment: nil, cluster: cluster) }
2020-04-22 19:07:51 +05:30
2020-11-24 15:15:51 +05:30
it_behaves_like 'metrics dashboard annotation policy' do
let(:project) { cluster.project }
end
2020-04-22 19:07:51 +05:30
end
end
end