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

Updates the contract to deal with missing a short key

Marcello Rocha4fe10f03b41f
diff --git a/app/contracts/custom_fields/hierarchy/insert_item_contract.rb b/app/contracts/custom_fields/hierarchy/insert_item_contract.rb
index 67c171a753a..043e1d90225 100644
--- a/app/contracts/custom_fields/hierarchy/insert_item_contract.rb
+++ b/app/contracts/custom_fields/hierarchy/insert_item_contract.rb
@@ -53,6 +53,7 @@ module CustomFields
rule(:short) do
next if schema_error?(:parent)
+ next unless key?
key.failure(:not_unique) if values[:parent].children.exists?(short: value)
end
diff --git a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb
index 21f6d5d2b19..e1266f3e649 100644
--- a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb
+++ b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb
@@ -35,7 +35,7 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService do
let(:invalid_custom_field) { create(:custom_field, field_format: "text", hierarchy_root: nil) }
let!(:root) { service.generate_root(custom_field).value! }
- let!(:luke) { service.insert_item(parent: root, label: "luke").value! }
+ let!(:luke) { service.insert_item(parent: root, label: "luke", short: "LS").value! }
let!(:mara) { service.insert_item(parent: luke, label: "mara").value! }
subject(:service) { described_class.new }
@@ -72,6 +72,7 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService do
context "with valid parameters" do
it "inserts an item successfully without short" do
result = service.insert_item(parent: luke, label:)
+
expect(result).to be_success
expect(luke.reload.children.count).to eq(2)
end
@@ -113,11 +114,12 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService do
let!(:leia) { service.insert_item(parent: root, label: "leia").value! }
it "refuses to update the item with new attributes" do
- result = service.update_item(item: luke, label: "leia", short: "LS")
+ result = service.update_item(item: leia, label: "luke", short: "LS")
expect(result).to be_failure
errors = result.failure.errors
- expect(errors.to_h).to eq({ label: ["must be unique at the same hierarchical level"] })
+ expect(errors[:label]).to eq(["must be unique within the same hierarchy level"])
+ expect(errors[:short]).to eq(["must be unique within the same hierarchy level"])
end
end
end