Commit aeae25ff authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'pl-speedup-spec-policy-project' into 'master'

Speed up EE project policy specs

See merge request gitlab-org/gitlab!37872
parents 5abc0108 c815990e
......@@ -12,17 +12,26 @@ RSpec.describe ProjectPolicy do
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:guest) { create(:user) }
let(:project) { create(:project, :public, namespace: owner.namespace) }
let_it_be(:non_member) { create(:user) }
let_it_be(:project, refind: true) { create(:project, :public, namespace: owner.namespace) }
let_it_be(:private_project, refind: true) { create(:project, :private, namespace: owner.namespace) }
subject { described_class.new(current_user, project) }
before do
stub_licensed_features(group_saml: true)
stub_licensed_features(license_scanning: true)
end
before_all do
project.add_maintainer(maintainer)
project.add_developer(developer)
project.add_reporter(reporter)
project.add_guest(guest)
stub_licensed_features(license_scanning: true)
private_project.add_maintainer(maintainer)
private_project.add_developer(developer)
private_project.add_reporter(reporter)
private_project.add_guest(guest)
end
context 'basic permissions' do
......@@ -161,7 +170,7 @@ RSpec.describe ProjectPolicy do
end
context 'when user is not a member' do
let(:current_user) { build(:user) }
let(:current_user) { non_member }
it { is_expected.to be_allowed(:read_iteration) }
it { is_expected.to be_disallowed(:create_iteration, :admin_iteration) }
......@@ -175,17 +184,10 @@ RSpec.describe ProjectPolicy do
end
context 'when the project is private' do
let(:project) { create(:project, :private, namespace: owner.namespace) }
before do
project.add_maintainer(maintainer)
project.add_developer(developer)
project.add_reporter(reporter)
project.add_guest(guest)
end
let(:project) { private_project }
context 'when user is not a member' do
let(:current_user) { build(:user) }
let(:current_user) { non_member }
it { is_expected.to be_disallowed(:read_iteration, :create_iteration, :admin_iteration) }
end
......@@ -200,7 +202,7 @@ RSpec.describe ProjectPolicy do
end
context 'issues feature' do
subject { described_class.new(owner, project) }
let(:current_user) { owner }
context 'when the feature is disabled' do
before do
......@@ -330,6 +332,7 @@ RSpec.describe ProjectPolicy do
let(:project) { create(:project, group: saml_provider.group) }
before do
stub_licensed_features(group_saml: true)
group.add_guest(current_user)
end
......@@ -451,8 +454,6 @@ RSpec.describe ProjectPolicy do
end
describe 'vulnerability feedback permissions' do
subject { described_class.new(current_user, project) }
where(permission: %i[
read_vulnerability_feedback
create_vulnerability_feedback
......@@ -504,7 +505,7 @@ RSpec.describe ProjectPolicy do
end
context 'with non member' do
let(:current_user) { create(:user) }
let(:current_user) { non_member }
it { is_expected.to be_disallowed(permission) }
end
......@@ -586,8 +587,8 @@ RSpec.describe ProjectPolicy do
end
end
context 'with not member' do
let(:current_user) { create(:user) }
context 'with non member' do
let(:current_user) { non_member }
it { is_expected.to be_disallowed(:read_threat_monitoring) }
end
......@@ -722,7 +723,7 @@ RSpec.describe ProjectPolicy do
end
context 'with non member' do
let(:current_user) { create(:user) }
let(:current_user) { non_member }
it { is_expected.to be_disallowed(:admin_software_license_policy) }
end
......@@ -769,7 +770,7 @@ RSpec.describe ProjectPolicy do
end
context 'with private project' do
let(:project) { create(:project, :private, namespace: owner.namespace) }
let(:project) { private_project }
context 'with admin' do
let(:current_user) { admin }
......@@ -813,8 +814,8 @@ RSpec.describe ProjectPolicy do
it { is_expected.to be_disallowed(:read_dependencies) }
end
context 'with not member' do
let(:current_user) { create(:user) }
context 'with non member' do
let(:current_user) { non_member }
it { is_expected.to be_disallowed(:read_dependencies) }
end
......@@ -837,7 +838,7 @@ RSpec.describe ProjectPolicy do
describe 'read_licenses' do
context 'when license management feature available' do
context 'with public project' do
let(:current_user) { create(:user) }
let(:current_user) { non_member }
context 'with public access to repository' do
it { is_expected.to be_allowed(:read_licenses) }
......@@ -845,7 +846,7 @@ RSpec.describe ProjectPolicy do
end
context 'with private project' do
let(:project) { create(:project, :private, namespace: owner.namespace) }
let(:project) { private_project }
where(role: %w[owner maintainer developer reporter])
......@@ -873,8 +874,8 @@ RSpec.describe ProjectPolicy do
it { is_expected.to be_disallowed(:read_licenses) }
end
context 'with not member' do
let(:current_user) { create(:user) }
context 'with non member' do
let(:current_user) { non_member }
it { is_expected.to be_disallowed(:read_licenses) }
end
......@@ -1139,7 +1140,7 @@ RSpec.describe ProjectPolicy do
end
context 'with non member' do
let(:current_user) { create(:user) }
let(:current_user) { non_member }
it { is_expected.to be_disallowed(:read_group_timelogs) }
end
......@@ -1162,7 +1163,7 @@ RSpec.describe ProjectPolicy do
end
describe ':read_code_review_analytics' do
let(:project) { create(:project, namespace: owner.namespace) }
let(:project) { private_project }
using RSpec::Parameterized::TableSyntax
......@@ -1199,7 +1200,7 @@ RSpec.describe ProjectPolicy do
end
shared_examples 'merge request rules' do
let(:project) { create(:project, namespace: owner.namespace) }
let(:project) { private_project }
using RSpec::Parameterized::TableSyntax
......
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