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
Replace build_work_package_hierarchy with let_work_packages
Christophe Bliardd230fcd1f7ff
diff --git a/spec/features/work_packages/display_fields/estimated_hours_display_spec.rb b/spec/features/work_packages/display_fields/estimated_hours_display_spec.rbindex c5faf425039..9d3cd0c9c6f 100644--- a/spec/features/work_packages/display_fields/estimated_hours_display_spec.rb+++ b/spec/features/work_packages/display_fields/estimated_hours_display_spec.rb@@ -29,31 +29,20 @@require 'spec_helper'RSpec.describe 'Estimated hours display' do- let(:user) { create(:admin) }- let(:project) { create(:project) }-- let(:hierarchy) { [] }-- let!(:work_packages) do- build_work_package_hierarchy(- hierarchy,- :subject,- :estimated_hours,- shared_attributes: {- project:- }- )+ shared_let(:project) { create(:project) }+ shared_let(:user) { create(:admin) }+ shared_let(:query) do+ create(:query,+ project:,+ user:,+ show_hierarchies: true,+ column_names: %i[id subject estimated_hours])end- let(:parent) { work_packages.first }- let(:child) { work_packages.last }-- let!(:query) do- query = build(:query, user:, project:)- query.column_names = %w[id subject estimated_hours]-- query.save!- query+ before_all do+ set_factory_default(:project, project)+ set_factory_default(:project_with_types, project)+ set_factory_default(:user, user)endlet(:wp_table) { Pages::WorkPackagesTable.new project }@@ -67,15 +56,11 @@ RSpec.describe 'Estimated hours display' doendcontext "with both work and derived work" do- let(:hierarchy) do- [- {- ["Parent", 1] => [- ["Child", 3]- ]- }- ]- end+ let_work_packages(<<~TABLE)+ hierarchy | work |+ parent | 1h |+ child | 3h |+ TABLEit 'work package index', :js dowp_table.visit_query query@@ -94,15 +79,11 @@ RSpec.describe 'Estimated hours display' doendcontext "with just work" do- let(:hierarchy) do- [- {- ["Parent", 1] => [- ["Child", 0]- ]- }- ]- end+ let_work_packages(<<~TABLE)+ hierarchy | work |+ parent | 1h |+ child | 0h |+ TABLEit 'work package index', :js dowp_table.visit_query query@@ -121,15 +102,11 @@ RSpec.describe 'Estimated hours display' doendcontext "with just derived work with (parent work 0 h)" do- let(:hierarchy) do- [- {- ["Parent", 0] => [- ["Child", 3]- ]- }- ]- end+ let_work_packages(<<~TABLE)+ hierarchy | work |+ parent | 0h |+ child | 3h |+ TABLEit 'work package index', :js dowp_table.visit_query query@@ -148,15 +125,11 @@ RSpec.describe 'Estimated hours display' doendcontext "with just derived work (parent work unset)" do- let(:hierarchy) do- [- {- ["Parent", nil] => [- ["Child", 3]- ]- }- ]- end+ let_work_packages(<<~TABLE)+ hierarchy | work |+ parent | |+ child | 3h |+ TABLEit 'work package index', :js dowp_table.visit_query query@@ -175,15 +148,11 @@ RSpec.describe 'Estimated hours display' doendcontext "with neither work nor derived work (both 0 h)" do- let(:hierarchy) do- [- {- ["Parent", 0] => [- ["Child", 0]- ]- }- ]- end+ let_work_packages(<<~TABLE)+ hierarchy | work |+ parent | 0h |+ child | 0h |+ TABLEit 'work package index', :js dowp_table.visit_query query@@ -202,15 +171,11 @@ RSpec.describe 'Estimated hours display' doendcontext "with neither work nor derived work (both unset)" do- let(:hierarchy) do- [- {- ["Parent", nil] => [- ["Child", nil]- ]- }- ]- end+ let_work_packages(<<~TABLE)+ hierarchy | work |+ parent | |+ child | |+ TABLEit 'work package index', :js dowp_table.visit_query querydiff --git a/spec/support/work_packages.rb b/spec/support/work_packages.rbindex d0ac2963c70..ee9faf7b417 100644--- a/spec/support/work_packages.rb+++ b/spec/support/work_packages.rb@@ -61,28 +61,3 @@ enddef become_member_with_move_work_package_permissionsbecome_member_with_permissions [:move_work_packages]end--def build_work_package_hierarchy(data, *attributes, parent: nil, shared_attributes: {})- work_packages = []-- Array(data).each do |attr|- if attr.is_a? Hash- parent_wp = create(- :work_package, shared_attributes.merge(**attributes.zip(attr.keys.first).to_h)- )-- work_packages << parent_wp- work_packages += build_work_package_hierarchy(- attr.values.first, *attributes, parent: parent_wp, shared_attributes:- )- else- wp = create(:work_package, shared_attributes.merge(**attributes.zip(attr).to_h))-- parent.children << wp if parent-- work_packages << wp- end- end-- work_packages-end