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

add test for gantt chart export rejecting with a too long range

as-opb86e36674c43
diff --git a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb
index 1fc3aba1d00..01b34feb97f 100644
--- a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb
+++ b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb
@@ -58,6 +58,7 @@ end
RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
include Redmine::I18n
include PDFExportSpecUtils
+
let!(:status_new) { create(:status, name: "New", is_default: true) }
let(:type_standard) { create(:type_standard, name: "Standard", color: create(:color, hexcode: "#FFFF00")) }
let(:type_bug) { create(:type_bug, name: "Bug", color: create(:color, hexcode: "#00FFFF")) }
@@ -104,6 +105,9 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
let(:work_package_task_due) do
Date.new(2024, 4, 21)
end
+ let(:work_package_task_due_too_long) do
+ work_package_task_due + (Exports::PDF::Components::Gantt::GanttBuilder::MAX_YEAR_RANGE + 1).years
+ end
let(:work_package_milestone_start) do
nil
end
@@ -128,6 +132,15 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
start_date: work_package_milestone_start,
due_date: work_package_milestone_due)
end
+ let(:work_package_task_far_future) do
+ create(:work_package,
+ project:,
+ status: status_new,
+ type: type_standard,
+ subject: "Work package 3",
+ start_date: work_package_task_start,
+ due_date: work_package_task_due_too_long)
+ end
let(:filler_work_packages) do
Array.new(50) do
create(:work_package,
@@ -390,4 +403,18 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
expect(include_calls?(task, pdf[:calls])).to be true
end
end
+
+ describe "with a request for a PDF gantt with too long date range" do
+ let(:work_packages) { [work_package_task_far_future] }
+
+ it "raises as the date range is too long" do
+ expect { export_pdf }.to raise_error(
+ Exports::ExportError,
+ I18n.t(
+ :error_pdf_date_range_too_long,
+ years: Exports::PDF::Components::Gantt::GanttBuilder::MAX_YEAR_RANGE
+ )
+ )
+ end
+ end
end