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
Fix undefined method ancestors_relations used in Task
Christophe Bliarda256c946dc14
diff --git a/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rbindex 111612a982e..c77f5c2350f 100644--- a/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb+++ b/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb@@ -106,13 +106,9 @@ module OpenProject::Backlogs::Patches::WorkPackagePatchif is_story?Story.find(id)elsif is_task?- # Make sure to get the closest ancestor that is a Story- ancestors_relations- .includes(:from)- .where(from: { type_id: Story.types })- .order(hierarchy: :asc)+ ancestors+ .where(type_id: Story.types).first- .fromendenddiff --git a/modules/backlogs/spec/models/work_package_spec.rb b/modules/backlogs/spec/models/work_package_spec.rbindex 05ecc730858..4516e9854b0 100644--- a/modules/backlogs/spec/models/work_package_spec.rb+++ b/modules/backlogs/spec/models/work_package_spec.rb@@ -26,28 +26,72 @@# See COPYRIGHT and LICENSE files for more details.#++-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')+require_relative '../spec_helper'describe WorkPackage dodescribe '#backlogs_types' doit 'returns all the ids of types that are configures to be considered backlogs types' doallow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [1], 'task_type' => 2 })- expect(WorkPackage.backlogs_types).to match_array([1, 2])+ expect(described_class.backlogs_types).to match_array([1, 2])endit 'returns an empty array if nothing is defined' doallow(Setting).to receive(:plugin_openproject_backlogs).and_return({})- expect(WorkPackage.backlogs_types).to eq([])+ expect(described_class.backlogs_types).to eq([])endit 'reflects changes to the configuration' doallow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [1], 'task_type' => 2 })- expect(WorkPackage.backlogs_types).to match_array([1, 2])+ expect(described_class.backlogs_types).to match_array([1, 2])allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [3], 'task_type' => 4 })- expect(WorkPackage.backlogs_types).to match_array([3, 4])+ expect(described_class.backlogs_types).to match_array([3, 4])+ end+ end++ describe '#story' do+ shared_let(:project) { create(:project) }+ shared_let(:status) { create(:status) }+ shared_let(:story_type) { create(:type, name: 'Story') }+ shared_let(:task_type) { create(:type, name: 'Task') }++ before do+ allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [story_type.id],+ 'task_type' => task_type.id })+ end++ context 'for a WorkPackage' do+ let(:work_package) { build_stubbed(:work_package) }++ it 'returns nil' do+ expect(work_package.story).to be_nil+ end+ end++ context 'for a Story' do+ let(:story) { create(:story, project:, status:, type: story_type) }++ it 'returns self' do+ expect(story.story).to eq(story)+ end+ end++ context 'for a Task' do+ let(:parent_parent_story) { create(:story, project:, status:, type: story_type) }+ let(:parent_story) { create(:story, parent: parent_parent_story, project:, status:, type: story_type) }+ let(:task) { create(:task, parent: parent_story, project:, status:, type: task_type) }++ it 'returns the closest WorkPackage ancestor being a Story' do+ expect(task.story).to eq(described_class.find(parent_story.id))++ # transform the parent_story into a task+ parent_story.update(type: task_type)++ # the returned story is now the grand parent+ expect(task.story).to eq(described_class.find(parent_parent_story.id))+ endendendend