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

[#47049] Added ProjectStorageRepresenterSpec

Andreas Pfohlb4cf3425c13c
diff --git a/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb b/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb
index eebb4459405..665929af640 100644
--- a/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb
+++ b/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb
@@ -31,6 +31,8 @@ module API::V3::ProjectStorages
include API::Decorators::DateProperty
include API::Decorators::LinkedResource
+ defaults render_nil: true
+
self_link(title: false)
property :id
diff --git a/modules/storages/spec/factories/project_storage_factory.rb b/modules/storages/spec/factories/project_storage_factory.rb
index 78b4c4736ea..29dfeea8f6b 100644
--- a/modules/storages/spec/factories/project_storage_factory.rb
+++ b/modules/storages/spec/factories/project_storage_factory.rb
@@ -32,5 +32,7 @@ FactoryBot.define do
creator factory: :user
storage factory: :storage
project factory: :project
+ project_folder_id { 'some_folder' }
+ project_folder_mode { 'manual' }
end
end
diff --git a/modules/storages/spec/lib/api/v3/project_storages/project_storage_representer_spec.rb b/modules/storages/spec/lib/api/v3/project_storages/project_storage_representer_spec.rb
new file mode 100644
index 00000000000..ef0c74800fb
--- /dev/null
+++ b/modules/storages/spec/lib/api/v3/project_storages/project_storage_representer_spec.rb
@@ -0,0 +1,85 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require 'spec_helper'
+
+describe API::V3::ProjectStorages::ProjectStorageRepresenter do
+ include API::V3::Utilities::PathHelper
+
+ let(:user) { build_stubbed(:user) }
+
+ let(:project_storage) { build_stubbed(:project_storage) }
+
+ let(:representer) { described_class.new(project_storage, current_user: user) }
+
+ subject { representer.to_json }
+
+ describe 'properties' do
+ it_behaves_like 'property', :_type do
+ let(:value) { representer._type }
+ end
+
+ it_behaves_like 'property', :id do
+ let(:value) { project_storage.id }
+ end
+
+ it_behaves_like 'datetime property', :createdAt do
+ let(:value) { project_storage.created_at }
+ end
+
+ it_behaves_like 'datetime property', :updatedAt do
+ let(:value) { project_storage.updated_at }
+ end
+
+ it_behaves_like 'property', :projectFolderId do
+ let(:value) { project_storage.project_folder_id }
+ end
+
+ it_behaves_like 'property', :projectFolderMode do
+ let(:value) { project_storage.project_folder_mode }
+ end
+
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'storage' }
+ let(:href) { api_v3_paths.storage(project_storage.storage.id) }
+ let(:title) { project_storage.storage.name }
+ end
+
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'project' }
+ let(:href) { api_v3_paths.project(project_storage.project.id) }
+ let(:title) { project_storage.project.name }
+ end
+
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'creator' }
+ let(:href) { api_v3_paths.user(project_storage.creator.id) }
+ let(:title) { project_storage.creator.name }
+ end
+ end
+end