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

Return validation error if duration does not match

Christophe Bliard469474efbedb
diff --git a/spec/contracts/work_packages/base_contract_spec.rb b/spec/contracts/work_packages/base_contract_spec.rb
index 5f9b4c8b6ee..e2a1f1ad1fa 100644
--- a/spec/contracts/work_packages/base_contract_spec.rb
+++ b/spec/contracts/work_packages/base_contract_spec.rb
@@ -527,7 +527,7 @@ describe WorkPackages::BaseContract do
end
describe 'duration', with_flag: { work_packages_duration_field_active: true } do
- context 'when setting the duration' do
+ context 'when setting duration' do
before do
work_package.duration = 5
end
@@ -535,7 +535,7 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is valid'
end
- context 'when setting the duration for a milestone type work package' do
+ context 'when setting duration for a milestone type work package' do
let(:is_milestone) { true }
before do
@@ -545,7 +545,7 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is invalid', duration: :not_available_for_milestones
end
- context 'when setting the duration to nil for a milestone type work package' do
+ context 'when setting duration to nil for a milestone type work package' do
let(:is_milestone) { true }
before do
@@ -555,7 +555,7 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is invalid'
end
- context 'when setting the duration to 1 for a milestone type work package' do
+ context 'when setting duration to 1 for a milestone type work package' do
let(:is_milestone) { true }
before do
@@ -565,7 +565,7 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is valid'
end
- context 'when setting the duration with the feature disabled', with_flag: { work_packages_duration_field_active: false } do
+ context 'when setting duration with the feature disabled', with_flag: { work_packages_duration_field_active: false } do
before do
work_package.duration = 5
end
@@ -573,7 +573,7 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is invalid', duration: :error_readonly
end
- context 'when setting the duration to 0' do
+ context 'when setting duration to 0' do
before do
work_package.duration = 0
end
@@ -581,7 +581,7 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is invalid', duration: :greater_than
end
- context 'when setting the duration to a floating point' do
+ context 'when setting duration to a floating point' do
before do
work_package.duration = 4.5
end
@@ -589,7 +589,7 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is invalid', duration: :not_an_integer
end
- context 'when setting the duration to a negative value' do
+ context 'when setting duration to a negative value' do
before do
work_package.duration = -5
end
@@ -597,8 +597,9 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is invalid', duration: :greater_than
end
- context 'when setting duration as well as the dates' do
+ context 'when setting duration and dates' do
before do
+ work_package.ignore_non_working_days = true
work_package.duration = 6
work_package.start_date = Time.zone.today - 4.days
work_package.due_date = Time.zone.today + 1.day
@@ -607,8 +608,21 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is valid'
end
- context 'when setting duration as well as the dates and the duration is too small' do
+ context 'when setting duration and dates while covering non-working days' do
before do
+ create(:week_days) # sat and sun are weekends
+ work_package.ignore_non_working_days = false
+ work_package.duration = 6
+ work_package.start_date = "2022-08-22"
+ work_package.due_date = "2022-08-29"
+ end
+
+ it_behaves_like 'contract is valid'
+ end
+
+ context 'when setting duration and dates and duration is too small' do
+ before do
+ work_package.ignore_non_working_days = true
work_package.duration = 5
work_package.start_date = Time.zone.today - 4.days
work_package.due_date = Time.zone.today + 1.day
@@ -617,8 +631,21 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is invalid', duration: :smaller_than_dates
end
- context 'when setting duration as well as the dates and the duration is too big' do
+ context 'when setting duration and dates while covering non-working days and duration is too small' do
before do
+ create(:week_days) # sat and sun are weekends
+ work_package.ignore_non_working_days = false
+ work_package.duration = 1
+ work_package.start_date = "2022-08-22"
+ work_package.due_date = "2022-08-29"
+ end
+
+ it_behaves_like 'contract is invalid', duration: :smaller_than_dates
+ end
+
+ context 'when setting duration and dates and duration is too big' do
+ before do
+ work_package.ignore_non_working_days = true
work_package.duration = 7
work_package.start_date = Time.zone.today - 4.days
work_package.due_date = Time.zone.today + 1.day
@@ -627,14 +654,16 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is invalid', duration: :larger_than_dates
end
- context 'when setting duration as well as the dates to the same date' do
+ context 'when setting duration and dates while covering non-working days and duration is too big' do
before do
- work_package.duration = 1
- work_package.start_date = Time.zone.today
- work_package.due_date = Time.zone.today
+ create(:week_days) # sat and sun are weekends
+ work_package.ignore_non_working_days = false
+ work_package.duration = 99
+ work_package.start_date = "2022-08-22"
+ work_package.due_date = "2022-08-29"
end
- it_behaves_like 'contract is valid'
+ it_behaves_like 'contract is invalid', duration: :larger_than_dates
end
context 'when setting start date and due date without duration' do