OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
add more tests for #allowed_based_on_permission_context specs
Klaus Zanders6a6b3b7c1109
diff --git a/spec/models/users/permission_checks_spec.rb b/spec/models/users/permission_checks_spec.rbindex d178bbbfda1..eee645520ac 100644--- a/spec/models/users/permission_checks_spec.rb+++ b/spec/models/users/permission_checks_spec.rb@@ -73,55 +73,87 @@ RSpec.describe User, "permission check methods" doendend- context 'with a project permission and a project' do+ context 'with a project permission' dolet(:permission) { :manage_members }- let(:project) { build_stubbed(:project) }- it 'uses the #allowed_in_project? method' do- expect(subject).to receive(:allowed_in_project?).with(permission_object, project)- result+ context 'without a project or entity' do+ let(:entity) { nil }+ let(:project) { nil }++ it 'uses the #allowed_in_any_project? method' do+ expect(subject).to receive(:allowed_in_any_project?).with(permission_object)+ result+ endend- end- context 'with a project permission and something that responds to #project' do- let(:permission) { :manage_members }- let(:entity) { build_stubbed(:meeting) }+ context 'with a project' do+ let(:project) { build_stubbed(:project) }- it 'uses the #allowed_in_project? method' do- expect(subject).to receive(:allowed_in_project?).with(permission_object, entity.project)- result+ it 'uses the #allowed_in_project? method' do+ expect(subject).to receive(:allowed_in_project?).with(permission_object, project)+ result+ endend- end- context 'with a work package permission and a work package' do- let(:permission) { :log_own_time }- let(:entity) { build_stubbed(:work_package) }+ context 'with an entity that responds to #project' do+ let(:permission) { :manage_members }+ let(:entity) { build_stubbed(:meeting) }- it 'uses the #allowed_in_work_package? method' do- expect(subject).to receive(:allowed_in_work_package?).with(permission_object, entity)- result+ it 'uses the #allowed_in_project? method' do+ expect(subject).to receive(:allowed_in_project?).with(permission_object, entity.project)+ result+ end++ context 'with the project being nil' do+ let(:entity) { build_stubbed(:meeting, project: nil) }++ it 'uses the #allowed_in_any_project? method' do+ expect(subject).to receive(:allowed_in_any_project?).with(permission_object)+ result+ end+ end+ end++ context 'and an entity that does not respond to #project' do+ let(:entity) { build_stubbed(:user) }++ it 'uses the #allowed_in_any_project? method' do+ expect(subject).to receive(:allowed_in_any_project?).with(permission_object)+ result+ endendend- context 'with a work package and project permission and a work package and a project' do+ context 'with a work package (and a project) permission' dolet(:permission) { :log_own_time }- let(:entity) { build_stubbed(:work_package) }- let(:project) { build_stubbed(:project) }- it 'uses the #allowed_in_work_package? method' do- expect(subject).to receive(:allowed_in_work_package?).with(permission_object, entity)- result+ context 'with a work package as the entity' do+ let(:entity) { build_stubbed(:work_package) }++ it 'uses the #allowed_in_work_package? method' do+ expect(subject).to receive(:allowed_in_work_package?).with(permission_object, entity)+ result+ endend- end- context 'with a project permission and no project or entity' do- let(:permission) { :manage_members }- let(:entity) { nil }- let(:project) { nil }+ context 'with a project and no entity' do+ let(:project) { build_stubbed(:project) }- it 'uses the #allowed_in_any_project? method' do- expect(subject).to receive(:allowed_in_any_project?).with(permission_object)- result+ it 'uses the #allowed_in_any_work_package? method with in_project: param' do+ expect(subject).to receive(:allowed_in_any_work_package?).with(permission_object, in_project: project)+ result+ end+ end++ context 'with a work package and a project' do+ let(:permission) { :log_own_time }+ let(:entity) { build_stubbed(:work_package) }+ let(:project) { build_stubbed(:project) }++ it 'uses the #allowed_in_work_package? method' do+ expect(subject).to receive(:allowed_in_work_package?).with(permission_object, entity)+ result+ endendendend