Add representation formats to project API

pull/9782/head
Oliver Günther 3 years ago
parent e904a7e59d
commit f039fc8333
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 9
      docs/api/apiv3/components/schemas/list_projects_model.yml
  2. 4
      lib/api/v3/projects/project_collection_representer.rb
  3. 4
      modules/backlogs/spec/models/work_package_export_spec.rb
  4. 40
      spec/lib/api/v3/projects/project_collection_representer_spec.rb

@ -5,6 +5,15 @@ example:
_links:
self:
href: "/api/v3/projects"
representations:
- href: "/projects.csv?filters=%5B%7B%22nameAndIdentifier%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%22open%22%5D%7D%7D%5D&offset=1&pageSize=50",
identifier: "csv",
type: "text/csv",
title: "CSV"
- href: "/projects.xls?filters=%5B%7B%22nameAndIdentifier%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%22open%22%5D%7D%7D%5D&offset=1&pageSize=50",
identifier: "xls",
type: "application/vnd.ms-excel",
title: "XLS"
_type: Collection
total: 2
count: 2

@ -36,11 +36,11 @@ require 'roar/json/hal'
module API
module V3
module Projects
class ProjectCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection
class ProjectCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection
self.to_eager_load = ::API::V3::Projects::ProjectRepresenter.to_eager_load
self.checked_permissions = ::API::V3::Projects::ProjectRepresenter.checked_permissions
def initialize(models, **options)
def initialize(represented, self_link:, current_user:, query: {}, page: nil, per_page: nil, groups: nil)
super
@represented = ::API::V3::Projects::ProjectEagerLoadingWrapper.wrap(represented)

@ -28,7 +28,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe WorkPackage::Exporter::PDF, type: :model do
describe WorkPackage::PDFExport::WorkPackageToPdf, type: :model do
let(:project) { FactoryBot.create :project }
let(:query) { Query.new_default(name: '_', project: project) }
subject { described_class.new query }
@ -39,7 +39,7 @@ describe WorkPackage::Exporter::PDF, type: :model do
describe 'backlogs column' do
it 'should contain the story_points column in valid export column names' do
backlog_column = subject.valid_export_columns.detect { |c| c.name == :story_points }
backlog_column = subject.columns.detect { |c| c.name == :story_points }
expect(backlog_column).to be_present
end
end

@ -29,17 +29,49 @@
require 'spec_helper'
describe ::API::V3::Projects::ProjectCollectionRepresenter do
let(:self_link) { '/api/v3/versions/1/projects' }
let(:projects) { FactoryBot.build_list(:project, 3) }
shared_let(:projects) { FactoryBot.create_list(:project, 3) }
let(:self_base_link) { '/api/v3/projects' }
let(:current_user) { FactoryBot.build(:user) }
let(:representer) do
described_class.new(projects, self_link: self_link, current_user: current_user)
described_class.new Project.all,
self_link: self_base_link,
current_user: current_user
end
let(:total) { 3 }
let(:page) { 1 }
let(:page_size) { 30 }
let(:actual_count) { 3 }
let(:collection_inner_type) { 'Project' }
subject { representer.to_json }
context 'generation' do
subject(:collection) { representer.to_json }
it_behaves_like 'unpaginated APIv3 collection', 3, 'versions/1/projects', 'Project'
it_behaves_like 'offset-paginated APIv3 collection', 3, 'projects', 'Project'
end
describe 'representation formats' do
it_behaves_like 'has a link collection' do
let(:link) { 'representations' }
let(:hrefs) do
[
{
'href' => '/projects.csv?offset=1&pageSize=30',
'identifier' => 'csv',
'type' => 'text/csv',
'title' => 'CSV'
},
{
'href' => '/projects.xls?offset=1&pageSize=30',
'identifier' => 'xls',
'type' => 'application/vnd.ms-excel',
'title' => 'XLS'
}
]
end
end
end
describe '.checked_permissions' do

Loading…
Cancel
Save