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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add scenarios for adding working days
Christophe Bliard94ad50116ef2
diff --git a/spec/factories/week_day_factory.rb b/spec/factories/week_day_factory.rbindex a8518739e60..875eb78de8d 100644--- a/spec/factories/week_day_factory.rb+++ b/spec/factories/week_day_factory.rb@@ -43,14 +43,30 @@ FactoryBot.define doend# Factory to create all 7 week days at once, Saturday and Sunday being weekend days- factory :week_with_saturday_and_sunday_as_weekend, aliases: [:week_days], class: 'Array' do+ factory :week_with_saturday_and_sunday_as_weekend, aliases: [:week_days], parent: :week do+ working_days { %w[monday tuesday wednesday thursday friday] }+ end++ # Factory to create all 7 week days at once+ #+ # use +working: ['monday', 'tuesday', ...]+ to define which days of the week+ # will be working days. By default, all days are working days.+ factory :week, class: 'Array' do+ transient do+ working_days { %w[monday tuesday wednesday thursday friday saturday sunday] }+ end+# Skip the create callback to be able to use non-AR models. Otherwise FactoryBot will# try to call #save! on any created object.skip_createinitialize_with do- days = 1.upto(7).map { |day| create(:week_day, day:) }- new(days)+ %w[monday tuesday wednesday thursday friday saturday sunday]+ .map.with_index do |day_name, i|+ day = i + 1+ working = working_days.include?(day_name)+ create(:week_day, day:, working:)+ endendendenddiff --git a/spec/workers/work_packages/apply_working_days_change_job_spec.rb b/spec/workers/work_packages/apply_working_days_change_job_spec.rbindex b08cd8ccc80..b749ba6f6ed 100644--- a/spec/workers/work_packages/apply_working_days_change_job_spec.rb+++ b/spec/workers/work_packages/apply_working_days_change_job_spec.rb@@ -32,12 +32,21 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dosubject(:job) { described_class }shared_let(:user) { create(:user) }- shared_let(:week_days) { create(:week_with_saturday_and_sunday_as_weekend) }++ let!(:week) { create(:week_with_saturday_and_sunday_as_weekend) }def set_non_working_week_days(*days)+ set_week_days(*days, working: false)+ end++ def set_working_week_days(*days)+ set_week_days(*days, working: true)+ end++ def set_week_days(*days, working:)days.each do |day|wday = %w[xxx monday tuesday wednesday thursday friday saturday sunday].index(day.downcase)- WeekDay.find_by!(day: wday).update(working: false)+ WeekDay.find_by!(day: wday).update(working:)endend@@ -88,6 +97,25 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendend+ context 'when a work package includes a date that is no more a non-working day' do+ let_schedule(<<~CHART)+ days | fssMTWTFSS |+ work_package | X..XX |+ CHART++ before do+ set_working_week_days('saturday')+ end++ it 'moves the finish date backwards to the corresponding number of now-included days to maintain duration [#31992]' do+ job.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | fssMTWTFSS |+ work_package | XX.X |+ CHART+ end+ end+context 'when a follower has a predecessor with dates covering a day that is now a non-working day' dolet_schedule(<<~CHART)days | MTWTFSS |@@ -109,6 +137,52 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendend+ context 'when a follower has a predecessor with dates covering a day that is now a working day' do+ let!(:week) { create(:week, working_days: ['monday', 'tuesday', 'thursday', 'friday']) }++ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | X.X | working days work week+ follower | XXX | working days include weekends, follows predecessor+ CHART++ before do+ set_working_week_days('wednesday')+ end++ it 'moves the follower start date backwards by consequence of the predecessor dates shift' do+ job.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX | working days work week+ follower | XXX | working days include weekends+ CHART+ end+ end++ xcontext 'when a follower has a predecessor with a non-working day between them that is now a working day' do+ let!(:week) { create(:week, working_days: ['monday', 'tuesday', 'thursday', 'friday']) }++ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX |+ follower | XX | follows predecessor+ CHART++ before do+ set_working_week_days('wednesday')+ end++ it 'moves the follower start date one day back to keep the same gap between them' do+ job.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX |+ follower | XX |+ CHART+ end+ end+context 'when a work package has working days include weekends, and includes a date that is now a non-working day' dolet_schedule(<<~CHART)days | MTWTFSS |@@ -144,7 +218,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendend- context 'when having multiple work packages following each other' do+ context 'when having multiple work packages following each other, and having days becoming non working days' dolet_schedule(<<~CHART)days | MTWTFSS |wp1 | X..XX | follows wp2@@ -170,12 +244,38 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendend+ xcontext 'when having multiple work packages following each other, and having days becoming working days' do+ let!(:week) { create(:week, working_days: ['monday', 'thursday']) }++ let_schedule(<<~CHART)+ days | MTWTFSSmtwtfssmtwtfss |+ wp1 | X..X...X | follows wp2+ wp2 | X | follows wp3+ wp3 | X..X...X |+ CHART++ before do+ set_working_week_days('tuesday', 'wednesday', 'friday')+ end++ it 'updates them only once' do+ job.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSmt |+ wp1 | X..XX |+ wp2 | X |+ wp3 | XXX |+ CHART+ expect(WorkPackage.pluck(:lock_version)).to all(be_less_or_equal_than(1))+ end+ end+context 'when having multiple work packages following each other and first one only has a due date' dolet_schedule(<<~CHART)days | MTWTFSS |wp1 | X..XX | follows wp2wp2 | XX | follows wp3- wp3 | ] |+ wp3 | ] |CHARTbefore do