2016-06-02 11:05:42 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Tags::CreateService do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:service) { described_class.new(project, user) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'creates the tag and returns success' do
|
|
|
|
response = service.execute('v42.42.42', 'master', 'Foo')
|
|
|
|
|
|
|
|
expect(response[:status]).to eq(:success)
|
|
|
|
expect(response[:tag]).to be_a Gitlab::Git::Tag
|
|
|
|
expect(response[:tag].name).to eq('v42.42.42')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when target is invalid' do
|
|
|
|
it 'returns an error' do
|
|
|
|
response = service.execute('v1.1.0', 'foo', 'Foo')
|
|
|
|
|
|
|
|
expect(response).to eq(status: :error,
|
|
|
|
message: 'Target foo is invalid')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when tag already exists' do
|
|
|
|
it 'returns an error' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(repository).to receive(:add_tag)
|
|
|
|
.with(user, 'v1.1.0', 'master', 'Foo')
|
2018-03-17 18:26:18 +05:30
|
|
|
.and_raise(Gitlab::Git::Repository::TagExistsError)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
response = service.execute('v1.1.0', 'master', 'Foo')
|
|
|
|
|
|
|
|
expect(response).to eq(status: :error,
|
|
|
|
message: 'Tag v1.1.0 already exists')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pre-receive hook fails' do
|
|
|
|
it 'returns an error' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(repository).to receive(:add_tag)
|
|
|
|
.with(user, 'v1.1.0', 'master', 'Foo')
|
2018-03-17 18:26:18 +05:30
|
|
|
.and_raise(Gitlab::Git::HooksService::PreReceiveError, 'something went wrong')
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
response = service.execute('v1.1.0', 'master', 'Foo')
|
|
|
|
|
|
|
|
expect(response).to eq(status: :error,
|
2016-08-24 12:49:21 +05:30
|
|
|
message: 'something went wrong')
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|