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
table_helpers: fix bug when defining multiple relations at once
Christophe Bliard6a836d758ec3
diff --git a/spec/support/table_helpers/column_type/predecessor_relations.rb b/spec/support/table_helpers/column_type/predecessor_relations.rbindex e4e3224d435..eb372bc1e7d 100644--- a/spec/support/table_helpers/column_type/predecessor_relations.rb+++ b/spec/support/table_helpers/column_type/predecessor_relations.rb@@ -60,8 +60,9 @@ module TableHelpersenddef parse_predecessors(predecessors)- relations = predecessors.map do |predecessor|- parse_predecessor(predecessor)+ relations = predecessors.to_h do |predecessor|+ relation = parse_predecessor(predecessor)+ [relation[:with], relation]end{ relations: }.compact_blankenddiff --git a/spec/support/table_helpers/column_type/related_to_relations.rb b/spec/support/table_helpers/column_type/related_to_relations.rbindex 99c709e5218..eb5cb1a8be6 100644--- a/spec/support/table_helpers/column_type/related_to_relations.rb+++ b/spec/support/table_helpers/column_type/related_to_relations.rb@@ -53,7 +53,10 @@ module TableHelpers.split(",").map(&:strip).compact_blank- .map { |name| make_related_to_relation(name) }+ .to_h do |name|+ relation = make_related_to_relation(name)+ [relation[:with], relation]+ end{ relations: }.compact_blankenddiff --git a/spec/support/table_helpers/table_data.rb b/spec/support/table_helpers/table_data.rbindex b02e13bdce7..3937cf0a0b0 100644--- a/spec/support/table_helpers/table_data.rb+++ b/spec/support/table_helpers/table_data.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -43,7 +45,7 @@ module TableHelpersattributes = columns.reduce({}) do |attrs, column|attrs.merge!(column.attributes_for_work_package(work_package))end- row = columns.to_h { [_1.title, nil] }+ row = columns.to_h { [it.title, nil] }identifier = to_identifier(work_package.subject){attributes:,@@ -87,7 +89,7 @@ module TableHelpersordered_identifiers = other_table.work_package_identifiersextra_identifiers = work_package_identifiers - ordered_identifiers@work_packages_data = work_packages_data- .index_by { _1[:identifier] }+ .index_by { it[:identifier] }.values_at(*(ordered_identifiers + extra_identifiers)).compactend@@ -178,7 +180,7 @@ module TableHelpersenddef work_package_relations(identifier)- work_package_data(identifier)[:relations] || []+ work_package_data(identifier)[:relations]&.values || []endendenddiff --git a/spec/support_spec/table_helpers/column_type/predecessor_relations_spec.rb b/spec/support_spec/table_helpers/column_type/predecessor_relations_spec.rbindex b9673a0c998..9e836ea22bc 100644--- a/spec/support_spec/table_helpers/column_type/predecessor_relations_spec.rb+++ b/spec/support_spec/table_helpers/column_type/predecessor_relations_spec.rb@@ -65,8 +65,12 @@ module TableHelpers::ColumnTypeTABLEexpect(work_package_data).to eq([- [{ raw: "follows main with lag 3", type: :follows, with: "main", lag: 3 }],- [{ raw: "main with lag 3", type: :follows, with: "main", lag: 3 }]+ {+ "main" => { raw: "follows main with lag 3", type: :follows, with: "main", lag: 3 }+ },+ {+ "main" => { raw: "main with lag 3", type: :follows, with: "main", lag: 3 }+ }])end@@ -78,8 +82,12 @@ module TableHelpers::ColumnTypeTABLEexpect(work_package_data).to eq([- [{ raw: "follows main", type: :follows, with: "main", lag: 0 }],- [{ raw: "main", type: :follows, with: "main", lag: 0 }]+ {+ "main" => { raw: "follows main", type: :follows, with: "main", lag: 0 }+ },+ {+ "main" => { raw: "main", type: :follows, with: "main", lag: 0 }+ }])end@@ -91,15 +99,15 @@ module TableHelpers::ColumnTypeTABLEexpect(work_package_data).to eq([- [- { raw: "follows wp1", type: :follows, with: "wp1", lag: 0 },- { raw: "follows wp2", type: :follows, with: "wp2", lag: 0 }- ],- [- { raw: "follows wp1", type: :follows, with: "wp1", lag: 0 },- { raw: "wp2", type: :follows, with: "wp2", lag: 0 },- { raw: "wp3", type: :follows, with: "wp3", lag: 0 }- ]+ {+ "wp1" => { raw: "follows wp1", type: :follows, with: "wp1", lag: 0 },+ "wp2" => { raw: "follows wp2", type: :follows, with: "wp2", lag: 0 }+ },+ {+ "wp1" => { raw: "follows wp1", type: :follows, with: "wp1", lag: 0 },+ "wp2" => { raw: "wp2", type: :follows, with: "wp2", lag: 0 },+ "wp3" => { raw: "wp3", type: :follows, with: "wp3", lag: 0 }+ }])endenddiff --git a/spec/support_spec/table_helpers/column_type/related_to_relations_spec.rb b/spec/support_spec/table_helpers/column_type/related_to_relations_spec.rbindex 0a20467df21..d9b22cd416c 100644--- a/spec/support_spec/table_helpers/column_type/related_to_relations_spec.rb+++ b/spec/support_spec/table_helpers/column_type/related_to_relations_spec.rb@@ -64,7 +64,9 @@ module TableHelpers::ColumnTypeTABLEexpect(work_package_data).to eq([- [{ raw: "main", type: :relates, with: "main" }]+ {+ "main" => { raw: "main", type: :relates, with: "main" }+ }])end@@ -75,11 +77,11 @@ module TableHelpers::ColumnTypeTABLEexpect(work_package_data).to eq([- [- { raw: "wp1", type: :relates, with: "wp1" },- { raw: "wp2", type: :relates, with: "wp2" },- { raw: "wp3", type: :relates, with: "wp3" }- ]+ {+ "wp1" => { raw: "wp1", type: :relates, with: "wp1" },+ "wp2" => { raw: "wp2", type: :relates, with: "wp2" },+ "wp3" => { raw: "wp3", type: :relates, with: "wp3" }+ }])endenddiff --git a/spec/support_spec/table_helpers/column_type/relations_spec.rb b/spec/support_spec/table_helpers/column_type/relations_spec.rbnew file mode 100644index 00000000000..902b982e671--- /dev/null+++ b/spec/support_spec/table_helpers/column_type/relations_spec.rb@@ -0,0 +1,63 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"++module TableHelpers::ColumnType+ RSpec.describe "Relations" do+ subject(:column_type) { described_class.new }++ def parsed_data(table)+ TableHelpers::TableParser.new.parse(table)+ end++ it "can merge relations from multiple relation columns" do+ work_package_data = parsed_data(<<~TABLE).pluck(:relations)+ | predecessors | relates to |+ | main | |+ | | related wp |+ | main with lag 3 | related wp |+ TABLE+ expect(work_package_data)+ .to eq([+ {+ "main" => { raw: "main", type: :follows, with: "main", lag: 0 }+ },+ {+ "related wp" => { raw: "related wp", type: :relates, with: "related wp" }+ },+ {+ "main" => { raw: "main with lag 3", type: :follows, with: "main", lag: 3 },+ "related wp" => { raw: "related wp", type: :relates, with: "related wp" }+ }+ ])+ end+ end+enddiff --git a/spec/support_spec/table_helpers/table_data_spec.rb b/spec/support_spec/table_helpers/table_data_spec.rbindex 581437a8f68..eefda8e5c6b 100644--- a/spec/support_spec/table_helpers/table_data_spec.rb+++ b/spec/support_spec/table_helpers/table_data_spec.rb@@ -193,6 +193,25 @@ module TableHelpersexpect(other.relations.relates.first.lag).to be_nilend+ it "can creates 'follows' and 'relates' relations at the same time out of the table data" do+ table_representation = <<~TABLE+ subject | related to | predecessors+ pred | |+ other | |+ main | other | pred+ TABLE++ table_data = described_class.for(table_representation)+ table = table_data.create_work_packages+ expect(table.work_packages.count).to eq(3)+ pred = table.work_package(:pred)+ other = table.work_package(:other)+ main = table.work_package(:main)+ expect(main.relations.count).to eq(2)+ expect(main.relations.relates.first.to).to eq(other)+ expect(main.relations.follows.first.to).to eq(pred)+ end+it "raises an error if a given status name does not exist" dotable_representation = <<~TABLEsubject | status |