Commit 6e462e0d authored by Etienne Baqué's avatar Etienne Baqué

Added and fixed tests releated to Release services

Added tests for Create and Update release services.
Fixed DestroyService release rspec test.
parent 3276f78e
...@@ -49,7 +49,6 @@ module Releases ...@@ -49,7 +49,6 @@ module Releases
success(tag: tag, release: release) success(tag: tag, release: release)
rescue => e rescue => e
binding.pry
error(e.message, 400) error(e.message, 400)
end end
......
...@@ -72,7 +72,7 @@ describe Milestones::DestroyService do ...@@ -72,7 +72,7 @@ describe Milestones::DestroyService do
:release, :release,
tag: 'v1.0', tag: 'v1.0',
project: project, project: project,
milestone: milestone milestones: [milestone]
) )
expect { service.execute(milestone) }.not_to change { Release.count } expect { service.execute(milestone) }.not_to change { Release.count }
......
...@@ -122,6 +122,41 @@ describe Releases::CreateService do ...@@ -122,6 +122,41 @@ describe Releases::CreateService do
end end
end end
context 'when multiple existing milestone titles are passed in' 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) }
let!(:params_with_milestones) { params.merge!({ milestones: [title_1, title_2] }) }
it 'creates a release and ties it to these milestones' do
described_class.new(project, user, params_with_milestones).execute
release = project.releases.last
expect(release.milestones.map(&:title)).to include(title_1, title_2)
end
end
context 'when multiple miletone titles are passed in but one of them does not exist' do
let(:title) { 'v1.0' }
let(:inexistent_title) { 'v111.0' }
let!(:milestone) { create(:milestone, :active, project: project, title: title) }
let!(:params_with_milestones) { params.merge!({ milestones: [title, inexistent_title] }) }
it 'raises an error' do
result = described_class.new(milestone.project, user, params_with_milestones).execute
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq("Inexistent milestone(s): #{inexistent_title}")
end
it 'does not create any release' do
expect do
described_class.new(milestone.project, user, params_with_milestones).execute
end.not_to change(Release, :count)
end
end
context 'when no milestone is passed in' do context 'when no milestone is passed in' do
it 'creates a release without a milestone tied to it' do it 'creates a release without a milestone tied to it' do
expect(params.key? :milestones).to be_falsey expect(params.key? :milestones).to be_falsey
......
...@@ -60,7 +60,7 @@ describe Releases::DestroyService do ...@@ -60,7 +60,7 @@ describe Releases::DestroyService do
context 'when a milestone is tied to the release' do context 'when a milestone is tied to the release' do
let!(:milestone) { create(:milestone, :active, project: project, title: 'v1.0') } let!(:milestone) { create(:milestone, :active, project: project, title: 'v1.0') }
let!(:release) { create(:release, milestone: milestone, project: project, tag: tag) } let!(:release) { create(:release, milestones: [milestone], project: project, tag: tag) }
it 'destroys the release but leave the milestone intact' do it 'destroys the release but leave the milestone intact' do
expect { subject }.not_to change { Milestone.count } expect { subject }.not_to change { Milestone.count }
......
...@@ -83,5 +83,27 @@ describe Releases::UpdateService do ...@@ -83,5 +83,27 @@ describe Releases::UpdateService do
expect(release.milestones).not_to be_present expect(release.milestones).not_to be_present
end end
end end
context "when multiple new milestones are passed in" do
let(:old_title) { 'v1.0' }
let(:new_title_1) { 'v2.0' }
let(:new_title_2) { 'v2.0-rc' }
let(:milestone) { create(:milestone, project: project, title: old_title) }
let(:new_milestone_1) { create(:milestone, project: project, title: new_title_1) }
let!(:new_milestone_2) { create(:milestone, project: project, title: new_title_2) }
let(:params_with_milestones) { params.merge!({ milestones: [new_title_1, new_title_2] }) }
before do
release.milestones << milestone
described_class.new(new_milestone_1.project, user, params_with_milestones).execute
release.reload
end
it 'removes the old milestone and update the release with the new ones' do
expect(release.milestones.map(&:title)).to include(new_title_1, new_title_2)
expect(release.milestones.map(&:title)).not_to include(old_title)
end
end
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