Skip to content

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

2nd refactoring step for the allowed_to spec

Klaus Zanders56c0c614473a
diff --git a/spec/models/users/allowed_to_spec.rb b/spec/models/users/allowed_to_spec.rb
index 8deced8de41..1790b25149c 100644
--- a/spec/models/users/allowed_to_spec.rb
+++ b/spec/models/users/allowed_to_spec.rb
@@ -55,62 +55,52 @@ RSpec.describe User, 'allowed_to?' do
let(:permission) { :add_work_packages }
let(:final_setup_step) {}
- context 'w/ the user being admin' do
- before do
- user.update(admin: true)
+ context 'with the user being admin' do
+ before { user.update(admin: true) }
- project.save
+ context 'with the project being persisted and active' do
+ before do
+ project.save
- final_setup_step
- end
+ final_setup_step
+ end
- it 'is true' do
- expect(user).to be_allowed_to(permission, project)
+ it { expect(user).to be_allowed_to(permission, project) }
end
- end
- context 'w/ the user being admin
- w/ the project being archived' do
- before do
- user.update(admin: true)
- project.update(active: false)
+ context 'with the project being archived' do
+ before do
+ project.update(active: false)
- final_setup_step
- end
+ final_setup_step
+ end
- it 'is false' do
- expect(user).not_to be_allowed_to(permission, project)
+ it { expect(user).not_to be_allowed_to(permission, project) }
end
- end
- context 'w/ the user being admin
- w/ the project module the permission belongs to being inactive' do
- before do
- user.update(admin: true)
- project.enabled_module_names = []
+ context 'with the required module being inactive' do
+ let(:permission) { :create_meetings } # pick a permission from a module
- final_setup_step
- end
+ before do
+ project.save
+ project.enabled_module_names -= ['meetings']
- it 'is false' do
- expect(user).not_to be_allowed_to(permission, project)
- end
- end
+ final_setup_step
+ end
- context 'w/ the user being admin
- w/ the permission not automatically granted to admins' do
- let(:permission) { :work_package_assigned }
+ it { expect(user).not_to be_allowed_to(permission, project) }
+ end
- before do
- user.update(admin: true)
+ context 'with the permission not being automatically granted to admins' do
+ let(:permission) { :work_package_assigned } # permission that is not automatically granted to admins
- project.save
+ before do
+ project.save
- final_setup_step
- end
+ final_setup_step
+ end
- it 'is false' do
- expect(user).not_to be_allowed_to(permission, project)
+ it { expect(user).not_to be_allowed_to(permission, project) }
end
end