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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
feat[#47147] define project folder id & mode pair contract
Kabiru Mwenjaa23ac42cd461
diff --git a/modules/storages/app/contracts/storages/project_storages/base_contract.rb b/modules/storages/app/contracts/storages/project_storages/base_contract.rbindex 88c8c65ff04..521ee30d1ad 100644--- a/modules/storages/app/contracts/storages/project_storages/base_contract.rb+++ b/modules/storages/app/contracts/storages/project_storages/base_contract.rb@@ -44,9 +44,17 @@ module Storages::ProjectStoragesvalidates_presence_of :storageattribute :project_folder_modevalidates :project_folder_mode, presence: true, inclusion: { in: Storages::ProjectStorage.project_folder_modes.keys }+ attribute :project_folder_id+ validates :project_folder_id, presence: true, if: :project_folder_mode_manual?def assignable_storagesStorages::Storage.visible(user).where.not(id: @model.project.projects_storages.pluck(:storage_id))end++ private++ def project_folder_mode_manual?+ @model.project_folder_manual?+ endendenddiff --git a/modules/storages/spec/contracts/storages/project_storages/base_contract_spec.rb b/modules/storages/spec/contracts/storages/project_storages/base_contract_spec.rbnew file mode 100644index 00000000000..35796e76887--- /dev/null+++ b/modules/storages/spec/contracts/storages/project_storages/base_contract_spec.rb@@ -0,0 +1,64 @@+#-- 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'+require 'contracts/shared/model_contract_shared_context'++describe Storages::ProjectStorages::BaseContract do+ include_context 'ModelContract shared context'++ let(:contract) { described_class.new(project_storage, build_stubbed(:admin)) }+ # Creator is not writable in BaseContract; just test base contract writable attributes+ let(:project_storage) { build(:project_storage) }++ context 'when the project folder mode is `inactive`' do+ before do+ project_storage.project_folder_mode = 'inactive'+ end++ it_behaves_like 'contract is valid'+ end++ context 'when the project folder mode is `manual`' do+ before do+ project_storage.project_folder_mode = 'manual'+ end++ context 'with no project_folder_id' do+ it_behaves_like 'contract is invalid', project_folder_id: :blank+ end++ context 'with project_folder_id' do+ before do+ project_storage.project_folder_id = 'Project#1'+ end++ it_behaves_like 'contract is valid'+ end+ end+end