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
Rewrite rspec examples in a more fluent fashion
Christophe Bliarda9168522017c
diff --git a/spec/support/schedule_helpers/chart.rb b/spec/support/schedule_helpers/chart.rbindex 4b4dafe5a73..e85b38fb274 100644--- a/spec/support/schedule_helpers/chart.rb+++ b/spec/support/schedule_helpers/chart.rb@@ -144,6 +144,11 @@ module ScheduleHelpersattributes[:duration] = durationend+ def set_ignore_non_working_days(name, ignore_non_working_days)+ attributes = work_package_attributes(name.to_sym)+ attributes[:ignore_non_working_days] = ignore_non_working_days+ end+def add_follows_relation(predecessor:, follower:, delay:)predecessors_by_follower(follower) << predecessordelays_between[[predecessor, follower]] = delaydiff --git a/spec/support/schedule_helpers/chart_builder.rb b/spec/support/schedule_helpers/chart_builder.rbindex 275ced89d40..570ba8089ac 100644--- a/spec/support/schedule_helpers/chart_builder.rb+++ b/spec/support/schedule_helpers/chart_builder.rb@@ -114,6 +114,10 @@ module ScheduleHelpers)when /^duration (\d+)/chart.set_duration(name, $1.to_i)+ when /^working days work week$/+ chart.set_ignore_non_working_days(name, false)+ when /^working days include weekends$/+ chart.set_ignore_non_working_days(name, true)elseraise "unable to parse property #{property.inspect} for line #{name.inspect}"enddiff --git a/spec/support/schedule_helpers/chart_representer.rb b/spec/support/schedule_helpers/chart_representer.rbindex ee4d8b6e4f7..9126cb7660e 100644--- a/spec/support/schedule_helpers/chart_representer.rb+++ b/spec/support/schedule_helpers/chart_representer.rb@@ -30,12 +30,12 @@ module ScheduleHelpersclass ChartRepresenterLINE = "%<id>s | %<days>s |".freeze- def self.normalized_to_s(reference_chart, other_chart)- order = reference_chart.work_package_names- id_column_size = [reference_chart, other_chart].map(&:id_column_size).max- first_day = [reference_chart, other_chart].map(&:first_day).min- last_day = [reference_chart, other_chart].map(&:last_day).max- [reference_chart, other_chart]+ def self.normalized_to_s(expected_chart, actual_chart)+ order = expected_chart.work_package_names+ id_column_size = [expected_chart, actual_chart].map(&:id_column_size).max+ first_day = [expected_chart, actual_chart].map(&:first_day).min+ last_day = [expected_chart, actual_chart].map(&:last_day).max+ [expected_chart, actual_chart].map { |chart| chart.with(order:, id_column_size:, first_day:, last_day:) }.map(&:to_s)enddiff --git a/spec/support_spec/schedule_helpers/chart_builder_spec.rb b/spec/support_spec/schedule_helpers/chart_builder_spec.rbindex 4c29735777f..de0f9e77d4b 100644--- a/spec/support_spec/schedule_helpers/chart_builder_spec.rb+++ b/spec/support_spec/schedule_helpers/chart_builder_spec.rb@@ -156,6 +156,26 @@ describe ScheduleHelpers::ChartBuilder doexpect(chart.work_package_attributes(:main)).to include(duration: 3)endend++ describe 'working days work week' do+ it 'sets ignore_non_working_days to false for the work package' do+ chart = builder.parse(<<~CHART)+ days | MTWTFSS |+ main | | working days work week+ CHART+ expect(chart.work_package_attributes(:main)).to include(ignore_non_working_days: false)+ end+ end++ describe 'working days include weekends' do+ it 'sets ignore_non_working_days to true for the work package' do+ chart = builder.parse(<<~CHART)+ days | MTWTFSS |+ main | | working days include weekends+ CHART+ expect(chart.work_package_attributes(:main)).to include(ignore_non_working_days: true)+ end+ endenddescribe 'error handling' dodiff --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 271baae0f68..a7852238bc1 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@@ -12,66 +12,109 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob,WeekDay.find_by(day: wday).update(working: false)end- it 'updates finish date of work packages after marking week days as non-working' do- work_package = create(:work_package,- ignore_non_working_days: false,- start_date: Date.parse('Mon 2022-08-22'),- duration: 5)+ context 'when a work package includes a date that is now a non-working day' do+ let_schedule(<<~CHART, ignore_non_working_days: false)+ days | MTWTFSS |+ work_package | XXXX |+ CHART- expect do+ before doset_non_working_week_day('wednesday')+ end++ it 'moves the finish date to the corresponding number of now-excluded days to maintain duration [#31992]' dojob.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XX.XX |+ CHARTend- .to change { work_package.reload.slice(:due_date) }- .from(due_date: Date.parse('Fri 2022-08-26'))- .to(due_date: Date.parse('Mon 2022-08-29'))end- it 'does not change work packages ignoring non-working days' do- work_package = create(:work_package,- ignore_non_working_days: true,- start_date: Date.parse('Mon 2022-08-22'),- duration: 5)+ context 'when a work package includes a date that is now a non-working day, but has working days include weekends' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XXXX | working days include weekends+ CHART- expect do+ before doset_non_working_week_day('wednesday')+ end++ it 'does not move any dates' do+ job.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XXXX | working days include weekends+ CHART+ end+ end++ context 'when having multiple work packages' do+ let_schedule(<<~CHART, ignore_non_working_days: false)+ days | MTWTFSS |+ wp1 | XX |+ wp2 | XX |+ wp3 | XX |+ wp4 | XX |+ wp5 | XXXXX |+ CHART++ before do+ set_non_working_week_day('wednesday')+ end++ it 'updates all impacted work packages' dojob.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ wp1 | XX |+ wp2 | X.X |+ wp3 | XX |+ wp4 | XX |+ wp5 | XX.XX..X |+ CHARTend- .not_to change { work_package.reload }end- it 'updates multiple work packages' do- create_list(:work_package,- 5,- ignore_non_working_days: false,- start_date: Date.parse('Mon 2022-08-22'),- duration: 5)+ context 'when a work package was scheduled to start on a date that is now a non-working day' do+ let_schedule(<<~CHART, ignore_non_working_days: false)+ days | MTWTFSS |+ work_package | XX |+ CHART- set_non_working_week_day('wednesday')- job.perform_now(user_id: user.id)+ before do+ set_non_working_week_day('wednesday')+ end- new_due_dates = WorkPackage.order(:id).pluck(:due_date)- expect(new_due_dates).to all(eq(Date.parse('Mon 2022-08-29')))+ it 'moves the start date to the earliest working day in the future, ' \+ 'and the finish date changes by consequence [#31992]' do+ job.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XX |+ CHART+ endend- it 'updates followers if needed' do- work_package = create(:work_package,- ignore_non_working_days: false,- start_date: Date.parse('Mon 2022-08-22'),- duration: 5)- follower = create(:work_package,- ignore_non_working_days: true,- start_date: Date.parse('Sat 2022-08-27'),- duration: 2)- create(:follows_relation, from: follower, to: work_package)-- set_non_working_week_day('wednesday')- job.perform_now(user_id: user.id)-- follower.reload- work_package.reload- expect(follower.start_date).not_to eq(Date.parse('Sat 2022-08-27'))- expect(follower.start_date).to eq(work_package.due_date + 1)- expect(follower.due_date).to eq(work_package.due_date + 2)+ context 'when a follower has a predecessor with dates covering a day that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX | working days work week+ follower | XXX | working days include weekends, follows predecessor+ CHART++ before do+ set_non_working_week_day('wednesday')+ end++ it 'moves the follower start date by consequence of the predecessor dates shift [#31992]' do+ job.perform_now(user_id: user.id)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | X.X | working days work week+ follower | XXX | working days include weekends+ CHART+ endendend