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

use self_link helper

Christophe Bliardc5028bc68630
diff --git a/modules/storages/lib/api/v3/file_links/file_link_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_representer.rb
index d944ebafdb7..7c31574c018 100644
--- a/modules/storages/lib/api/v3/file_links/file_link_representer.rb
+++ b/modules/storages/lib/api/v3/file_links/file_link_representer.rb
@@ -49,11 +49,7 @@ module API
end
end
- link :self do
- {
- href: api_v3_paths.file_link(represented.id)
- }
- end
+ self_link
link :delete, cache_if: -> { user_allowed_to_manage?(represented) } do
{
diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rb
index 1eb20587721..ca4defde83b 100644
--- a/modules/storages/lib/api/v3/storages/storage_representer.rb
+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb
@@ -47,12 +47,7 @@ module API
date_time_property :updated_at
# A link back to the specific object ("represented")
- link :self do
- {
- href: api_v3_paths.storage(represented.id),
- method: :get
- }
- end
+ self_link
link :type do
{
diff --git a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb
index eb7df90e175..6ae4fc934cc 100644
--- a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb
+++ b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb
@@ -46,9 +46,10 @@ describe ::API::V3::FileLinks::FileLinkRepresenter, 'rendering' do
describe '_links' do
describe 'self' do
- it_behaves_like 'has an untitled link' do
+ it_behaves_like 'has a titled link' do
let(:link) { 'self' }
let(:href) { "/api/v3/file_links/#{file_link.id}" }
+ let(:title) { file_link.name }
end
end
diff --git a/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb b/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb
new file mode 100644
index 00000000000..6926e3c050c
--- /dev/null
+++ b/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb
@@ -0,0 +1,65 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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::Storages::StorageRepresenter, 'rendering' do
+ let(:storage) { build_stubbed(:storage) }
+ let(:user) { build_stubbed(:user) }
+ let(:representer) { described_class.new(storage, current_user: user) }
+
+ subject(:generated) { representer.to_json }
+
+ describe '_links' do
+ describe 'self' do
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'self' }
+ let(:href) { "/api/v3/storages/#{storage.id}" }
+ let(:title) { storage.name }
+ end
+ end
+ end
+
+ describe 'properties' do
+ it_behaves_like 'property', :_type do
+ let(:value) { 'Storage' }
+ end
+
+ it_behaves_like 'property', :id do
+ let(:value) { storage.id }
+ end
+
+ it_behaves_like 'datetime property', :createdAt do
+ let(:value) { storage.created_at }
+ end
+
+ it_behaves_like 'datetime property', :updatedAt do
+ let(:value) { storage.updated_at }
+ end
+ end
+end