diff options
Diffstat (limited to 'spec/services/update_release_service_spec.rb')
-rw-r--r-- | spec/services/update_release_service_spec.rb | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/spec/services/update_release_service_spec.rb b/spec/services/update_release_service_spec.rb index dc2d0e2d47a..a24dcabfc2e 100644 --- a/spec/services/update_release_service_spec.rb +++ b/spec/services/update_release_service_spec.rb @@ -5,30 +5,49 @@ describe UpdateReleaseService do let(:user) { create(:user) } let(:tag_name) { project.repository.tag_names.first } let(:description) { 'Awesome release!' } + let(:new_name) { 'A new name' } let(:new_description) { 'The best release!' } - let(:service) { described_class.new(project, user) } + let(:params) { { name: new_name, description: new_description } } + let(:service) { described_class.new(project, user, tag_name, params) } + let(:create_service) { CreateReleaseService.new(project, user) } - context 'with an existing release' do - let(:create_service) { CreateReleaseService.new(project, user) } + before do + create_service.execute(tag_name, description) + end - before do - create_service.execute(tag_name, description) + shared_examples 'a failed update' do + it 'raises an error' do + result = service.execute + expect(result[:status]).to eq(:error) end + end - it 'successfully updates an existing release' do - result = service.execute(tag_name, new_description) - expect(result[:status]).to eq(:success) - expect(project.releases.find_by(tag: tag_name).description).to eq(new_description) - end + it 'successfully updates an existing release' do + result = service.execute + expect(result[:status]).to eq(:success) + + release = project.releases.find_by(tag: tag_name) + expect(release.name).to eq(new_name) + expect(release.description).to eq(new_description) + end + + context 'when the tag does not exists' do + let(:tag_name) { 'foobar' } + + it_behaves_like 'a failed update' end - it 'raises an error if the tag does not exist' do - result = service.execute("foobar", description) - expect(result[:status]).to eq(:error) + context 'when the release does not exist' do + before do + project.releases.delete_all + end + + it_behaves_like 'a failed update' end - it 'raises an error if the release does not exist' do - result = service.execute(tag_name, description) - expect(result[:status]).to eq(:error) + context 'with an invalid update' do + let(:new_description) { '' } + + it_behaves_like 'a failed update' end end |