Merge pull request #11111 from opf/fix-time-entries-spec

Prevent date overflow on time_entries.spent_on
pull/11114/head
Christophe Bliard 2 years ago committed by GitHub
commit ef2f7a0bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/costs/app/contracts/time_entries/base_contract.rb
  2. 30
      modules/costs/spec/contracts/time_entries/shared_contract_examples.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? }

@ -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

Loading…
Cancel
Save