diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-03-25 10:41:38 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-03-26 15:10:31 +0300 |
commit | b27c4420c9e62ffc8cf53a4a854f4907454af400 (patch) | |
tree | 2390248510be0e40eb8cd59b80d27fe973b75f9a | |
parent | b4de23a687d16c96f1adaa456e4aeaac64d9cb23 (diff) |
Destroy releases when delete a tag
ok
ok
ok
ok
-rw-r--r-- | app/services/releases/destroy_service.rb | 1 | ||||
-rw-r--r-- | changelogs/unreleased/delete-release-when-delete-tag.yml | 5 | ||||
-rw-r--r-- | spec/services/releases/destroy_service_spec.rb | 8 | ||||
-rw-r--r-- | spec/services/tags/destroy_service_spec.rb | 16 |
4 files changed, 24 insertions, 6 deletions
diff --git a/app/services/releases/destroy_service.rb b/app/services/releases/destroy_service.rb index 8c2bc3b4e6e..f9f6101abdd 100644 --- a/app/services/releases/destroy_service.rb +++ b/app/services/releases/destroy_service.rb @@ -5,7 +5,6 @@ module Releases include Releases::Concerns def execute - return error('Tag does not exist', 404) unless existing_tag return error('Release does not exist', 404) unless release return error('Access Denied', 403) unless allowed? diff --git a/changelogs/unreleased/delete-release-when-delete-tag.yml b/changelogs/unreleased/delete-release-when-delete-tag.yml new file mode 100644 index 00000000000..58acd449bf1 --- /dev/null +++ b/changelogs/unreleased/delete-release-when-delete-tag.yml @@ -0,0 +1,5 @@ +--- +title: Releases will now be automatically deleted when deleting corresponding tag +merge_request: 26530 +author: +type: fixed diff --git a/spec/services/releases/destroy_service_spec.rb b/spec/services/releases/destroy_service_spec.rb index dd5b8708f36..28663ca8853 100644 --- a/spec/services/releases/destroy_service_spec.rb +++ b/spec/services/releases/destroy_service_spec.rb @@ -28,13 +28,11 @@ describe Releases::DestroyService do end end - context 'when tag is not found' do + context 'when tag does not exist in the repository' do let(:tag) { 'v1.1.1' } - it 'returns an error' do - is_expected.to include(status: :error, - message: 'Tag does not exist', - http_status: 404) + it 'removes the orphaned release' do + expect { subject }.to change { project.releases.count }.by(-1) end end diff --git a/spec/services/tags/destroy_service_spec.rb b/spec/services/tags/destroy_service_spec.rb index 7c8c1dd0d3a..a541d300595 100644 --- a/spec/services/tags/destroy_service_spec.rb +++ b/spec/services/tags/destroy_service_spec.rb @@ -7,11 +7,27 @@ describe Tags::DestroyService do let(:service) { described_class.new(project, user) } describe '#execute' do + subject { service.execute(tag_name) } + it 'removes the tag' do expect(repository).to receive(:before_remove_tag) expect(service).to receive(:success) service.execute('v1.1.0') end + + context 'when there is an associated release on the tag' do + let(:tag) { repository.tags.first } + let(:tag_name) { tag.name } + + before do + project.add_maintainer(user) + create(:release, tag: tag_name, project: project) + end + + it 'destroys the release' do + expect { subject }.to change { project.releases.count }.by(-1) + end + end end end |