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 helper can have first line being a comment

Christophe Bliard4e05da24c126
diff --git a/spec/support/table_helpers/table_parser.rb b/spec/support/table_helpers/table_parser.rb
index 80466f3e45d..4ac10ceee87 100644
--- a/spec/support/table_helpers/table_parser.rb
+++ b/spec/support/table_helpers/table_parser.rb
@@ -31,14 +31,12 @@
module TableHelpers
class TableParser
def parse(representation)
- headers, *rows = representation.split("\n")
- headers = split(headers)
- rows = rows.filter_map { |row| parse_row(row, headers) }
- work_packages_data = rows.map.with_index do |row, index|
+ headers, *rows = representation.split("\n").filter_map { |line| split_line_into_cells(line) }
+ work_packages_data = rows.map.with_index do |cells, index|
{
attributes: {},
index:,
- row:
+ row: headers.zip(cells).to_h
}
end
headers.each do |header|
@@ -50,13 +48,12 @@ module TableHelpers
private
- def parse_row(row, headers)
- case row
+ def split_line_into_cells(line)
+ case line
when "", /^\s*#/
# noop
else
- values = split(row)
- headers.zip(values).to_h
+ split(line)
end
end
diff --git a/spec/support_spec/table_helpers/table_parser_spec.rb b/spec/support_spec/table_helpers/table_parser_spec.rb
index 12d0b34e2f1..843d500cd13 100644
--- a/spec/support_spec/table_helpers/table_parser_spec.rb
+++ b/spec/support_spec/table_helpers/table_parser_spec.rb
@@ -53,6 +53,7 @@ RSpec.describe TableHelpers::TableParser do
it "ignores comments and empty lines" do
table = <<~TABLE
+ # this comment is ignored
| subject |
# this comment and the following empty line are ignored