From 01f5cb131e61a79a775d5863cf5d93fda50315c7 Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Wed, 4 Dec 2024 16:16:48 +0100 Subject: [PATCH] [#59866] fixed update contract - https://community.openproject.org/work_packages/59866 - skip uniqueness check for short if short is deleted --- app/contracts/custom_fields/hierarchy/update_item_contract.rb | 1 + .../custom_fields/hierarchy/update_item_contract_spec.rb | 1 + spec/factories/hierarchy_item_factory.rb | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/contracts/custom_fields/hierarchy/update_item_contract.rb b/app/contracts/custom_fields/hierarchy/update_item_contract.rb index 01c12c873401..614cd121ab7e 100644 --- a/app/contracts/custom_fields/hierarchy/update_item_contract.rb +++ b/app/contracts/custom_fields/hierarchy/update_item_contract.rb @@ -52,6 +52,7 @@ class UpdateItemContract < Dry::Validation::Contract rule(:short) do next if schema_error?(:item) + next unless key? key.failure(:not_unique) if values[:item].siblings.exists?(short: value) end diff --git a/spec/contracts/custom_fields/hierarchy/update_item_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/update_item_contract_spec.rb index d1f0a7ebeaf9..f2eaae17f3c2 100644 --- a/spec/contracts/custom_fields/hierarchy/update_item_contract_spec.rb +++ b/spec/contracts/custom_fields/hierarchy/update_item_contract_spec.rb @@ -38,6 +38,7 @@ let!(:vader) { create(:hierarchy_item) } let!(:luke) { create(:hierarchy_item, label: "luke", short: "ls", parent: vader) } let!(:leia) { create(:hierarchy_item, label: "leia", short: "lo", parent: vader) } + let!(:starkiller) { create(:hierarchy_item, label: "starkiller", parent: vader) } context "when all required fields are valid" do it "is valid" do diff --git a/spec/factories/hierarchy_item_factory.rb b/spec/factories/hierarchy_item_factory.rb index c24c0155d161..0185ff0f3feb 100644 --- a/spec/factories/hierarchy_item_factory.rb +++ b/spec/factories/hierarchy_item_factory.rb @@ -31,6 +31,5 @@ FactoryBot.define do factory :hierarchy_item, class: "CustomField::Hierarchy::Item" do sequence(:label) { |n| "Item #{n}" } - sequence(:short) { |n| "I #{n}" } end end