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
Raise an error if there are more cells than headers in a row
Christophe Bliardd728ea37db30
diff --git a/spec/support/table_helpers/table_parser.rb b/spec/support/table_helpers/table_parser.rbindex 4ac10ceee87..c3faa62614b 100644--- a/spec/support/table_helpers/table_parser.rb+++ b/spec/support/table_helpers/table_parser.rb@@ -33,6 +33,10 @@ module TableHelpersdef parse(representation)headers, *rows = representation.split("\n").filter_map { |line| split_line_into_cells(line) }work_packages_data = rows.map.with_index do |cells, index|+ if cells.size > headers.size+ raise ArgumentError, "Too many cells in row #{index + 1}, have you forgotten some headers?"+ end+{attributes: {},index:,diff --git a/spec/support_spec/table_helpers/table_parser_spec.rb b/spec/support_spec/table_helpers/table_parser_spec.rbindex 843d500cd13..2e5358ec574 100644--- a/spec/support_spec/table_helpers/table_parser_spec.rb+++ b/spec/support_spec/table_helpers/table_parser_spec.rb@@ -73,6 +73,25 @@ RSpec.describe TableHelpers::TableParser do.to raise_error(ArgumentError, 'Please use "remaining work" instead of "remaining hours"')end+ it "raises an error if there are more cells than headers in a row" do+ table = <<~TABLE+ subject | work+ wp | 4h | 6h+ TABLE+ expect { described_class.new.parse(table) }+ .to raise_error(ArgumentError, "Too many cells in row 1, have you forgotten some headers?")+ end++ it "is ok to have more headers than cells (value of missing cells will be nil)" do+ table = <<~TABLE+ subject | work | remaining work+ wp | 4h+ TABLE+ parsed_data = described_class.new.parse(table)+ expect(parsed_data.dig(0, :attributes, :estimated_hours)).to eq(4.0)+ expect(parsed_data.dig(0, :attributes, :remaining_hours)).to be_nil+ end+describe "subject column" dolet(:table) do<<~TABLE