Commit 6a5a8458 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch...

Merge branch '354085-iterations-cannot-be-created-after-turning-off-iteration_cadences-ff' into 'master'

Allow iteration to be created without cadence

See merge request gitlab-org/gitlab!82086
parents f5b7e943 e5699a3f
......@@ -68,7 +68,7 @@ module Mutations
# Once we introduce cadence CRUD support we need to specify to which iteration cadence a given iteration
# belongs if there are more than once cadence in the group. Eventually `iterations_cadence_id` argument should
# become required and there should be no need for group_path argument for iteration.
if args[:iterations_cadence].blank? && parent.iterations_cadences.count > 1
if args[:iterations_cadence].blank? && parent.iterations_cadences.count > 1 && parent.iteration_cadences_feature_flag_enabled?
raise Gitlab::Graphql::Errors::ArgumentError, 'Please provide iterations_cadence_id argument to assign iteration to respective cadence'
end
end
......
......@@ -311,7 +311,7 @@ module EE
# set to 0, i.e. unspecified when creating default iterations as we do validate for presence.
iterations_in_advance: 0,
duration_in_weeks: 0
).safe_find_or_create_by!(group: group)
).order(id: :asc).safe_find_or_create_by!(group: group)
end
# TODO: remove this as part of https://gitlab.com/gitlab-org/gitlab/-/issues/296100
......
......@@ -87,6 +87,22 @@ RSpec.describe 'Creating an Iteration' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['Please provide iterations_cadence_id argument to assign iteration to respective cadence']
context 'when iteration_cadences FF is disabled' do
before do
stub_feature_flags(iteration_cadences: false)
end
it 'creates a new iteration in the default cadence' do
post_graphql_mutation(mutation, current_user: current_user)
iteration_hash = mutation_response['iteration']
aggregate_failures do
expect(iteration_hash['title']).to eq('title')
expect(iteration_hash['iterationCadence']['id']).to eq(group.iterations_cadences.first.to_global_id.to_s)
end
end
end
end
end
......
......@@ -110,39 +110,66 @@ RSpec.describe Iterations::CreateService do
it_behaves_like 'iterations create service'
end
context 'group with multiple cadences' do
let_it_be(:cadence) { create_list(:iterations_cadence, 2, group: group) }
context 'group with multiple cadences', :aggregate_failures do
let_it_be(:parent, refind: true) { group }
it_behaves_like 'iterations create service'
context 'with specific cadence being passed as param' do
let_it_be(:user) { create(:user) }
let(:params) do
let(:base_params) do
{
title: 'v2.1.9',
description: 'Patch release to fix security issue',
start_date: Time.current.to_s,
due_date: 1.day.from_now.to_s,
iterations_cadence_id: group.iterations_cadences.last.id
due_date: 1.day.from_now.to_s
}
end
let(:response) { described_class.new(parent, user, params).execute }
let(:iteration) { response.payload[:iteration] }
let(:saved_iteration) { response.payload[:iteration] }
it_behaves_like 'iterations create service'
context 'with specific cadence being passed as param' do
let_it_be(:user) { create(:user) }
let_it_be(:cadences) { create_list(:iterations_cadence, 2, group: group) }
let(:params) { base_params.merge(iterations_cadence_id: cadences.last.id) }
before do
parent.add_developer(user)
end
context 'valid params' do
it 'creates an iteration' do
expect(response.success?).to be_truthy
expect(iteration).to be_persisted
expect(iteration.iterations_cadence_id).to eq(group.iterations_cadences.last.id)
expect(response).to be_success
expect(saved_iteration).to be_persisted
expect(saved_iteration.iterations_cadence_id).to eq(cadences.last.id)
end
end
context 'when iteration_cadences FF is disabled' do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:cadences) { create_list(:iterations_cadence, 2, group: group) }
let_it_be(:other_iteration) { create(:iteration, iterations_cadence: cadences.second) }
let_it_be(:parent, refind: true) { group }
let(:params) { base_params }
let(:ordered_cadences) { group.iterations_cadences.order(id: :asc) }
before do
stub_feature_flags(iteration_cadences: false)
parent.add_developer(user)
end
it 'creates an iteration in the default (first) cadence' do
expect(response).to be_success
expect(saved_iteration).to be_persisted
expect(saved_iteration.title).to eq('v2.1.9')
expect(saved_iteration.iterations_cadence_id).to eq(ordered_cadences.first.id)
end
it 'does not update the iterations from the non-default cadences' do
expect(response).to be_success
expect(other_iteration.iterations_cadence_id).to eq(ordered_cadences.second.id)
end
end
end
end
......
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