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
[#67973] change contract behaviour for list items
Eric Schubert29e51b69095e
diff --git a/app/contracts/custom_fields/hierarchy/update_list_item_contract.rb b/app/contracts/custom_fields/hierarchy/update_list_item_contract.rbindex cb302386381..8be798ad16f 100644--- a/app/contracts/custom_fields/hierarchy/update_list_item_contract.rb+++ b/app/contracts/custom_fields/hierarchy/update_list_item_contract.rb@@ -33,8 +33,8 @@ module CustomFieldsclass UpdateListItemContract < DryApplicationContractparams dorequired(:item).filled(type?: CustomField::Hierarchy::Item)- optional(:label).filled(:string)- optional(:short).filled(:string)+ required(:label).filled(:string)+ required(:short).maybe(:string)endrule(:item) do@@ -50,7 +50,7 @@ module CustomFieldsrule(:short) donext if schema_error?(:item)- next unless key?+ next if value.nil?key.failure(:not_unique) if values[:item].siblings.exists?(short: value)enddiff --git a/app/contracts/custom_fields/hierarchy/update_scored_item_contract.rb b/app/contracts/custom_fields/hierarchy/update_scored_item_contract.rbindex 7cab92cf8c0..234c01bf200 100644--- a/app/contracts/custom_fields/hierarchy/update_scored_item_contract.rb+++ b/app/contracts/custom_fields/hierarchy/update_scored_item_contract.rb@@ -31,11 +31,10 @@module CustomFieldsmodule Hierarchyclass UpdateScoredItemContract < DryApplicationContract-params dorequired(:item).filled(type?: CustomField::Hierarchy::Item)- optional(:label).filled(:string)- optional(:score).filled(:decimal)+ required(:label).filled(:string)+ required(:score).filled(:decimal)endrule(:item) dodiff --git a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb b/app/services/custom_fields/hierarchy/hierarchical_item_service.rbindex d801b75be0c..aa0266c817c 100644--- a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb+++ b/app/services/custom_fields/hierarchy/hierarchical_item_service.rb@@ -56,7 +56,7 @@ module CustomFieldsdef insert_item(contract_class:, parent:, label:, short: nil, score: nil, sort_order: nil)contract_class.new- .call({ parent:, label:, short:, score: }.compact)+ .call({ parent:, label:, short:, score: }).to_monad.bind { |validation| create_child_item(validation:, sort_order:) }end@@ -72,7 +72,7 @@ module CustomFieldsdef update_item(contract_class:, item:, label: nil, short: nil, score: nil)contract_class.new- .call({ item:, label:, short:, score: }.compact)+ .call({ item:, label:, short:, score: }).to_monad.bind { |attributes| update_item_attributes(item:, attributes:) }enddiff --git a/spec/contracts/custom_fields/hierarchy/update_list_item_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/update_list_item_contract_spec.rbindex 44e1094f49c..3782d10208c 100644--- a/spec/contracts/custom_fields/hierarchy/update_list_item_contract_spec.rb+++ b/spec/contracts/custom_fields/hierarchy/update_list_item_contract_spec.rb@@ -44,11 +44,8 @@ RSpec.describe CustomFields::Hierarchy::UpdateListItemContract doit "is valid" do[{ item: luke, label: "Luke Skywalker", short: "LS" },- { item: luke, label: "Luke Skywalker" },- { item: luke, label: "luke", short: "lu" },- { item: luke, short: "LS" },- { item: luke, short: "ls" },- { item: luke }+ { item: luke, label: "Luke Skywalker", short: nil },+ { item: luke, label: "luke", short: "lu" }].each { |params| expect(subject.call(params)).to be_success }endend@@ -113,10 +110,12 @@ RSpec.describe CustomFields::Hierarchy::UpdateListItemContract do[{},{ item: nil },- { item: luke, label: nil },- { item: luke, label: 42 },+ { item: luke, label: nil, short: "lu" },+ { item: luke, label: 42, short: "lu" },+ { item: luke, label: "LUKE", short: 42 },{ item: luke, short: nil },- { item: luke, short: 42 }+ { item: luke, label: "LUKE" },+ { item: luke, short: "lu" }].each { |params| expect(subject.call(params)).to be_failure }endenddiff --git a/spec/contracts/custom_fields/hierarchy/update_scored_item_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/update_scored_item_contract_spec.rbindex 8e4853078d4..137e9f97657 100644--- a/spec/contracts/custom_fields/hierarchy/update_scored_item_contract_spec.rb+++ b/spec/contracts/custom_fields/hierarchy/update_scored_item_contract_spec.rb@@ -44,10 +44,7 @@ RSpec.describe CustomFields::Hierarchy::UpdateScoredItemContract doit "is valid" do[{ item: high, label: "VERY HIGH", score: 1.17e-12 },- { item: high, label: "HIGH", score: 1.17e-11 },- { item: high, label: "VERY HIGH" },- { item: high, score: 1.17e-10 },- { item: high }+ { item: high, label: "HIGH", score: 1.17e-11 }].each { |params| expect(subject.call(params)).to be_success }endend@@ -100,10 +97,13 @@ RSpec.describe CustomFields::Hierarchy::UpdateScoredItemContract do[{},{ item: nil },- { item: high, label: nil },{ item: high, label: 42 },- { item: high, score: nil },- { item: high, score: "pi" }+ { item: high, score: "pi" },+ { item: high, label: nil, score: 4 },+ { item: high, label: "pi", score: nil },+ { item: high, label: "pi", score: "threepointonefour" },+ { item: high, label: 42, score: 4 },+ { item: high, label: "", score: 4 }].each { |params| expect(subject.call(params)).to be_failure }endend