[#42551] API: Add Storages to collection endpoint of projects

https://community.openproject.org/work_packages/42551

- This fixes a failed class check when eager loading projects
pull/10794/head
Andreas Pfohl 2 years ago committed by Oliver Günther
parent a850392a04
commit cebc05b3e5
  1. 3
      lib/api/v3/projects/project_eager_loading_wrapper.rb
  2. 13
      spec/requests/api/v3/projects/index_resource_spec.rb

@ -32,6 +32,9 @@ module API
class ProjectEagerLoadingWrapper < API::V3::Utilities::EagerLoading::EagerLoadingWrapper
include API::V3::Utilities::EagerLoading::CustomFieldAccessor
# delegate class check to wrapped object, as there are cases where the type is checked explicitly.
delegate :is_a?, to: :__getobj__
class << self
def wrap(projects)
custom_fields = projects.first.available_custom_fields if projects.present?

@ -266,4 +266,17 @@ describe 'API v3 Project resource index', type: :request, content_type: :json do
.to be_json_eql(expected.to_json)
end
end
context 'as project collection' do
let(:role) { create(:role, permissions: %i[view_work_packages]) }
let(:projects) { [project] }
let(:expected) do
"#{api_v3_paths.project(project.id)}/work_packages"
end
it 'has projects with links to their work packages' do
expect(last_response.body)
.to be_json_eql(expected.to_json).at_path('_embedded/elements/0/_links/workPackages/href')
end
end
end

Loading…
Cancel
Save