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

turn Storages::FileLinks::CreateContract into a ModelContract

Christophe Bliardf40197dc1a03
diff --git a/modules/storages/app/contracts/storages/file_links/create_contract.rb b/modules/storages/app/contracts/storages/file_links/create_contract.rb
index c8735429840..f694dfc954f 100644
--- a/modules/storages/app/contracts/storages/file_links/create_contract.rb
+++ b/modules/storages/app/contracts/storages/file_links/create_contract.rb
@@ -26,7 +26,21 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Storages::FileLinks::CreateContract < BaseContract
+class Storages::FileLinks::CreateContract < ModelContract
+ attribute :name
+ attribute :storage
+ attribute :creator
+ attribute :container
+ attribute :container_type
+
+ attribute :origin_id
+ attribute :origin_name
+ attribute :origin_created_by_name
+ attribute :origin_last_modified_by_name
+ attribute :origin_mime_type
+ attribute :origin_created_at
+ attribute :origin_updated_at
+
validate :validate_storage_presence
validate :validate_user_allowed_to_manage
validate :validate_project_storage_link
diff --git a/spec/requests/api/v3/support/api_v3_collection_response.rb b/spec/requests/api/v3/support/api_v3_collection_response.rb
index a2b8ec73c81..15559403c6d 100644
--- a/spec/requests/api/v3/support/api_v3_collection_response.rb
+++ b/spec/requests/api/v3/support/api_v3_collection_response.rb
@@ -60,6 +60,13 @@ shared_examples_for 'API V3 collection response' do |total, count, element_type,
it 'returns a collection successfully' do
aggregate_failures do
expect(last_response.status).to eq(expected_status_code)
+ errors = JSON.parse(subject).dig("_embedded", "errors")&.map { _1["message"] }
+ expect(errors).to eq([]) if errors # make errors visible in console if any
+ end
+ end
+
+ it 'contains all elements' do
+ aggregate_failures do
expect(subject).to be_json_eql(collection_type.to_json).at_path('_type')
expect(subject).to be_json_eql(count_number.to_json).at_path('count')
expect(subject).to be_json_eql(total_number.to_json).at_path('total')