Commit b629e8bb authored by Stan Hu's avatar Stan Hu

Merge branch '299312-update-overlapping-dates-validation-message' into 'master'

Update dates validation message when iteration dates overlap

See merge request gitlab-org/gitlab!65957
parents 6a6f8e01 afed1ba3
...@@ -212,11 +212,12 @@ module EE ...@@ -212,11 +212,12 @@ module EE
return unless iterations_cadence return unless iterations_cadence
return unless iterations_cadence.iterations.where.not(id: self.id).within_timeframe(start_date, due_date).exists? return unless iterations_cadence.iterations.where.not(id: self.id).within_timeframe(start_date, due_date).exists?
# for now we only have a single default cadence within a group just to wrap the iterations into a set. if group.iteration_cadences_feature_flag_enabled?
# once we introduce multiple cadences per group we need to change this message. errors.add(:base, s_("Iteration|Dates cannot overlap with other existing Iterations within this iterations cadence"))
# related issue: https://gitlab.com/gitlab-org/gitlab/-/issues/299312 else
errors.add(:base, s_("Iteration|Dates cannot overlap with other existing Iterations within this group")) errors.add(:base, s_("Iteration|Dates cannot overlap with other existing Iterations within this group"))
end end
end
def future_date def future_date
if start_or_due_dates_changed? if start_or_due_dates_changed?
......
...@@ -178,53 +178,46 @@ RSpec.describe Iteration do ...@@ -178,53 +178,46 @@ RSpec.describe Iteration do
let(:start_date) { 5.days.from_now } let(:start_date) { 5.days.from_now }
let(:due_date) { 6.days.from_now } let(:due_date) { 6.days.from_now }
shared_examples_for 'overlapping dates' do |skip_constraint_test: false| shared_examples_for 'overlapping dates' do
context 'when start_date overlaps' do shared_examples_for 'invalid dates' do
let(:start_date) { 5.days.from_now } context 'with iterations_cadences FF disabled' do
let(:due_date) { 3.weeks.from_now } before do
stub_feature_flags(iteration_cadences: false)
end
it 'is not valid' do it 'is not valid' do
expect(subject).not_to be_valid expect(subject).not_to be_valid
expect(subject.errors[:base]).to include('Dates cannot overlap with other existing Iterations within this group') expect(subject.errors[:base]).to include('Dates cannot overlap with other existing Iterations within this group')
end end
end
unless skip_constraint_test
it 'is not valid even if forced' do it 'is not valid even if forced' do
subject.validate # to generate iid/etc subject.validate # to generate iid/etc
expect { subject.save!(validate: false) }.to raise_exception(ActiveRecord::StatementInvalid, /#{constraint_name}/) expect { subject.save!(validate: false) }.to raise_exception(ActiveRecord::StatementInvalid, /#{constraint_name}/)
end end
it 'is not valid' do
expect(subject).not_to be_valid
expect(subject.errors[:base]).to include('Dates cannot overlap with other existing Iterations within this iterations cadence')
end
end end
context 'when start_date overlaps' do
let(:start_date) { 5.days.from_now }
let(:due_date) { 3.weeks.from_now }
it_behaves_like 'invalid dates'
end end
context 'when due_date overlaps' do context 'when due_date overlaps' do
let(:start_date) { Time.current } let(:start_date) { Time.current }
let(:due_date) { 6.days.from_now } let(:due_date) { 6.days.from_now }
it 'is not valid' do it_behaves_like 'invalid dates'
expect(subject).not_to be_valid
expect(subject.errors[:base]).to include('Dates cannot overlap with other existing Iterations within this group')
end
unless skip_constraint_test
it 'is not valid even if forced' do
subject.validate # to generate iid/etc
expect { subject.save!(validate: false) }.to raise_exception(ActiveRecord::StatementInvalid, /#{constraint_name}/)
end
end
end end
context 'when both overlap' do context 'when both overlap' do
it 'is not valid' do it_behaves_like 'invalid dates'
expect(subject).not_to be_valid
expect(subject.errors[:base]).to include('Dates cannot overlap with other existing Iterations within this group')
end
unless skip_constraint_test
it 'is not valid even if forced' do
subject.validate # to generate iid/etc
expect { subject.save!(validate: false) }.to raise_exception(ActiveRecord::StatementInvalid, /#{constraint_name}/)
end
end
end end
end end
......
...@@ -108,10 +108,19 @@ RSpec.describe 'Updating an Iteration' do ...@@ -108,10 +108,19 @@ RSpec.describe 'Updating an Iteration' do
context 'when another iteration with given dates overlap' do context 'when another iteration with given dates overlap' do
let_it_be(:another_iteration) { create(:iteration, group: group, start_date: start_date.strftime('%F'), due_date: end_date.strftime('%F') ) } let_it_be(:another_iteration) { create(:iteration, group: group, start_date: start_date.strftime('%F'), due_date: end_date.strftime('%F') ) }
it_behaves_like 'a mutation that returns errors in the response',
errors: ["Dates cannot overlap with other existing Iterations within this iterations cadence"]
context 'with iterations_cadences FF disabled' do
before do
stub_feature_flags(iteration_cadences: false)
end
it_behaves_like 'a mutation that returns errors in the response', it_behaves_like 'a mutation that returns errors in the response',
errors: ["Dates cannot overlap with other existing Iterations within this group"] errors: ["Dates cannot overlap with other existing Iterations within this group"]
end end
end end
end
context 'when given a raw model id (backward compatibility)' do context 'when given a raw model id (backward compatibility)' do
let(:attributes) { { id: iteration.id, title: 'title' } } let(:attributes) { { id: iteration.id, title: 'title' } }
......
...@@ -18514,6 +18514,9 @@ msgstr "" ...@@ -18514,6 +18514,9 @@ msgstr ""
msgid "Iteration|Dates cannot overlap with other existing Iterations within this group" msgid "Iteration|Dates cannot overlap with other existing Iterations within this group"
msgstr "" msgstr ""
msgid "Iteration|Dates cannot overlap with other existing Iterations within this iterations cadence"
msgstr ""
msgid "Iteration|cannot be more than 500 years in the future" msgid "Iteration|cannot be more than 500 years in the future"
msgstr "" msgstr ""
......
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