Commit bc2868e2 authored by Nathan Friend's avatar Nathan Friend Committed by Gabriel Mazetto

Handle milestones: nil in releases create service

This commit updates `Releases::CreateService` to handle cases where
`#execute` is passed a Hash with `milestones: nil`. In this case, the
service should behave as if `milestones: []` was passed.
parent 0e8c176d
......@@ -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,9 +167,15 @@ RSpec.describe Releases::CreateService do
end
end
context 'when no milestone is passed in' do
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) }
context 'when no milestones parameter is passed' do
it 'creates a release without a milestone tied to it' do
expect(params.key?(:milestones)).to be_falsey
expect(service.param_for_milestone_titles_provided?).to be_falsey
service.execute
release = project.releases.last
......@@ -182,7 +188,7 @@ RSpec.describe Releases::CreateService do
end
end
context 'when an empty value is passed as a milestone' do
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
......@@ -191,6 +197,19 @@ RSpec.describe Releases::CreateService do
expect(release.milestones).to be_empty
end
end
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
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
context 'Evidence collection' do
......
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