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
also update attributes when parent_id is signaled to be updated
ulfertsfa7e469051d6
diff --git a/app/services/work_packages/update_ancestors_service.rb b/app/services/work_packages/update_ancestors_service.rbindex eab66517a75..3f9cec11822 100644--- a/app/services/work_packages/update_ancestors_service.rb+++ b/app/services/work_packages/update_ancestors_service.rb@@ -100,7 +100,7 @@ class WorkPackages::UpdateAncestorsServiceenddef inherit?(attributes, attribute)- [attribute, :parent].any? { |attr| attributes.include? attr }+ [attribute, :parent, :parent_id].any? { |attr| attributes.include? attr }enddef set_journal_note(work_packages)diff --git a/spec/services/work_packages/update_ancestors_service_spec.rb b/spec/services/work_packages/update_ancestors_service_spec.rbindex 5e5c05fa4cb..7bf5f691e46 100644--- a/spec/services/work_packages/update_ancestors_service_spec.rb+++ b/spec/services/work_packages/update_ancestors_service_spec.rb@@ -67,10 +67,10 @@ describe WorkPackages::UpdateAncestorsService, type: :model dolet(:children) do(statuses.size - 1).downto(0).map do |i|FactoryBot.create :work_package,- parent: parent,- status: statuses[i] == :open ? open_status : closed_status,- estimated_hours: estimated_hours[i],- done_ratio: done_ratios[i]+ parent: parent,+ status: statuses[i] == :open ? open_status : closed_status,+ estimated_hours: estimated_hours[i],+ done_ratio: done_ratios[i]endendlet(:parent) { FactoryBot.create :work_package, status: open_status }@@ -199,10 +199,10 @@ describe WorkPackages::UpdateAncestorsService, type: :model doendlet!(:sibling) doFactoryBot.create :work_package,- parent: parent,- status: sibling_status,- estimated_hours: sibling_estimated_hours,- done_ratio: sibling_done_ratio+ parent: parent,+ status: sibling_status,+ estimated_hours: sibling_estimated_hours,+ done_ratio: sibling_done_ratioendlet!(:work_package) do@@ -265,58 +265,79 @@ describe WorkPackages::UpdateAncestorsService, type: :model doendlet!(:parent) doFactoryBot.create :work_package,- parent: grandparent+ parent: grandparentendlet!(:work_package) doFactoryBot.create :work_package,- status: status,- estimated_hours: estimated_hours,- done_ratio: done_ratio+ status: status,+ estimated_hours: estimated_hours,+ done_ratio: done_ratioend- subject do- work_package.parent = parent- work_package.save!- work_package.parent_id_was+ shared_examples_for 'updates the attributes within the new hierarchy' do+ before do+ subject+ end- described_class- .new(user: user,- work_package: work_package)- .call(%i(parent))- end+ it 'is successful' do+ expect(subject)+ .to be_success+ end- before do- subject- end+ it 'returns the new ancestors in the dependent results' do+ expect(subject.dependent_results.map(&:result))+ .to match_array [parent, grandparent]+ end- it 'is successful' do- expect(subject)- .to be_success- end+ it 'updates the done_ratio of the new parent' do+ expect(parent.reload(select: :done_ratio).done_ratio)+ .to eql done_ratio+ end- it 'returns the new ancestors in the dependent results' do- expect(subject.dependent_results.map(&:result))- .to match_array [parent, grandparent]- end+ it 'updates the estimated_hours of the new parent' do+ expect(parent.reload(select: :derived_estimated_hours).derived_estimated_hours)+ .to eql estimated_hours+ end- it 'updates the done_ratio of the new parent' do- expect(parent.reload(select: :done_ratio).done_ratio)- .to eql done_ratio- end+ it 'updates the done_ratio of the new grandparent' do+ expect(grandparent.reload(select: :done_ratio).done_ratio)+ .to eql done_ratio+ end- it 'updates the estimated_hours of the new parent' do- expect(parent.reload(select: :derived_estimated_hours).derived_estimated_hours)- .to eql estimated_hours+ it 'updates the estimated_hours of the new grandparent' do+ expect(grandparent.reload(select: :derived_estimated_hours).derived_estimated_hours)+ .to eql estimated_hours+ endend- it 'updates the done_ratio of the new grandparent' do- expect(grandparent.reload(select: :done_ratio).done_ratio)- .to eql done_ratio+ context 'if setting the parent' do+ subject do+ work_package.parent = parent+ work_package.save!+ work_package.parent_id_was++ described_class+ .new(user: user,+ work_package: work_package)+ .call(%i(parent))+ end++ it_behaves_like 'updates the attributes within the new hierarchy'end- it 'updates the estimated_hours of the new grandparent' do- expect(grandparent.reload(select: :derived_estimated_hours).derived_estimated_hours)- .to eql estimated_hours+ context 'if setting the parent_id' do+ subject do+ work_package.parent_id = parent.id+ work_package.save!+ work_package.parent_id_was++ described_class+ .new(user: user,+ work_package: work_package)+ .call(%i(parent_id))+ end++ it_behaves_like 'updates the attributes within the new hierarchy'endendend