Skip to content

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

table_helpers: Fix issue with empty tables

Christophe Bliard59825de67722
diff --git a/spec/support/table_helpers/table_representer.rb b/spec/support/table_helpers/table_representer.rb
index aa6171ecbe8..e14dab90447 100644
--- a/spec/support/table_helpers/table_representer.rb
+++ b/spec/support/table_helpers/table_representer.rb
@@ -102,7 +102,7 @@ module TableHelpers
else
values = tables_data.flat_map { _1.values_for_attribute(column.attribute) }
values_max_size = values.map { column.format(_1).size }.max
- [column.title.size, values_max_size].max
+ [column.title.size, values_max_size].compact.max
end
end
end
diff --git a/spec/support_spec/table_helpers/table_representer_spec.rb b/spec/support_spec/table_helpers/table_representer_spec.rb
index 26fe75ba594..bf979773eb8 100644
--- a/spec/support_spec/table_helpers/table_representer_spec.rb
+++ b/spec/support_spec/table_helpers/table_representer_spec.rb
@@ -68,6 +68,19 @@ module TableHelpers
end
end
+ context "when there are no work packages" do
+ let(:table_data) do
+ TableData.from_work_packages([], columns)
+ end
+ let(:columns) { [Column.for("subject")] }
+
+ it "renders no rows" do
+ expect(representer.render(table_data)).to eq <<~TABLE
+ | subject |
+ TABLE
+ end
+ end
+
describe "subject column" do
let(:columns) { [Column.for("subject")] }
@@ -131,6 +144,18 @@ module TableHelpers
TABLE
end
+ context "when there are no work packages" do
+ let(:table_data) do
+ TableData.from_work_packages([], columns)
+ end
+
+ it "renders no rows" do
+ expect(representer.render(table_data)).to eq <<~TABLE
+ | MTWTFSS |
+ TABLE
+ end
+ end
+
context "when non working days are defined" do
let(:table) do
<<~TABLE