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

Prevent date overflow on time_entries.spent_on during cost_report query type casting

Dombi Attila29f49d20893a
diff --git a/modules/costs/app/contracts/time_entries/base_contract.rb b/modules/costs/app/contracts/time_entries/base_contract.rb
index 031a72c8d9c..e007263d92a 100644
--- a/modules/costs/app/contracts/time_entries/base_contract.rb
+++ b/modules/costs/app/contracts/time_entries/base_contract.rb
@@ -46,7 +46,7 @@ module TimeEntries
validate :validate_work_package
validates :spent_on,
- date: { before_or_equal_to: Proc.new { Time.zone.today },
+ date: { before_or_equal_to: Proc.new { Date.new(9999, 12, 31) },
allow_blank: true },
unless: Proc.new { spent_on.blank? }
diff --git a/modules/costs/spec/contracts/time_entries/shared_contract_examples.rb b/modules/costs/spec/contracts/time_entries/shared_contract_examples.rb
index 0b766fc5fd2..bce63626940 100644
--- a/modules/costs/spec/contracts/time_entries/shared_contract_examples.rb
+++ b/modules/costs/spec/contracts/time_entries/shared_contract_examples.rb
@@ -48,13 +48,13 @@ shared_examples_for 'time entry contract' do
build_stubbed(:time_entry_activity)
end
let(:time_entry_activity_active) { true }
- let(:time_entry_spent_on) { Date.today }
+ let(:time_entry_spent_on) { Time.zone.today }
let(:time_entry_hours) { 5 }
let(:time_entry_comments) { "A comment" }
let(:work_package_visible) { true }
let(:time_entry_day_sum) { 5 }
let(:activities_scope) do
- scope = double('activities')
+ scope = class_double(TimeEntryActivity)
if time_entry_activity
allow(scope)
@@ -78,7 +78,7 @@ shared_examples_for 'time entry contract' do
.to receive(:active_in_project)
.and_return(TimeEntryActivity.none)
- of_user_and_day_scope = double('of_user_and_day_scope')
+ of_user_and_day_scope = instance_double(ActiveRecord::Relation)
allow(TimeEntry)
.to receive(:of_user_and_day)
@@ -162,14 +162,22 @@ shared_examples_for 'time entry contract' do
end
end
- context 'when spent_on is in the future' do
- let(:time_entry_spent_on) { Time.zone.tomorrow }
+ context 'when spent_on is outside the year limits to prevent overflow in postgres' do
+ let(:time_entry_spent_on) { Date.new(10000) }
it 'is invalid' do
expect_valid(false, spent_on: %i(date_before_or_equal_to))
end
end
+ context 'when spent_on is in the future' do
+ let(:time_entry_spent_on) { Date.new(9999) }
+
+ it 'is valid' do
+ expect_valid(true)
+ end
+ end
+
context 'when spent_on is today' do
let(:time_entry_spent_on) { Time.zone.today }
@@ -202,14 +210,6 @@ shared_examples_for 'time entry contract' do
end
end
- context 'when hours is nil' do
- let(:time_entry_hours) { nil }
-
- it 'is invalid' do
- expect_valid(false, hours: %i(blank))
- end
- end
-
context 'when comment is longer than 255' do
let(:time_entry_comments) { "a" * 256 }
@@ -251,8 +251,8 @@ shared_examples_for 'time entry contract' do
end
describe 'assignable_versions' do
- let(:project_versions) { double('project versions') }
- let(:wp_versions) { double('work_package versions') }
+ let(:project_versions) { [instance_double(Version)] }
+ let(:wp_versions) { [instance_double(Version)] }
before do
if time_entry_project