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

refactor

Christophe Bliard4e5c01cf4198
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 9f8e3cfdd4c..063b24d8e05 100644
--- a/modules/storages/app/contracts/storages/file_links/create_contract.rb
+++ b/modules/storages/app/contracts/storages/file_links/create_contract.rb
@@ -27,7 +27,7 @@
#++
class Storages::FileLinks::CreateContract < BaseContract
- validate :validate_storage_url
+ validate :validate_storage_presence
validate :validate_user_allowed_to_manage
validate :validate_project_storage_link
@@ -41,12 +41,12 @@ class Storages::FileLinks::CreateContract < BaseContract
end
end
- def validate_storage_url
- errors.add(:storage_id, :invalid) if model.storage_id.blank?
+ def validate_storage_presence
+ errors.add(:storage, :invalid) if model.storage.nil?
end
def validate_project_storage_link
storage_is_not_linked = model.storage.present? && model.project.storages.exclude?(model.storage)
- errors.add(:storage_id, :not_linked_to_project) if storage_is_not_linked
+ errors.add(:storage, :not_linked_to_project) if storage_is_not_linked
end
end
diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb
index 61a1ab03006..1af682ea68c 100644
--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb
+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb
@@ -140,7 +140,6 @@ describe 'API v3 file links resource', type: :request do
context 'if the request body contains an invalid storage host' do
let(:storage_url1) { 'https://invalid.host.org/' }
- let(:storage_url2) { storage.host }
it_behaves_like 'constraint violation' do
let(:message) { 'Storage is invalid' }
@@ -149,7 +148,6 @@ describe 'API v3 file links resource', type: :request do
context 'if the request body contains a storage host that is not linked to the project of the work package' do
let(:storage_url1) { another_storage.host }
- let(:storage_url2) { storage.host }
it_behaves_like 'constraint violation' do
let(:message) { 'Storage is not linked to project' }