gitlab-org--gitlab-foss/spec/services/create_release_service_spec.rb
Alessio Caiazza b782ba1113
Add name, author and sha to releases
This commit adds a name to each release, defaulting it to tag name,
keeps track of the SHA when a new release is created and tracks the
current user as release author.
2018-12-13 12:15:21 +01:00

39 lines
1.3 KiB
Ruby

require 'spec_helper'
describe CreateReleaseService do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:tag_name) { project.repository.tag_names.first }
let(:description) { 'Awesome release!' }
let(:service) { described_class.new(project, user) }
let(:tag) { project.repository.find_tag(tag_name) }
let(:sha) { tag.dereferenced_target.sha }
it 'creates a new release' do
result = service.execute(tag_name, description)
expect(result[:status]).to eq(:success)
release = project.releases.find_by(tag: tag_name)
expect(release).not_to be_nil
expect(release.description).to eq(description)
expect(release.name).to eq(tag_name)
expect(release.sha).to eq(sha)
expect(release.author).to eq(user)
end
it 'raises an error if the tag does not exist' do
result = service.execute("foobar", description)
expect(result[:status]).to eq(:error)
end
context 'there already exists a release on a tag' do
before do
service.execute(tag_name, description)
end
it 'raises an error and does not update the release' do
result = service.execute(tag_name, 'The best release!')
expect(result[:status]).to eq(:error)
expect(project.releases.find_by(tag: tag_name).description).to eq(description)
end
end
end