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] update insert contract to behave like update
Eric Schubert7845b35cb31a
diff --git a/app/contracts/custom_fields/hierarchy/insert_list_item_contract.rb b/app/contracts/custom_fields/hierarchy/insert_list_item_contract.rbindex 2efc10d6603..4e0fc3ebb7d 100644--- a/app/contracts/custom_fields/hierarchy/insert_list_item_contract.rb+++ b/app/contracts/custom_fields/hierarchy/insert_list_item_contract.rb@@ -31,11 +31,10 @@module CustomFieldsmodule Hierarchyclass InsertListItemContract < DryApplicationContract-params dorequired(:parent).filled(type?: CustomField::Hierarchy::Item)required(:label).filled(:string)- optional(:short).filled(:string)+ required(:short).maybe(:string)endrule(:parent) do@@ -52,7 +51,7 @@ module CustomFieldsrule(:short) donext if schema_error?(:parent)- next unless key?+ next if value.nil?key.failure(:not_unique) if values[:parent].children.exists?(short: value)enddiff --git a/spec/contracts/custom_fields/hierarchy/insert_list_item_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/insert_list_item_contract_spec.rbindex fad946b3584..0f72935454b 100644--- a/spec/contracts/custom_fields/hierarchy/insert_list_item_contract_spec.rb+++ b/spec/contracts/custom_fields/hierarchy/insert_list_item_contract_spec.rb@@ -38,7 +38,7 @@ RSpec.describe CustomFields::Hierarchy::InsertListItemContract dolet(:parent) { create(:hierarchy_item) }context "when all required fields are valid" do- let(:params) { { parent:, label: "Valid Label" } }+ let(:params) { { parent:, label: "Valid Label", short: nil } }it "is valid" doresult = subject.call(params)@@ -48,7 +48,7 @@ RSpec.describe CustomFields::Hierarchy::InsertListItemContract docontext "when parent is not of type 'Item'" dolet(:invalid_parent) { create(:custom_field) }- let(:params) { { parent: invalid_parent, label: "Valid Label" } }+ let(:params) { { parent: invalid_parent, label: "Valid Label", short: nil } }it "is invalid" doresult = subject.call(params)@@ -62,7 +62,7 @@ RSpec.describe CustomFields::Hierarchy::InsertListItemContract docreate(:hierarchy_item, parent:, label: "Duplicate Label")end- let(:params) { { parent:, label: "Duplicate Label" } }+ let(:params) { { parent:, label: "Duplicate Label", short: nil } }it "is invalid" doresult = subject.call(params)@@ -132,7 +132,7 @@ RSpec.describe CustomFields::Hierarchy::InsertListItemContract doit "creates a success result" do[{ parent:, label: "A label", short: "A shorthand" },- { parent:, label: "A label" }+ { parent:, label: "A label", short: nil }].each { |params| expect(subject.call(params)).to be_success }endend@@ -140,15 +140,14 @@ RSpec.describe CustomFields::Hierarchy::InsertListItemContract docontext "when inputs are invalid" doit "creates a failure result" do[- { parent:, label: "A label", short: "" },- { parent:, label: "A label", short: nil },- { parent:, label: "" },- { parent:, label: nil },{ parent: },- { parent: nil },- { parent: nil, label: "A label" },- { parent: "parent", label: "A label" },- { parent: 42, label: "A label" }+ { parent:, label: "A label" },+ { parent:, short: "AL" },+ { parent: nil, label: "A label", short: nil },+ { parent: 42, label: "A label", short: nil },+ { parent:, label: nil, short: nil },+ { parent:, label: 42, short: nil },+ { parent:, label: "A label", short: 42 }].each { |params| expect(subject.call(params)).to be_failure }endend