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

[#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.rb
index 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 CustomFields
end
# 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 CustomFields
end
# 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_monad
diff --git a/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb
index 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.rb
index 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 do
subject { 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.rb
index 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 do
subject { 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.rb
index 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 do
subject { 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.rb
index 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 do
subject { 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.rb
index 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: [:custo
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").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: [:custo
describe "PUT #move" do
before 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")
end
context "when it is successful" do
diff --git a/spec/features/admin/custom_fields/work_packages/hierarchy_spec.rb b/spec/features/admin/custom_fields/work_packages/hierarchy_spec.rb
index 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 do
let(: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 do
diff --git a/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rb b/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rb
index 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:
end
end
let(: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) do
create(: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:
end
context "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) do
create(: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.rb
index 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, "rend
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! }
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.rb
index 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 do
let!(: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" do
let(: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.rb
index 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_hie
let(: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.rb
index 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 do
context "when hierarchy", with_ee: [:custom_field_hierarchies] do
let(: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")
end
describe "#order_statement" do
diff --git a/spec/models/exports/formatters/custom_field_hierarchy_spec.rb b/spec/models/exports/formatters/custom_field_hierarchy_spec.rb
index 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_hierarc
let(: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) do
cf = 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.rb
index 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::EqualsWithDescenda
let(: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.rb
index 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" do
let(: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.rb
index 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.rb
index 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: :j
describe "GET /api/v3/custom_fields/:id/items" do
let(: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.rb
index 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] do
let!(: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: [:cust
context "with valid parameters" do
it "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_success
expect(luke.reload.children.count).to eq(2)
end
it "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_success
end
it "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)
end
it "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)
end
end
@@ -104,7 +105,7 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:cust
child = 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_failure
end
end
@@ -113,16 +114,18 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:cust
describe "#update_item" do
context "with valid parameters" do
it "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_success
end
end
context "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_failure
errors = result.failure.errors
@@ -181,9 +184,9 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:cust
end
describe "#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" do
it "returns all the descendants to that item" do
@@ -217,7 +220,7 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:cust
end
describe "#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" do
expect { 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: [:cust
end
describe "#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" do
service.reorder_item(item: chewbacca, new_sort_order: 1)
@@ -307,9 +310,9 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:cust
end
describe "#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" do
subtree = service.hashed_subtree(item: root, depth: -1)