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
refactor: avoid using Hashie::Mash
Christophe Bliard83564887c62f
diff --git a/app/services/work_packages/update_ancestors/loader.rb b/app/services/work_packages/update_ancestors/loader.rbindex bebb80880e2..21eda6038a1 100644--- a/app/services/work_packages/update_ancestors/loader.rb+++ b/app/services/work_packages/update_ancestors/loader.rb@@ -104,7 +104,7 @@ class WorkPackages::UpdateAncestors::Loaderattributes = selected_descendants_attributesscope.pluck(*attributes)- .map { |p| LoaderStruct.new(attributes.zip(p).to_h) }+ .map { |p| WorkPackageLikeStruct.new(**attributes.zip(p).to_h) }end# Returns the current ancestors sorted by distance (called generations in the table)@@ -126,7 +126,7 @@ class WorkPackages::UpdateAncestors::Loaderdef selected_descendants_attributes# By having the id in here, we can avoid DISTINCT queries squashing duplicate values- %i[id estimated_hours parent_id schedule_manually ignore_non_working_days remaining_hours]+ %i[id parent_id estimated_hours remaining_hours schedule_manually ignore_non_working_days]end##@@ -152,6 +152,7 @@ class WorkPackages::UpdateAncestors::Loaderprevious_parent_changes&.firstend- class LoaderStruct < Hashie::Mash; end- LoaderStruct.disable_warnings+ WorkPackageLikeStruct = Data.define(:id, :parent_id,+ :estimated_hours, :remaining_hours,+ :schedule_manually, :ignore_non_working_days)enddiff --git a/spec/services/work_packages/update_ancestors/loader_spec.rb b/spec/services/work_packages/update_ancestors/loader_spec.rbindex 0b4f7c70bd2..6e20a2ca707 100644--- a/spec/services/work_packages/update_ancestors/loader_spec.rb+++ b/spec/services/work_packages/update_ancestors/loader_spec.rb@@ -223,67 +223,55 @@ RSpec.describe WorkPackages::UpdateAncestors::Loader, type: :model doendend- describe "#descendants_of" do- def descendants_of_hash(hashed_work_package)- { "estimated_hours" => nil,- "id" => hashed_work_package.id,- "ignore_non_working_days" => false,- "parent_id" => hashed_work_package.parent_id,- "remaining_hours" => nil,- "schedule_manually" => false }- end+ def work_package_struct(work_package)+ attribute_names = WorkPackages::UpdateAncestors::Loader::WorkPackageLikeStruct.members.map(&:to_s)+ attributes = work_package.attributes.slice(*attribute_names)+ WorkPackages::UpdateAncestors::Loader::WorkPackageLikeStruct.new(**attributes)+ end+ describe "#descendants_of" docontext "for the work_package" do- it "is its child (as a hash)" do+ it "is its child (as a struct)" doexpect(instance.descendants_of(work_package))- .to contain_exactly(descendants_of_hash(child))+ .to contain_exactly(work_package_struct(child))endendcontext "for the parent" do- it "is the work package, its child (as a hash) and its sibling (as a hash)" do+ it "is the work package, its child (as a struct) and its sibling (as a struct)" doexpect(instance.descendants_of(parent))- .to contain_exactly(descendants_of_hash(child), work_package, descendants_of_hash(sibling))+ .to contain_exactly(work_package_struct(child), work_package, work_package_struct(sibling))endendcontext "for the grandparent" do- it "is the parent, the work package, its child (as a hash) and its sibling (as a hash)" do+ it "is the parent, the work package, its child (as a struct) and its sibling (as a struct)" doexpect(instance.descendants_of(grandparent))- .to contain_exactly(parent, work_package, descendants_of_hash(child), descendants_of_hash(sibling))+ .to contain_exactly(parent, work_package, work_package_struct(child), work_package_struct(sibling))endendcontext "for the grandgrandparent (the root)" do- it "is the complete tree, partly as a hash and partly as the preloaded work packages" do+ it "is the complete tree, partly as a struct and partly as the preloaded work packages" doexpect(instance.descendants_of(grandgrandparent))- .to contain_exactly(descendants_of_hash(grandparent_sibling), grandparent, parent, work_package,- descendants_of_hash(child), descendants_of_hash(sibling))+ .to contain_exactly(work_package_struct(grandparent_sibling), grandparent, parent, work_package,+ work_package_struct(child), work_package_struct(sibling))endendenddescribe "#children_of" do- def children_of_hash(hashed_work_package)- { "estimated_hours" => nil,- "id" => hashed_work_package.id,- "ignore_non_working_days" => false,- "parent_id" => hashed_work_package.parent_id,- "remaining_hours" => nil,- "schedule_manually" => false }- end-context "for the work_package" do- it "is its child (as a hash)" do+ it "is its child (as a struct)" doexpect(instance.children_of(work_package))- .to contain_exactly(children_of_hash(child))+ .to contain_exactly(work_package_struct(child))endendcontext "for the parent" do- it "is the work package and its sibling (as a hash)" do+ it "is the work package and its sibling (as a struct)" doexpect(instance.children_of(parent))- .to contain_exactly(work_package, children_of_hash(sibling))+ .to contain_exactly(work_package, work_package_struct(sibling))endend@@ -295,9 +283,9 @@ RSpec.describe WorkPackages::UpdateAncestors::Loader, type: :model doendcontext "for the grandgrandparent" do- it "is the grandparent and its sibling (as a hash)" do+ it "is the grandparent and its sibling (as a struct)" doexpect(instance.children_of(grandgrandparent))- .to contain_exactly(children_of_hash(grandparent_sibling), grandparent)+ .to contain_exactly(work_package_struct(grandparent_sibling), grandparent)endendend