Commit abe8a30c authored by Kerri Miller's avatar Kerri Miller

Merge branch '343523-auto-generated-iterations-should-not-have-dates-in-titles' into 'master'

Remove the logic hardcoding iteration dates in title

See merge request gitlab-org/gitlab!72846
parents a17aec21 c509d68c
......@@ -55,7 +55,6 @@ module Iterations
# we end up having 2020-01-01(beginning of day) - 2020-01-07(end of day)
start_date = next_start_date
due_date = start_date + duration.weeks - 1.day
title = "Iteration #{iteration_number}: #{format_period(start_date, due_date)}"
{
iid: iid,
......@@ -66,7 +65,7 @@ module Iterations
start_date: start_date,
due_date: due_date,
state_enum: Iteration::STATE_ENUM_MAP[::Iteration.compute_state(start_date, due_date)],
title: title
title: "Iteration #{iteration_number}"
}
end
......@@ -122,11 +121,8 @@ module Iterations
existing_iterations_in_advance.each do |iteration|
if iteration.duration_in_days != cadence.duration_in_days
old_title_dates_substring = format_period(iteration.start_date, iteration.due_date)
iteration.start_date = prev_iteration.due_date + 1.day if prev_iteration
iteration.due_date = iteration.start_date + cadence.duration_in_days.days - 1.day
new_title_dates_substring = format_period(iteration.start_date, iteration.due_date)
iteration.title = iteration.title.gsub(old_title_dates_substring, new_title_dates_substring)
end
prev_iteration = iteration
......@@ -141,12 +137,6 @@ module Iterations
end
end
def format_period(start_date, due_date)
format = Date::DATE_FORMATS[:long]
"#{start_date.strftime(format)} - #{due_date.strftime(format)}"
end
def compute_last_run_date
reloaded_last_iteration = cadence_iterations.last
run_date = reloaded_last_iteration.due_date - ((cadence.iterations_in_advance - 1) * cadence.duration_in_weeks).weeks if reloaded_last_iteration
......
......@@ -139,8 +139,8 @@ RSpec.describe Iterations::Cadences::CreateIterationsInAdvanceService do
end
context 'when cadence has iterations but all are in the past' do
let_it_be(:past_iteration1) { create(:iteration, group: group, title: 'Iteration 1', iterations_cadence: automated_cadence, start_date: 3.weeks.ago, due_date: 2.weeks.ago)}
let_it_be(:past_iteration2) { create(:iteration, group: group, title: 'Iteration 2', iterations_cadence: automated_cadence, start_date: past_iteration1.due_date + 1.day, due_date: past_iteration1.due_date + 1.week)}
let_it_be(:past_iteration1) { create(:iteration, group: group, title: 'Iteration 1: some user note', iterations_cadence: automated_cadence, start_date: 3.weeks.ago, due_date: 2.weeks.ago)}
let_it_be(:past_iteration2) { create(:iteration, group: group, title: 'Iteration 2: some user note', iterations_cadence: automated_cadence, start_date: past_iteration1.due_date + 1.day, due_date: past_iteration1.due_date + 1.week)}
before do
automated_cadence.update!(iterations_in_advance: 2)
......@@ -159,46 +159,18 @@ RSpec.describe Iterations::Cadences::CreateIterationsInAdvanceService do
expect(automated_cadence.reload.last_run_date).to eq(automated_cadence.reload.iterations.last(2).first.due_date)
end
it 'sets the title correctly based on iterations count and follow-up dates' do
it 'sets the title correctly based on iterations count without modifying user-edited titles' do
subject
initial_start_date = past_iteration2.due_date + 1.day
initial_due_date = past_iteration2.due_date + 1.week
expect(group.reload.iterations.due_date_order_asc.pluck(:title)).to eq([
'Iteration 1',
'Iteration 2',
"Iteration 3: #{(initial_start_date).strftime(Date::DATE_FORMATS[:long])} - #{initial_due_date.strftime(Date::DATE_FORMATS[:long])}",
"Iteration 4: #{(initial_due_date + 1.day).strftime(Date::DATE_FORMATS[:long])} - #{(initial_due_date + 1.week).strftime(Date::DATE_FORMATS[:long])}",
"Iteration 5: #{(initial_due_date + 1.week + 1.day).strftime(Date::DATE_FORMATS[:long])} - #{(initial_due_date + 2.weeks).strftime(Date::DATE_FORMATS[:long])}"
'Iteration 1: some user note',
'Iteration 2: some user note',
'Iteration 3',
'Iteration 4',
'Iteration 5'
])
end
context 'when cadence changes duration' do
before do
subject
automated_cadence.update!(duration_in_weeks: 3)
automated_cadence.reload
end
it 'adjusts iteration titles for iterations that are autogenerated and have the dates in the title' do
subject
# change duration and expect the titles for iterations containing dates in title to change
described_class.new(user, automated_cadence).execute
initial_start_date = past_iteration2.due_date + 1.day
initial_due_date = past_iteration2.due_date + 1.week
expect(group.reload.iterations.due_date_order_asc.pluck(:title)).to eq([
'Iteration 1',
'Iteration 2',
"Iteration 3: #{(initial_start_date).strftime(Date::DATE_FORMATS[:long])} - #{initial_due_date.strftime(Date::DATE_FORMATS[:long])}",
"Iteration 4: #{(initial_due_date + 1.day).strftime(Date::DATE_FORMATS[:long])} - #{(initial_due_date + 3.weeks).strftime(Date::DATE_FORMATS[:long])}",
"Iteration 5: #{(initial_due_date + 3.weeks + 1.day).strftime(Date::DATE_FORMATS[:long])} - #{(initial_due_date + 6.weeks).strftime(Date::DATE_FORMATS[:long])}"
])
end
end
it 'sets the states correctly based on iterations dates' do
subject
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment