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
[#66412] fixed test setup
Eric Schubertc6ad2c3c8f3c
diff --git a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb b/app/services/custom_fields/hierarchy/hierarchical_item_service.rbindex 8d53a964bc6..498b62c43f6 100644--- a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb+++ b/app/services/custom_fields/hierarchy/hierarchical_item_service.rb@@ -45,7 +45,7 @@ module CustomFieldsend# Insert a new node on the hierarchy tree at a desired position or at the end if no sort_order is passed.- # @param contract [Class<CustomFields::Hierarchy::InsertListItemContract>, Class<CustomFields::Hierarchy::InsertScoredItemContract>]+ # @param contract_class [Class<CustomFields::Hierarchy::InsertListItemContract>, Class<CustomFields::Hierarchy::InsertScoredItemContract>]# the params validation contract class# @param parent [CustomField::Hierarchy::Item] the parent of the node# @param label [String] the node label/name that must be unique at the same tree level@@ -53,8 +53,8 @@ module CustomFields# @param score [Decimal] a numeric value for the node# @param sort_order [Integer] the position into which insert the item.# @return [Success(CustomField::Hierarchy::Item), Failure(Dry::Validation::Result), Failure(ActiveModel::Errors)]- def insert_item(contract:, parent:, label:, short: nil, score: nil, sort_order: nil)- contract+ def insert_item(contract_class:, parent:, label:, short: nil, score: nil, sort_order: nil)+ contract_class.new.call({ parent:, label:, short:, score: }.compact).to_monad@@ -62,15 +62,15 @@ module CustomFieldsend# Updates an item/node- # @param contract [Class<CustomFields::Hierarchy::UpdateListItemContract>, Class<CustomFields::Hierarchy::UpdateScoredItemContract>]+ # @param contract_class [Class<CustomFields::Hierarchy::UpdateListItemContract>, Class<CustomFields::Hierarchy::UpdateScoredItemContract>]# the params validation contract class# @param item [CustomField::Hierarchy::Item] the item to be updated# @param label [String] the node label/name that must be unique at the same tree level# @param short [String] an alias for the node# @param score [Decimal] a numeric value for the node# @return [Success(CustomField::Hierarchy::Item), Failure(Dry::Validation::Result), Failure(ActiveModel::Errors)]- def update_item(contract:, item:, label: nil, short: nil, score: nil)- contract+ def update_item(contract_class:, item:, label: nil, short: nil, score: nil)+ contract_class.new.call({ item:, label:, short:, score: }.compact).to_monaddiff --git a/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rbindex 573a1c55b5b..07485c33a4d 100644--- a/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb+++ b/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb@@ -28,7 +28,7 @@# See COPYRIGHT and LICENSE files for more details.#++-require "rails_helper"+require "spec_helper"RSpec.describe CustomFields::Hierarchy::GenerateRootContract,with_ee: [:custom_field_hierarchies],diff --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 bc7aab367b2..2f94324e40e 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@@ -28,7 +28,7 @@# See COPYRIGHT and LICENSE files for more details.#++-require "rails_helper"+require "spec_helper"RSpec.describe CustomFields::Hierarchy::InsertListItemContract dosubject { described_class.new }diff --git a/spec/contracts/custom_fields/hierarchy/insert_scored_item_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/insert_scored_item_contract_spec.rbindex 4d36d28a1bc..1ad6fb92fff 100644--- a/spec/contracts/custom_fields/hierarchy/insert_scored_item_contract_spec.rb+++ b/spec/contracts/custom_fields/hierarchy/insert_scored_item_contract_spec.rb@@ -28,7 +28,7 @@# See COPYRIGHT and LICENSE files for more details.#++-require "rails_helper"+require "spec_helper"RSpec.describe CustomFields::Hierarchy::InsertScoredItemContract dosubject { described_class.new }diff --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 5f09cd57479..cc8f5b8a3f4 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@@ -28,7 +28,7 @@# See COPYRIGHT and LICENSE files for more details.#++-require "rails_helper"+require "spec_helper"RSpec.describe CustomFields::Hierarchy::UpdateListItemContract dosubject { described_class.new }diff --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 dcd6d471eb7..44c1741b9d0 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@@ -28,7 +28,7 @@# See COPYRIGHT and LICENSE files for more details.#++-require "rails_helper"+require "spec_helper"RSpec.describe CustomFields::Hierarchy::UpdateScoredItemContract dosubject { described_class.new }diff --git a/spec/controllers/admin/custom_fields/hierarchy/items_controller_spec.rb b/spec/controllers/admin/custom_fields/hierarchy/items_controller_spec.rbindex aef9b12d7cc..dfa24354829 100644--- a/spec/controllers/admin/custom_fields/hierarchy/items_controller_spec.rb+++ b/spec/controllers/admin/custom_fields/hierarchy/items_controller_spec.rb@@ -36,7 +36,8 @@ RSpec.describe Admin::CustomFields::Hierarchy::ItemsController, with_ee: [:custolet(:custom_field) { create(:custom_field, field_format: "hierarchy", hierarchy_root: nil) }let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let(:root) { service.generate_root(custom_field).value! }- let!(:luke) { service.insert_item(parent: root, label: "luke").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:luke) { service.insert_item(contract_class:, parent: root, label: "luke").value! }current_user { user }@@ -141,9 +142,10 @@ RSpec.describe Admin::CustomFields::Hierarchy::ItemsController, with_ee: [:custodescribe "PUT #move" dobefore do- service.insert_item(parent: root, label: "not relevant")- service.insert_item(parent: root, label: "not important")- service.insert_item(parent: root, label: "unused")+ contract_class = CustomFields::Hierarchy::InsertListItemContract+ service.insert_item(contract_class:, parent: root, label: "not relevant")+ service.insert_item(contract_class:, parent: root, label: "not important")+ service.insert_item(contract_class:, parent: root, label: "unused")endcontext "when it is successful" dodiff --git a/spec/features/admin/custom_fields/work_packages/hierarchy_spec.rb b/spec/features/admin/custom_fields/work_packages/hierarchy_spec.rbindex ad766542ee6..bc073d0f726 100644--- a/spec/features/admin/custom_fields/work_packages/hierarchy_spec.rb+++ b/spec/features/admin/custom_fields/work_packages/hierarchy_spec.rb@@ -195,13 +195,14 @@ RSpec.describe "work package custom fields of type hierarchy", :js dolet(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let(:custom_field) { create(:wp_custom_field, name: "Hogwarts", field_format: "hierarchy", hierarchy_root: nil) }let!(:root) { service.generate_root(custom_field).value! }- let!(:ravenclaw) { service.insert_item(parent: root, label: "Ravenclaw").value! }- let!(:slytherin) { service.insert_item(parent: root, label: "Slytherin").value! }- let!(:hufflepuff) { service.insert_item(parent: root, label: "Hufflepuff").value! }- let!(:gryffindor) { service.insert_item(parent: root, label: "Gryffindor").value! }- let!(:luna) { service.insert_item(parent: ravenclaw, label: "Luna Lovegood").value! }- let!(:harry) { service.insert_item(parent: gryffindor, label: "Harry Potter").value! }- let!(:hermione) { service.insert_item(parent: gryffindor, label: "Hermione Granger").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:ravenclaw) { service.insert_item(contract_class:, parent: root, label: "Ravenclaw").value! }+ let!(:slytherin) { service.insert_item(contract_class:, parent: root, label: "Slytherin").value! }+ let!(:hufflepuff) { service.insert_item(contract_class:, parent: root, label: "Hufflepuff").value! }+ let!(:gryffindor) { service.insert_item(contract_class:, parent: root, label: "Gryffindor").value! }+ let!(:luna) { service.insert_item(contract_class:, parent: ravenclaw, label: "Luna Lovegood").value! }+ let!(:harry) { service.insert_item(contract_class:, parent: gryffindor, label: "Harry Potter").value! }+ let!(:hermione) { service.insert_item(contract_class:, parent: gryffindor, label: "Hermione Granger").value! }let(:tree_view) { Components::TreeView.new }before dodiff --git a/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rb b/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rbindex da088f80558..c33965cabcb 100644--- a/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rb+++ b/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rb@@ -43,8 +43,9 @@ RSpec.describe "Work package filtering by hierarchy custom field", :js, with_ee:endendlet(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }- let!(:luke) { service.insert_item(parent: hierarchy_root, label: "luke").value! }- let!(:leia) { service.insert_item(parent: hierarchy_root, label: "leia").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:luke) { service.insert_item(contract_class:, parent: hierarchy_root, label: "luke").value! }+ let!(:leia) { service.insert_item(contract_class:, parent: hierarchy_root, label: "leia").value! }let!(:wp_luke) docreate(:work_package, project:, subject: "Luke's wp").tap do |wp|@@ -96,7 +97,7 @@ RSpec.describe "Work package filtering by hierarchy custom field", :js, with_ee:endcontext "when equals with descendants" do- let!(:grogu) { service.insert_item(parent: luke, label: "Grogu").value! }+ let!(:grogu) { service.insert_item(contract_class:, parent: luke, label: "Grogu").value! }let!(:wp_grogu) docreate(:work_package, project:, subject: "Grogu's wp").tap do |wp|wp.custom_field_values = { hierarchy_cf.id => grogu.id }diff --git a/spec/lib/api/v3/custom_fields/hierarchy/hierarchy_item_representer_rendering_spec.rb b/spec/lib/api/v3/custom_fields/hierarchy/hierarchy_item_representer_rendering_spec.rbindex 151a6553174..7a59566f457 100644--- a/spec/lib/api/v3/custom_fields/hierarchy/hierarchy_item_representer_rendering_spec.rb+++ b/spec/lib/api/v3/custom_fields/hierarchy/hierarchy_item_representer_rendering_spec.rb@@ -36,11 +36,12 @@ RSpec.describe API::V3::CustomFields::Hierarchy::HierarchyItemRepresenter, "rendlet(:custom_field) { create(:custom_field, field_format: "hierarchy", hierarchy_root: nil) }let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let!(:root) { service.generate_root(custom_field).value! }- let!(:luke) { service.insert_item(parent: root, label: "Luke", short: "LS").value! }- let!(:r2d2) { service.insert_item(parent: luke, label: "R2-D2", short: "R2").value! }- let!(:mouse) { service.insert_item(parent: r2d2, label: "Mouse Droid", short: "MD").value! }- let!(:c3po) { service.insert_item(parent: luke, label: "C-3PO", short: "3PO").value! }- let!(:mara) { service.insert_item(parent: root, label: "Mara", short: "MJ").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:luke) { service.insert_item(contract_class:, parent: root, label: "Luke", short: "LS").value! }+ let!(:r2d2) { service.insert_item(contract_class:, parent: luke, label: "R2-D2", short: "R2").value! }+ let!(:mouse) { service.insert_item(contract_class:, parent: r2d2, label: "Mouse Droid", short: "MD").value! }+ let!(:c3po) { service.insert_item(contract_class:, parent: luke, label: "C-3PO", short: "3PO").value! }+ let!(:mara) { service.insert_item(contract_class:, parent: root, label: "Mara", short: "MJ").value! }let(:user) { build_stubbed(:user) }let(:representer) { described_class.new(item, current_user: user) }diff --git a/spec/lib/open_project/journal_formatter/custom_field_spec.rb b/spec/lib/open_project/journal_formatter/custom_field_spec.rbindex 474bdfbff00..b759f9187f6 100644--- a/spec/lib/open_project/journal_formatter/custom_field_spec.rb+++ b/spec/lib/open_project/journal_formatter/custom_field_spec.rb@@ -403,8 +403,9 @@ RSpec.describe OpenProject::JournalFormatter::CustomField dolet!(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let!(:root) { custom_field.hierarchy_root }- let!(:luke) { service.insert_item(parent: root, label: "luke", short: "LS").value! }- let!(:mara) { service.insert_item(parent: luke, label: "mara").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:luke) { service.insert_item(contract_class:, parent: root, label: "luke", short: "LS").value! }+ let!(:mara) { service.insert_item(contract_class:, parent: luke, label: "mara").value! }describe "first value being nil and second value a string" dolet(:values) { [nil, mara.id.to_s] }diff --git a/spec/models/custom_field/hierarchy/item_spec.rb b/spec/models/custom_field/hierarchy/item_spec.rbindex 17c8965e86e..bba272c63e5 100644--- a/spec/models/custom_field/hierarchy/item_spec.rb+++ b/spec/models/custom_field/hierarchy/item_spec.rb@@ -37,10 +37,11 @@ RSpec.describe CustomField::Hierarchy::Item, :model, with_ee: [:custom_field_hielet(:root) { service.generate_root(custom_field).value! }context "when custom field is deleted" do- let!(:luke) { service.insert_item(parent: root, label: "luke").value! }- let!(:mara) { service.insert_item(parent: luke, label: "mara").value! }- let!(:leia) { service.insert_item(parent: root, label: "leia").value! }- let!(:kylo) { service.insert_item(parent: leia, label: "kylo").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:luke) { service.insert_item(contract_class:, parent: root, label: "luke").value! }+ let!(:mara) { service.insert_item(contract_class:, parent: luke, label: "mara").value! }+ let!(:leia) { service.insert_item(contract_class:, parent: root, label: "leia").value! }+ let!(:kylo) { service.insert_item(contract_class:, parent: leia, label: "kylo").value! }before { custom_field.reload }diff --git a/spec/models/custom_field/order_statements_spec.rb b/spec/models/custom_field/order_statements_spec.rbindex a8ad8c7b62a..53d05c869d8 100644--- a/spec/models/custom_field/order_statements_spec.rb+++ b/spec/models/custom_field/order_statements_spec.rb@@ -35,11 +35,12 @@ RSpec.describe CustomField::OrderStatements docontext "when hierarchy", with_ee: [:custom_field_hierarchies] dolet(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let(:item) { custom_field.hierarchy_root }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }subject(:custom_field) { create(:hierarchy_wp_custom_field) }before do- service.insert_item(parent: item, label: "Test")+ service.insert_item(contract_class:, parent: item, label: "Test")enddescribe "#order_statement" dodiff --git a/spec/models/exports/formatters/custom_field_hierarchy_spec.rb b/spec/models/exports/formatters/custom_field_hierarchy_spec.rbindex 11c950fac3a..57ef03d8278 100644--- a/spec/models/exports/formatters/custom_field_hierarchy_spec.rb+++ b/spec/models/exports/formatters/custom_field_hierarchy_spec.rb@@ -34,10 +34,11 @@ RSpec.describe Exports::Formatters::CustomField, with_ee: [:custom_field_hierarclet(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let(:custom_field) { create(:custom_field, field_format: "hierarchy", hierarchy_root: nil) }let(:root) { service.generate_root(custom_field).value! }- let!(:homer) { service.insert_item(parent: root, label: "Homer", short: "HS").value! }- let!(:bart) { service.insert_item(parent: homer, label: "Bart", short: "BS").value! }- let!(:lisa) { service.insert_item(parent: homer, label: "Lisa").value! }- let!(:zia) { service.insert_item(parent: lisa, label: "Zia").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:homer) { service.insert_item(contract_class:, parent: root, label: "Homer", short: "HS").value! }+ let!(:bart) { service.insert_item(contract_class:, parent: homer, label: "Bart", short: "BS").value! }+ let!(:lisa) { service.insert_item(contract_class:, parent: homer, label: "Lisa").value! }+ let!(:zia) { service.insert_item(contract_class:, parent: lisa, label: "Zia").value! }let(:work_package) docf = build_stubbed(:work_package)allow(cf)diff --git a/spec/models/queries/operators/custom_fields/hierarchies/equals_with_descendants_spec.rb b/spec/models/queries/operators/custom_fields/hierarchies/equals_with_descendants_spec.rbindex 8b339a6fddb..88aab5bac4b 100644--- a/spec/models/queries/operators/custom_fields/hierarchies/equals_with_descendants_spec.rb+++ b/spec/models/queries/operators/custom_fields/hierarchies/equals_with_descendants_spec.rb@@ -35,11 +35,12 @@ RSpec.describe Queries::Operators::CustomFields::Hierarchies::EqualsWithDescendalet(:custom_field) { create(:hierarchy_wp_custom_field, hierarchy_root: nil) }let!(:root) { service.generate_root(custom_field).value! }- let!(:germany) { service.insert_item(parent: root, label: "Germany", short: "DE").value! }- let!(:berlin) { service.insert_item(parent: germany, label: "Berlin").value! }- let!(:munich) { service.insert_item(parent: germany, label: "Munich").value! }- let!(:portugal) { service.insert_item(parent: root, label: "Portugal", short: "PT").value! }- let!(:lisbon) { service.insert_item(parent: portugal, label: "Lisboa").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:germany) { service.insert_item(contract_class:, parent: root, label: "Germany", short: "DE").value! }+ let!(:berlin) { service.insert_item(contract_class:, parent: germany, label: "Berlin").value! }+ let!(:munich) { service.insert_item(contract_class:, parent: germany, label: "Munich").value! }+ let!(:portugal) { service.insert_item(contract_class:, parent: root, label: "Portugal", short: "PT").value! }+ let!(:lisbon) { service.insert_item(contract_class:, parent: portugal, label: "Lisboa").value! }let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let(:db_table) { "custom_values" }diff --git a/spec/models/query/results_cf_sorting_integration_spec.rb b/spec/models/query/results_cf_sorting_integration_spec.rbindex 3fa511ff5ed..a3642161260 100644--- a/spec/models/query/results_cf_sorting_integration_spec.rb+++ b/spec/models/query/results_cf_sorting_integration_spec.rb@@ -351,14 +351,15 @@ RSpec.describe Query::Results, "Sorting by custom field" dolet(:custom_field) { create(:hierarchy_wp_custom_field, hierarchy_root: nil) }let(:root) { service.generate_root(custom_field).value! }let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }-- let!(:item_first) { service.insert_item(parent: root, label: "aa item").value! }- let!(:item_a) { service.insert_item(parent: root, label: "item_a").value! }- let!(:item_a1) { service.insert_item(parent: item_a, label: "item_a1").value! }- let!(:item_a2) { service.insert_item(parent: item_a, label: "item_a2").value! }- let!(:item_c) { service.insert_item(parent: root, label: "item_c").value! }- let!(:item_b) { service.insert_item(parent: root, label: "item_b").value! }- let!(:item_last) { service.insert_item(parent: root, label: "zz item").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }++ let!(:item_first) { service.insert_item(contract_class:, parent: root, label: "aa item").value! }+ let!(:item_a) { service.insert_item(contract_class:, parent: root, label: "item_a").value! }+ let!(:item_a1) { service.insert_item(contract_class:, parent: item_a, label: "item_a1").value! }+ let!(:item_a2) { service.insert_item(contract_class:, parent: item_a, label: "item_a2").value! }+ let!(:item_c) { service.insert_item(contract_class:, parent: root, label: "item_c").value! }+ let!(:item_b) { service.insert_item(contract_class:, parent: root, label: "item_b").value! }+ let!(:item_last) { service.insert_item(contract_class:, parent: root, label: "zz item").value! }let(:work_packages) do[diff --git a/spec/requests/api/v3/custom_fields/hierarchy/item_api_spec.rb b/spec/requests/api/v3/custom_fields/hierarchy/item_api_spec.rbindex 82b33b407e4..39e72aafe49 100644--- a/spec/requests/api/v3/custom_fields/hierarchy/item_api_spec.rb+++ b/spec/requests/api/v3/custom_fields/hierarchy/item_api_spec.rb@@ -36,11 +36,12 @@ RSpec.describe "API v3 custom field items", :webmock, content_type: :json, with_let(:custom_field) { create(:custom_field, field_format: "hierarchy", hierarchy_root: nil) }let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let!(:root) { service.generate_root(custom_field).value! }- let!(:luke) { service.insert_item(parent: root, label: "Luke", short: "LS").value! }- let!(:r2d2) { service.insert_item(parent: luke, label: "R2-D2", short: "R2").value! }- let!(:mouse) { service.insert_item(parent: r2d2, label: "Mouse Droid", short: "MD").value! }- let!(:c3po) { service.insert_item(parent: luke, label: "C-3PO", short: "3PO").value! }- let!(:mara) { service.insert_item(parent: root, label: "Mara", short: "MJ").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:luke) { service.insert_item(contract_class:, parent: root, label: "Luke", short: "LS").value! }+ let!(:r2d2) { service.insert_item(contract_class:, parent: luke, label: "R2-D2", short: "R2").value! }+ let!(:mouse) { service.insert_item(contract_class:, parent: r2d2, label: "Mouse Droid", short: "MD").value! }+ let!(:c3po) { service.insert_item(contract_class:, parent: luke, label: "C-3PO", short: "3PO").value! }+ let!(:mara) { service.insert_item(contract_class:, parent: root, label: "Mara", short: "MJ").value! }subject(:last_response) { get path }diff --git a/spec/requests/api/v3/custom_fields/hierarchy/items_api_spec.rb b/spec/requests/api/v3/custom_fields/hierarchy/items_api_spec.rbindex 2fddc122eee..76719237e79 100644--- a/spec/requests/api/v3/custom_fields/hierarchy/items_api_spec.rb+++ b/spec/requests/api/v3/custom_fields/hierarchy/items_api_spec.rb@@ -36,11 +36,12 @@ RSpec.describe "API v3 custom field hierarchy items", :webmock, content_type: :jdescribe "GET /api/v3/custom_fields/:id/items" dolet(:custom_field) { create(:custom_field, field_format: "hierarchy", hierarchy_root: nil) }let!(:root) { service.generate_root(custom_field).value! }- let!(:luke) { service.insert_item(parent: root, label: "Luke", short: "LS").value! }- let!(:r2d2) { service.insert_item(parent: luke, label: "R2-D2", short: "R2").value! }- let!(:mouse) { service.insert_item(parent: r2d2, label: "Mouse Droid", short: "MD").value! }- let!(:c3po) { service.insert_item(parent: luke, label: "C-3PO", short: "3PO").value! }- let!(:mara) { service.insert_item(parent: root, label: "Mara", short: "MJ").value! }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let!(:luke) { service.insert_item(contract_class:, parent: root, label: "Luke", short: "LS").value! }+ let!(:r2d2) { service.insert_item(contract_class:, parent: luke, label: "R2-D2", short: "R2").value! }+ let!(:mouse) { service.insert_item(contract_class:, parent: r2d2, label: "Mouse Droid", short: "MD").value! }+ let!(:c3po) { service.insert_item(contract_class:, parent: luke, label: "C-3PO", short: "3PO").value! }+ let!(:mara) { service.insert_item(contract_class:, parent: root, label: "Mara", short: "MJ").value! }let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }let(:path) { api_v3_paths.custom_field_items(custom_field.id) }diff --git a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rbindex 03b2036460a..76038df3732 100644--- a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb+++ b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb@@ -33,10 +33,11 @@ require "spec_helper"RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custom_field_hierarchies] dolet!(:custom_field) { create(:custom_field, field_format: "hierarchy", hierarchy_root: nil) }let!(:invalid_custom_field) { create(:custom_field, field_format: "text", hierarchy_root: nil) }+ let!(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }let!(:root) { service.generate_root(custom_field).value! }- let!(:luke) { service.insert_item(parent: root, label: "luke", short: "LS").value! }- let!(:mara) { service.insert_item(parent: luke, label: "mara").value! }+ let!(:luke) { service.insert_item(contract_class:, parent: root, label: "luke", short: "LS").value! }+ let!(:mara) { service.insert_item(contract_class:, parent: luke, label: "mara").value! }subject(:service) { described_class.new }@@ -71,30 +72,30 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custcontext "with valid parameters" doit "inserts an item successfully without short" do- result = service.insert_item(parent: luke, label:)+ result = service.insert_item(contract_class:, parent: luke, label:)expect(result).to be_successexpect(luke.reload.children.count).to eq(2)endit "inserts an item successfully with short" do- result = service.insert_item(parent: root, label:, short:)+ result = service.insert_item(contract_class:, parent: root, label:, short:)expect(result).to be_successendit "insert an item into a specific sort_order" do- leia = service.insert_item(parent: root, label: "leia").value!+ leia = service.insert_item(contract_class:, parent: root, label: "leia").value!expect(root.reload.children).to contain_exactly(luke, leia)- bob = service.insert_item(parent: root, label: "Bob", sort_order: 1).value!+ bob = service.insert_item(contract_class:, parent: root, label: "Bob", sort_order: 1).value!expect(root.reload.children).to contain_exactly(luke, bob, leia)endit "updates the position_cache" do- leia = service.insert_item(parent: root, label: "leia").value!+ leia = service.insert_item(contract_class:, parent: root, label: "leia").value!expect(root.reload.position_cache).to eq(64)- service.insert_item(parent: root, label: "Bob", sort_order: 1).value!+ service.insert_item(contract_class:, parent: root, label: "Bob", sort_order: 1).value!expect(leia.reload.position_cache).to eq(200)endend@@ -104,7 +105,7 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custchild = instance_double(CustomField::Hierarchy::Item, new_record?: true, errors: "some errors")allow(root.children).to receive(:create).and_return(child)- result = service.insert_item(parent: root, label:, short:)+ result = service.insert_item(contract_class:, parent: root, label:, short:)expect(result).to be_failureendend@@ -113,16 +114,18 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custdescribe "#update_item" docontext "with valid parameters" doit "updates the item with new attributes" do- result = service.update_item(item: luke, label: "Luke Skywalker", short: "LS")+ update_contract = CustomFields::Hierarchy::UpdateListItemContract+ result = service.update_item(contract_class: update_contract, item: luke, label: "Luke Skywalker", short: "LS")expect(result).to be_successendendcontext "with invalid parameters" do- let!(:leia) { service.insert_item(parent: root, label: "leia").value! }+ let!(:leia) { service.insert_item(contract_class:, parent: root, label: "leia").value! }it "refuses to update the item with new attributes" do- result = service.update_item(item: leia, label: "luke", short: "LS")+ update_contract = CustomFields::Hierarchy::UpdateListItemContract+ result = service.update_item(contract_class: update_contract, item: leia, label: "luke", short: "LS")expect(result).to be_failureerrors = result.failure.errors@@ -181,9 +184,9 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custenddescribe "#get_descendants" do- let!(:subitem) { service.insert_item(parent: mara, label: "Sub1").value! }- let!(:subitem2) { service.insert_item(parent: mara, label: "sub two").value! }- let!(:unrelated_subitem) { service.insert_item(parent: luke, label: "not related").value! }+ let!(:subitem) { service.insert_item(contract_class:, parent: mara, label: "Sub1").value! }+ let!(:subitem2) { service.insert_item(contract_class:, parent: mara, label: "sub two").value! }+ let!(:unrelated_subitem) { service.insert_item(contract_class:, parent: luke, label: "not related").value! }context "with a non-root node" doit "returns all the descendants to that item" do@@ -217,7 +220,7 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custenddescribe "#move_item" do- let(:lando) { service.insert_item(parent: root, label: "lando").value! }+ let(:lando) { service.insert_item(contract_class:, parent: root, label: "lando").value! }it "move the node to the new parent" doexpect { service.move_item(item: mara, new_parent: lando) }.to change { mara.reload.ancestors.first }.to(lando)@@ -239,8 +242,8 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custenddescribe "#reorder_item" do- let!(:lando) { service.insert_item(parent: root, label: "lando").value! }- let!(:chewbacca) { service.insert_item(parent: root, label: "AWOOO").value! }+ let!(:lando) { service.insert_item(contract_class:, parent: root, label: "lando").value! }+ let!(:chewbacca) { service.insert_item(contract_class:, parent: root, label: "AWOOO").value! }it "reorders the item to the target position" doservice.reorder_item(item: chewbacca, new_sort_order: 1)@@ -307,9 +310,9 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custenddescribe "#hashed_subtree" do- let!(:lando) { service.insert_item(parent: root, label: "lando").value! }- let!(:chewbacca) { service.insert_item(parent: root, label: "AWOOO").value! }- let!(:lowbacca) { service.insert_item(parent: chewbacca, label: "ARWWWW").value! }+ let!(:lando) { service.insert_item(contract_class:, parent: root, label: "lando").value! }+ let!(:chewbacca) { service.insert_item(contract_class:, parent: root, label: "AWOOO").value! }+ let!(:lowbacca) { service.insert_item(contract_class:, parent: chewbacca, label: "ARWWWW").value! }it "produces a hash version of the tree" dosubtree = service.hashed_subtree(item: root, depth: -1)