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

use calculate_duration trait in feature spec instead of defaulting to calculating duration

Ivan Kuchin142862f82dbd
diff --git a/spec/factories/project_phase_factory.rb b/spec/factories/project_phase_factory.rb
index 5fb25bbfd39..81c6229b9ca 100644
--- a/spec/factories/project_phase_factory.rb
+++ b/spec/factories/project_phase_factory.rb
@@ -36,12 +36,8 @@ FactoryBot.define do
start_date { Date.current - 2.days }
finish_date { Date.current + 2.days }
- duration do
- next nil unless date_range_set?
-
- working_days = Setting.find_by(name: :working_days).value.map(&:to_i)
- (start_date..finish_date).count { |d| working_days.include?(d.cwday) }
- end
+ # use :calculate_duration trait if duration needs to take weekends and non working days into account
+ duration { date_range_set? ? finish_date - start_date + 1 : nil }
trait :skip_validate do
to_create { |instance| instance.save(validate: false) }
@@ -60,7 +56,7 @@ FactoryBot.define do
end
# calculate duration taking weekdays and non working days into account
- trait :proper_duration do
+ trait :calculate_duration do
duration { calculate_duration }
end
end
diff --git a/spec/features/admin/working_days_spec.rb b/spec/features/admin/working_days_spec.rb
index 0486b0a6a94..6604d14642c 100644
--- a/spec/features/admin/working_days_spec.rb
+++ b/spec/features/admin/working_days_spec.rb
@@ -46,6 +46,7 @@ RSpec.describe "Working Days", :js do
# Create consecutive phases with fixed dates
shared_let(:phase1) do
create(:project_phase,
+ :calculate_duration,
project:,
definition: phase_definition1,
start_date: phase1_start_date,
@@ -54,6 +55,7 @@ RSpec.describe "Working Days", :js do
shared_let(:phase2) do
create(:project_phase,
+ :calculate_duration,
project:,
definition: phase_definition2,
start_date: phase2_start_date,