Commit a49cd500 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'nfriend-fix-release-create-service-when-milestones-nil' into 'master'

Handle `milestones: nil` in `Release::CreateService#execute`

See merge request gitlab-org/gitlab!47229
parents cfa4b126 bc2868e2
......@@ -40,12 +40,11 @@ module Mutations
authorize :create_release
def resolve(project_path:, milestones: nil, assets: nil, **scalars)
def resolve(project_path:, assets: nil, **scalars)
project = authorized_find!(full_path: project_path)
params = {
**scalars,
milestones: milestones.presence || [],
assets: assets.to_h
}.with_indifferent_access
......
......@@ -78,7 +78,7 @@ module Releases
end
def param_for_milestone_titles_provided?
params.key?(:milestones)
!!params[:milestones]
end
def execute_hooks(release, action = 'create')
......
......@@ -167,28 +167,47 @@ RSpec.describe Releases::CreateService do
end
end
context 'when no milestone is passed in' do
it 'creates a release without a milestone tied to it' do
expect(params.key?(:milestones)).to be_falsey
context 'no milestone association behavior' do
let(:title_1) { 'v1.0' }
let(:title_2) { 'v1.0-rc' }
let!(:milestone_1) { create(:milestone, :active, project: project, title: title_1) }
let!(:milestone_2) { create(:milestone, :active, project: project, title: title_2) }
service.execute
release = project.releases.last
context 'when no milestones parameter is passed' do
it 'creates a release without a milestone tied to it' do
expect(service.param_for_milestone_titles_provided?).to be_falsey
expect(release.milestones).to be_empty
service.execute
release = project.releases.last
expect(release.milestones).to be_empty
end
it 'does not create any new MilestoneRelease object' do
expect { service.execute }.not_to change { MilestoneRelease.count }
end
end
it 'does not create any new MilestoneRelease object' do
expect { service.execute }.not_to change { MilestoneRelease.count }
context 'when an empty array is passed as the milestones parameter' do
it 'creates a release without a milestone tied to it' do
service = described_class.new(project, user, params.merge!({ milestones: [] }))
service.execute
release = project.releases.last
expect(release.milestones).to be_empty
end
end
end
context 'when an empty value is passed as a milestone' do
it 'creates a release without a milestone tied to it' do
service = described_class.new(project, user, params.merge!({ milestones: [] }))
service.execute
release = project.releases.last
context 'when nil is passed as the milestones parameter' do
it 'creates a release without a milestone tied to it' do
expect(service.param_for_milestone_titles_provided?).to be_falsey
expect(release.milestones).to be_empty
service = described_class.new(project, user, params.merge!({ milestones: nil }))
service.execute
release = project.releases.last
expect(release.milestones).to be_empty
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