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

Fix tests for WP Representer

Klaus Zandersd6238ed6ec07
diff --git a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
index 6d74550b99a..c7358b24247 100644
--- a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
@@ -220,10 +220,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
context 'when the user lacks the export_work_packages permission' do
before do
- allow(user)
- .to receive(:allowed_to?)
- .with(:export_work_packages, project, global: project.nil?)
- .and_return(false)
+ mock_permissions_for(user, &:forbid_everything)
end
it 'has no export links' do
@@ -236,18 +233,11 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
describe 'customFields' do
let(:project) { build_stubbed(:project) }
- before do
- allow(user)
- .to receive(:allowed_to?)
- .and_return(false)
- end
-
context 'with the permission to select custom fields' do
before do
- allow(user)
- .to receive(:allowed_to?)
- .with(:select_custom_fields, project)
- .and_return(true)
+ mock_permissions_for(user) do |mock|
+ mock.allow_in_project :select_custom_fields, project:
+ end
end
it 'has a link to set the custom fields for that project' do
@@ -264,6 +254,10 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
end
context 'without the permission to select custom fields' do
+ before do
+ mock_permissions_for(user, &:forbid_everything)
+ end
+
it 'has no link to set the custom fields for that project' do
expect(collection).not_to have_json_path('_links/customFields')
end
@@ -330,18 +324,13 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
context 'when the user has the edit_work_package permission in any project' do
before do
- allow(user)
- .to receive(:allowed_to?)
- .and_return(false)
-
- allow(user)
- .to receive(:allowed_to?)
- .with(:edit_work_packages, nil, global: true)
- .and_return(allowed)
+ mock_permissions_for(user) do |mock|
+ mock.allow_in_project *permissions, project: build_stubbed(:project) # any project
+ end
end
context 'when allowed' do
- let(:allowed) { true }
+ let(:permissions) { [:edit_work_packages] }
it 'has a link to templated edit work_package' do
expect(collection)
@@ -351,7 +340,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
end
context 'when not allowed' do
- let(:allowed) { false }
+ let(:permissions) { [] }
it 'has no link to templated edit work_package' do
expect(collection).not_to have_json_path('_links/editWorkPackage')
@@ -361,14 +350,9 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
context 'when the user has the add_work_package permission in any project' do
before do
- allow(user)
- .to receive(:allowed_to?)
- .and_return(false)
-
- allow(user)
- .to receive(:allowed_to?)
- .with(:add_work_packages, nil, global: true)
- .and_return(true)
+ mock_permissions_for(user) do |mock|
+ mock.allow_in_project :add_work_packages, project: build_stubbed(:project) # any project
+ end
end
it 'has a link to create work_packages' do
@@ -412,9 +396,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
context 'when the user lacks the add_work_package permission' do
before do
- allow(user)
- .to receive(:allowed_to?)
- .and_return(false)
+ mock_permissions_for(user, &:forbid_everything)
end
it 'has no link to create work_packages' do