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
[#41821] Reschedule on new follows relation or parent
Christophe Bliard7cbdbcd81709
diff --git a/spec/services/work_packages/set_schedule_service_working_days_spec.rb b/spec/services/work_packages/set_schedule_service_working_days_spec.rbindex fc7deb48350..1a5ff4c24c0 100644--- a/spec/services/work_packages/set_schedule_service_working_days_spec.rb+++ b/spec/services/work_packages/set_schedule_service_working_days_spec.rb@@ -547,70 +547,101 @@ describe WorkPackages::SetScheduleService, 'working days', with_flag: { work_pacCHARTendend- end- # context 'when not moving and the successor having start and due before predecessor due date (e.g. creating relation)' do- # let(:follower1_start_date) { work_package_due_date - 5.days }- # let(:follower1_due_date) { work_package_due_date - 2.days }+ context 'with predecessor and follower having no dates' do+ let_schedule(<<~CHART, ignore_non_working_days: false)+ days | MTWTFSS |+ work_package | |+ follower | |+ CHART- # it_behaves_like 'reschedules' do- # let(:expected) do- # { following_work_package1 => [work_package.due_date + 1.day, work_package.due_date + 4.days] }- # end- # end- # end+ before do+ create(:follows_relation, from: follower, to: work_package)+ end- # context 'when not having dates and the successor not having start & due date (e.g. creating relation)' do- # let(:work_package_due_date) { nil }- # let(:follower1_start_date) { nil }- # let(:follower1_due_date) { nil }+ it 'does not reschedule any work package' do+ expect(subject.all_results).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | |+ CHART+ end+ end+ end- # it_behaves_like 'reschedules' do- # let(:expected) do- # {}- # end- # end- # end+ context 'with the successor having another predecessor which has no dates' do+ context 'when moved forward' do+ let_schedule(<<~CHART, ignore_non_working_days: false)+ days | MTWTFSS |+ work_package | ] |+ follower | XXX | follows work_package, follows other_predecessor+ other_predecessor | |+ CHART- # context 'with the successor having another predecessor which has no dates' do- # let(:following_work_package1) do- # create_follower(follower1_start_date,- # follower1_due_date,- # { work_package => follower1_delay,- # another_successor => 0 })- # end- # let(:another_successor) do- # create(:work_package,- # start_date: nil,- # due_date: nil)- # end+ before do+ change_schedule([work_package], <<~CHART)+ days | MTWTFSS |+ work_package | ] |+ CHART+ end- # context 'when moving forward' do- # before do- # work_package.due_date = Time.zone.today + 5.days- # end+ it 'reschedules follower without influence from the other predecessor' do+ expect(subject.all_results).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | ] |+ follower | X..XX |+ CHART+ end+ end- # it_behaves_like 'reschedules' do- # let(:expected) do- # { following_work_package1 => [Time.zone.today + 6.days, Time.zone.today + 8.days] }- # end- # end- # end+ context 'when moved backwards' do+ let_schedule(<<~CHART, ignore_non_working_days: false)+ days | MTWTFSS |+ work_package | ] |+ follower | XXX | follows work_package, follows other_predecessor+ other_predecessor | |+ CHART- # context 'when moving backwards' do- # before do- # work_package.due_date = Time.zone.today - 5.days- # end+ before do+ change_schedule([work_package], <<~CHART)+ days | mtwtfssMTWTFSS |+ work_package | ] |+ CHART+ end- # it_behaves_like 'reschedules' do- # let(:expected) do- # { following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days] }- # end- # end- # end- # end- # end+ it 'reschedules follower without influence from the other predecessor' do+ expect(subject.all_results).to match_schedule(<<~CHART)+ days | mtwtfssMTWTFSS |+ work_package | ] |+ follower | XX..X |+ CHART+ end+ end+ end+ end+ context 'with a parent' do+ context 'when setting both start and due dates' do+ let_schedule(<<~CHART, ignore_non_working_days: false)+ days | MTWTFSS |+ parent | |+ work_package | ] | child of parent+ CHART++ before do+ change_schedule([work_package], <<~CHART)+ days | mtwtfssMTWTFSS |+ work_package | XXX..X |+ CHART+ end++ it 'reschedules parent to have the same dates as the child' do+ expect(subject.all_results).to match_schedule(<<~CHART)+ days | mtwtfssMTWTFSS |+ parent | XXX..X |+ work_package | XXX..X |+ CHART+ end+ end# context 'with only a parent' do# let!(:parent_work_package) do# create(:work_package).tap do |parent|diff --git a/spec/support/schedule_helpers.rb b/spec/support/schedule_helpers.rbindex 8e7836a12b7..83bfcd423bb 100644--- a/spec/support/schedule_helpers.rb+++ b/spec/support/schedule_helpers.rb@@ -35,11 +35,9 @@ RSpec.configure do |config|RSpec::Matchers.define :match_schedule do |expected|match do |actual_work_packages|expected_chart = ScheduleHelpers::Chart.for(expected)- @expected = expected_chart.to_s # normalize expected-actual_chart = ScheduleHelpers::Chart.from_work_packages(actual_work_packages)- actual_chart.monday = expected_chart.monday- @actual = actual_chart.to_s++ @expected, @actual = ScheduleHelpers::ChartRepresenter.normalized_to_s(expected_chart, actual_chart)values_match? @expected, @actualenddiff --git a/spec/support/schedule_helpers/chart.rb b/spec/support/schedule_helpers/chart.rbindex c8f7b8c192a..d0d02cb9c88 100644--- a/spec/support/schedule_helpers/chart.rb+++ b/spec/support/schedule_helpers/chart.rb@@ -49,7 +49,10 @@ module ScheduleHelpers# * +_+: ignored but useful as a placeholder to highlight particular days, for# instance to highlight the previous dates of a work package.class Chart- attr_reader :first_day, :last_day, :monday+ FIRST_CELL_TEXT = 'days'.freeze+ WEEK_DAYS_TEXT = 'MTWTFSS'.freeze++ attr_reader :id_column_size, :first_day, :last_day, :mondaydef self.for(representation)builder = ChartBuilder.new@@ -62,6 +65,22 @@ module ScheduleHelpersdef initializeself.monday = next_monday+ self.id_column_size = FIRST_CELL_TEXT.length+ end++ # duplicates the chart with different representation properties+ def with(order: work_package_names, id_column_size: self.id_column_size, first_day: self.first_day, last_day: self.last_day)+ chart = Chart.new+ extra_names = work_package_names - order+ chart.work_packages_attributes = work_packages_attributes.index_by { _1[:name] }.values_at(*(order + extra_names)).compact+ chart.monday = monday+ chart.id_column_size = id_column_size+ chart.first_day = first_day+ chart.last_day = last_day+ chart.predecessors_by_followers = predecessors_by_followers+ chart.delays_between = delays_between+ chart.parent_by_child = parent_by_child+ chartend# Sets the origin of the calendar, represented by +M+ on the first line (M as@@ -74,9 +93,9 @@ module ScheduleHelpersenddef validate- work_packages.each_key do |follower|+ work_package_names.each do |follower|predecessors_by_follower(follower).each do |predecessor|- if !work_packages.has_key?(predecessor)+ unless work_package_attributes(predecessor)raise "unable to find predecessor #{predecessor.inspect} " \"in property \"follows #{predecessor}\" " \"for work package #{follower.inspect}"@@ -85,27 +104,30 @@ module ScheduleHelpersendend- def work_packages- @work_packages ||= {}+ def work_packages_attributes+ @work_packages_attributes ||= []enddef work_package_attributes(name)- work_packages[name.to_sym]+ work_packages_attributes.find { |wpa| wpa[:name] == name.to_sym }end- def delay_between(predecessor:, follower:)- delays_between.fetch([predecessor, follower])+ def work_package_names+ work_packages_attributes.pluck(:name)enddef predecessors_by_follower(follower)- @predecessors_by_follower ||= Hash.new { |h, k| h[k] = [] }- @predecessors_by_follower[follower]+ predecessors_by_followers[follower]+ end++ def delay_between(predecessor:, follower:)+ delays_between.fetch([predecessor, follower])enddef add_work_package(attributes)- name = attributes[:subject].to_symextend_calendar_range(*attributes.values_at(:start_date, :due_date))- work_packages[name] = attributes+ extend_id_column_size(*attributes.values_at(:subject))+ work_packages_attributes << attributes.merge(name: attributes[:subject].to_sym)enddef add_follows_relation(predecessor:, follower:, delay:)@@ -113,24 +135,50 @@ module ScheduleHelpersdelays_between[[predecessor, follower]] = delayend+ def add_parent_relation(parent:, child:)+ parent_by_child[child] = parent+ end++ def parent(name)+ parent_by_child[name]+ end+def to_s- representer = ChartRepresenter.new+ representer = ChartRepresenter.new(id_column_size:, days_column_size:)representer.add_row- representer.add_cell('days')- representer.add_cell(spaced_at(monday, 'MTWTFSS'))- work_packages.each do |name, attributes|+ representer.add_cell(FIRST_CELL_TEXT)+ representer.add_cell(spaced_at(monday, WEEK_DAYS_TEXT))+ work_package_names.each do |name|representer.add_rowrepresenter.add_cell(name.to_s)- representer.add_cell(span(attributes))+ representer.add_cell(span(work_package_attributes(name)))endrepresenter.to_send+ protected++ attr_writer :work_packages_attributes,+ :id_column_size,+ :first_day,+ :last_day,+ :predecessors_by_followers,+ :delays_between,+ :parent_by_child+privatedef extend_calendar_range(*dates)- @first_day = [@first_day, *dates].compact.min- @last_day = [@last_day, *dates].compact.max+ self.first_day = [@first_day, *dates].compact.min+ self.last_day = [@last_day, *dates].compact.max+ end++ def extend_id_column_size(name)+ self.id_column_size = [id_column_size, name.length].max+ end++ def days_column_size+ (first_day..last_day).countenddef spaced_at(date, text)@@ -161,8 +209,16 @@ module ScheduleHelpersdateend+ def predecessors_by_followers+ @predecessors_by_followers ||= Hash.new { |h, k| h[k] = [] }+ end+def delays_between@delays_between ||= Hash.new(0)end++ def parent_by_child+ @parent_by_child ||= {}+ endendenddiff --git a/spec/support/schedule_helpers/chart_builder.rb b/spec/support/schedule_helpers/chart_builder.rbindex 51775b9e941..f6fdc818e06 100644--- a/spec/support/schedule_helpers/chart_builder.rb+++ b/spec/support/schedule_helpers/chart_builder.rb@@ -68,11 +68,12 @@ module ScheduleHelpersdef parse_header(header)_, week_days = header.split(' | ', 2)- unless week_days.include?('MTWTFSS')- raise ArgumentError, "First header line of schedule chart must contain MTWTFSS to indicate day names and have an origin"+ unless week_days.include?(Chart::WEEK_DAYS_TEXT)+ raise ArgumentError,+ "First header line of schedule chart must contain #{Chart::WEEK_DAYS_TEXT} to indicate day names and have an origin"end- @nb_days_from_origin_monday = week_days.index('M')+ @nb_days_from_origin_monday = week_days.index(Chart::WEEK_DAYS_TEXT.first)enddef parse_line(line)@@ -106,6 +107,11 @@ module ScheduleHelpersfollower: name.to_sym,delay: $2.to_i)+ when /^child of (\w+)/+ chart.add_parent_relation(+ parent: $1.to_sym,+ child: name.to_sym+ )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 6a329bd0818..ee4d8b6e4f7 100644--- a/spec/support/schedule_helpers/chart_representer.rb+++ b/spec/support/schedule_helpers/chart_representer.rb@@ -30,6 +30,21 @@ 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]+ .map { |chart| chart.with(order:, id_column_size:, first_day:, last_day:) }+ .map(&:to_s)+ end++ def initialize(id_column_size:, days_column_size:)+ @id_column_size = id_column_size+ @days_column_size = days_column_size+ end+def add_rowrows << []end@@ -43,18 +58,10 @@ module ScheduleHelpersenddef to_s- line_template = "%<id>-#{columns_size[0]}s | %<days>-#{columns_size[1]}s |"+ line_template = "%<id>-#{@id_column_size}s | %<days>-#{@days_column_size}s |"rows.map do |row|line_template % { id: row[0], days: row[1] }end.join("\n")end-- def columns- rows.transpose- end-- def columns_size- columns.map { |column| column.map(&:length).max }- endendenddiff --git a/spec/support/schedule_helpers/example_methods.rb b/spec/support/schedule_helpers/example_methods.rbindex edb612433c8..0205620dcfe 100644--- a/spec/support/schedule_helpers/example_methods.rb+++ b/spec/support/schedule_helpers/example_methods.rb@@ -28,29 +28,6 @@module ScheduleHelpersmodule ExampleMethods- # Update the given work packages according to the given chart representation.- # Work packages are changed without being saved.- #- # For instance:- #- # before do- # change_schedule([main], <<~CHART)- # days | MTWTFSS |- # main | XX |- # CHART- # end- #- # is equivalent to:- #- # before do- # main.start_date = monday- # main.due_date = tuesday- # end- def update_schedule(work_packages, chart)- change_schedule(work_packages, chart)- work_packages.each(&:save!)- end-# Change the given work packages according to the given chart representation.# Work packages are changed without being saved.#@@ -70,10 +47,11 @@ module ScheduleHelpers# main.due_date = tuesday# enddef change_schedule(work_packages, chart)- Chart.for(chart).work_packages.each do |name, attributes|+ Chart.for(chart).work_packages_attributes.each do |attributes|work_package = work_packages.find { |wp| wp.subject == attributes[:subject] }unless work_package- raise ArgumentError, "unable to find a WorkPackage with name :#{name}. Got #{work_packages.pluck(:subject).to_sentence}"+ raise ArgumentError, "no work package with subject #{attributes[:subject]} given; " \+ "available work packages are #{work_packages.pluck(:subject).to_sentence}"endattributes.slice(:start_date, :due_date).each do |attribute, value|@@ -107,7 +85,8 @@ module ScheduleHelpersdef expect_schedule(work_packages, chart)by_id = work_packages.index_by(&:id)chart = Chart.for(chart)- chart.work_packages.each do |name, attributes|+ chart.work_packages_attributes.each do |attributes|+ name = attributes[:name]raise ArgumentError, "unable to find WorkPackage :#{name}" unless respond_to?(name)work_package = send(name)diff --git a/spec/support/schedule_helpers/let_schedule.rb b/spec/support/schedule_helpers/let_schedule.rbindex ff436eea65f..453e5ee0c04 100644--- a/spec/support/schedule_helpers/let_schedule.rb+++ b/spec/support/schedule_helpers/let_schedule.rb@@ -42,35 +42,59 @@ module ScheduleHelpers## is equivalent to:#- # let!(:main) do+ # let!(:schedule_chart) do+ # chart = <...parse_chart(CHART)...>+ # main+ # follower+ # start_only+ # due_only+ # relation_follower_follows_main+ # chart+ # end+ # let(:main) do# create(:work_package, subject: 'main', start_date: next_monday, due_date: next_monday + 1.day)# end- # let!(:follower) do+ # let(:follower) do# create(:work_package, subject: 'follower', start_date: next_monday + 2.days, due_date: next_monday + 4.days) }# end- # let!(:relation_follower_follows_main) do+ # let(:relation_follower_follows_main) do# create(:follows_relation, from: follower, to: main, delay: 0) }# end- # let!(:start_only) do+ # let(:start_only) do# create(:work_package, subject: 'start_only', start_date: next_monday + 1.day) }# end- # let!(:due_only) do+ # let(:due_only) do# create(:work_package, subject: 'due_only', due_date: next_monday + 3.days) }# enddef let_schedule(chart_representation, **extra_attributes)# To be able to use `travel_to` in a before hook, the dates in the chart# must be lazy evaluated in a let statement.let(:schedule_chart) { Chart.for(chart_representation) }+ let!(:__evaluate_work_packages_from_schedule_chart) do+ schedule_chart.work_package_names.each do |name|+ # force evaluation of work package+ send(name)+ schedule_chart.predecessors_by_follower(name).each do |predecessor|+ # force evaluation of relation+ send("relation_#{name}_follows_#{predecessor}")+ end+ end+ end# we still need to parse the chart to get the work package names and relationschart = Chart.for(chart_representation)- chart.work_packages.each_key do |name|- let!(name) do- create(:work_package, schedule_chart.work_package_attributes(name).reverse_merge(extra_attributes))+ chart.work_package_names.each do |name|+ let(name) do+ attributes = schedule_chart+ .work_package_attributes(name)+ .excluding(:name)+ .reverse_merge(extra_attributes)+ .merge(parent: schedule_chart.parent(name) ? send(schedule_chart.parent(name)) : nil)+ create(:work_package, attributes)endchart.predecessors_by_follower(name).each do |predecessor|relation_alias = "relation_#{name}_follows_#{predecessor}"- let!(relation_alias) do+ let(relation_alias) docreate(:follows_relation,from: send(name),to: send(predecessor),diff --git a/spec/support_spec/schedule_helpers/chart_builder_spec.rb b/spec/support_spec/schedule_helpers/chart_builder_spec.rbindex b177eee8695..1ab3c85305b 100644--- a/spec/support_spec/schedule_helpers/chart_builder_spec.rb+++ b/spec/support_spec/schedule_helpers/chart_builder_spec.rb@@ -59,15 +59,15 @@ describe ScheduleHelpers::ChartBuilder dodue_only | ] |no_dates | |CHART- expect(chart.work_packages).to eq(- {- main: { subject: 'main', start_date: monday, due_date: tuesday },- other: { subject: 'other', start_date: thursday, due_date: next_tuesday },- follower: { subject: 'follower', start_date: wednesday, due_date: friday },- start_only: { subject: 'start_only', start_date: tuesday, due_date: nil },- due_only: { subject: 'due_only', start_date: nil, due_date: friday },- no_dates: { subject: 'no_dates', start_date: nil, due_date: nil }- }+ expect(chart.work_packages_attributes).to eq(+ [+ { name: :main, subject: 'main', start_date: monday, due_date: tuesday },+ { name: :other, subject: 'other', start_date: thursday, due_date: next_tuesday },+ { name: :follower, subject: 'follower', start_date: wednesday, due_date: friday },+ { name: :start_only, subject: 'start_only', start_date: tuesday, due_date: nil },+ { name: :due_only, subject: 'due_only', start_date: nil, due_date: friday },+ { name: :no_dates, subject: 'no_dates', start_date: nil, due_date: nil }+ ])expect(chart.predecessors_by_follower(:main)).to eq([])expect(chart.predecessors_by_follower(:other)).to eq([])@@ -94,7 +94,7 @@ describe ScheduleHelpers::ChartBuilder dowp | X |CHARTexpect(chart.monday).to eq(monday)- expect(chart.first_day).to eq(chart.work_packages.dig(:wp, :start_date))+ expect(chart.first_day).to eq(chart.work_package_attributes(:wp)[:start_date])endend@@ -132,6 +132,20 @@ describe ScheduleHelpers::ChartBuilder doexpect(chart.delay_between(predecessor: :main, follower: :follower)).to eq(3)endend++ describe 'child of <name>' do+ it 'sets the parent to the named one' do+ chart = builder.parse(<<~CHART)+ days | MTWTFSS |+ parent | | child of grandparent+ main | | child of parent+ grandparent | |+ CHART+ expect(chart.parent(:grandparent)).to be_nil+ expect(chart.parent(:parent)).to eq(:grandparent)+ expect(chart.parent(:main)).to eq(:parent)+ end+ endenddescribe 'error handling' dodiff --git a/spec/support_spec/schedule_helpers/chart_representer_spec.rb b/spec/support_spec/schedule_helpers/chart_representer_spec.rbnew file mode 100644index 00000000000..67c75525eb5--- /dev/null+++ b/spec/support_spec/schedule_helpers/chart_representer_spec.rb@@ -0,0 +1,192 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++describe ScheduleHelpers::ChartRepresenter do+ let(:fake_today) { Date.new(2022, 6, 16) } # Thursday 16 June 2022+ let(:monday) { Date.new(2022, 6, 20) } # Monday 20 June+ let(:tuesday) { Date.new(2022, 6, 21) }+ let(:wednesday) { Date.new(2022, 6, 22) }+ let(:thursday) { Date.new(2022, 6, 23) }+ let(:friday) { Date.new(2022, 6, 24) }+ let(:saturday) { Date.new(2022, 6, 25) }+ let(:sunday) { Date.new(2022, 6, 26) }++ describe '#normalized_to_s' do+ let!(:week_days) { create(:week_days) }++ context 'when both charts have different work packages items and/or order' do+ def to_first_columns(charts)+ charts.map { _1.split("\n").map(&:split).map(&:first).join(' ') }+ end++ it 'returns charts ascii with work packages in same order as the first given chart' do+ initial_expected_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ main | X..X |+ other | XXX..X |+ CHART+ initial_actual_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ other | XXX..X |+ main | X..X |+ CHART++ expected_column, actual_column =+ described_class+ .normalized_to_s(initial_expected_chart, initial_actual_chart)+ .then(&method(:to_first_columns))++ expect(actual_column).to eq(expected_column)+ end++ it 'pushes extra elements of the second chart at the end' do+ initial_expected_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ main | X..X |+ other | XXX..X |+ CHART+ initial_actual_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ extra | |+ main | X..X |+ other | XXX..X |+ CHART++ expected_column, actual_column =+ described_class+ .normalized_to_s(initial_expected_chart, initial_actual_chart)+ .then(&method(:to_first_columns))++ expect(expected_column).to eq('days main other')+ expect(actual_column).to eq('days main other extra')+ end++ it 'keeps extra elements of the first chart at the same place' do+ initial_expected_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ main | X..X |+ extra | |+ other | XXX..X |+ CHART+ initial_actual_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ main | X..X |+ other | XXX..X |+ CHART++ expected_column, actual_column =+ described_class+ .normalized_to_s(initial_expected_chart, initial_actual_chart)+ .then(&method(:to_first_columns))++ expect(expected_column).to eq('days main extra other')+ expect(actual_column).to eq('days main other')+ end+ end++ context 'when both charts have different first column width' do+ def to_first_cells(charts)+ charts.map { _1.split("\n").first.split(" | ").first }+ end++ it 'returns charts ascii with identical first column width' do+ tiny_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ tiny name | XX |+ CHART+ longer_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ much longer name | XX |+ CHART++ # tiny_chart as reference chart+ first_cell, second_cell =+ described_class+ .normalized_to_s(tiny_chart, longer_chart)+ .then(&method(:to_first_cells))++ expect(first_cell).to eq('days ')+ expect(first_cell).to eq(second_cell)++ # tiny_chart as reference chart+ first_cell, second_cell =+ described_class+ .normalized_to_s(longer_chart, tiny_chart)+ .then(&method(:to_first_cells))++ expect(first_cell).to eq('days ')+ expect(first_cell).to eq(second_cell)+ end+ end++ context 'when both charts cover different time periods' do+ def to_headers(charts)+ charts.map { _1.split("\n").first }+ end++ it 'returns charts ascii with identical time periods' do+ larger_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ main | XXXXXXXXXXX |+ CHART+ shorter_chart =+ ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)+ days | MTWTFSS |+ main | XXX |+ CHART++ # larger_chart as reference+ first_header, second_header =+ described_class+ .normalized_to_s(larger_chart, shorter_chart)+ .then(&method(:to_headers))++ expect(first_header).to eq(second_header)++ # shorter_chart as reference+ first_header, second_header =+ described_class+ .normalized_to_s(shorter_chart, larger_chart)+ .then(&method(:to_headers))++ expect(first_header).to eq(second_header)+ end+ end+ end+enddiff --git a/spec/support_spec/schedule_helpers/let_schedule_spec.rb b/spec/support_spec/schedule_helpers/let_schedule_spec.rbindex e661b99fbc8..97fdcb5842d 100644--- a/spec/support_spec/schedule_helpers/let_schedule_spec.rb+++ b/spec/support_spec/schedule_helpers/let_schedule_spec.rb@@ -47,6 +47,7 @@ describe ScheduleHelpers::LetSchedule dodays | MTWTFSS |main | XX |follower | XXX | follows main with delay 2+ child | | child of mainCHARTit 'creates let! call for :schedule_chart which returns the chart' do@@ -55,8 +56,8 @@ describe ScheduleHelpers::LetSchedule doendit 'creates let! calls for each work package' do- expect([main, follower]).to all(be_an_instance_of(WorkPackage))- expect([main, follower]).to all(be_persisted)+ expect([main, follower, child]).to all(be_an_instance_of(WorkPackage))+ expect([main, follower, child]).to all(be_persisted)expect(main).to have_attributes(subject: 'main',start_date: schedule_chart.monday,@@ -67,6 +68,11 @@ describe ScheduleHelpers::LetSchedule dostart_date: schedule_chart.monday + 2.days,due_date: schedule_chart.monday + 4.days)+ expect(child).to have_attributes(+ subject: 'child',+ start_date: nil,+ due_date: nil+ )endit 'creates let! calls for follows relations between work packages' do@@ -75,6 +81,10 @@ describe ScheduleHelpers::LetSchedule doexpect(relation_follower_follows_main.delay).to eq(2)end+ it 'creates parent / child relations' do+ expect(child.parent).to eq(main)+ end+context 'with additional attributes' dolet_schedule(<<~CHART, done_ratio: 50, schedule_manually: true)days | MTWTFSS |