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