debian-mirror-gitlab/spec/services/branches/create_service_spec.rb

49 lines
1.3 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-01-01 13:55:28 +05:30
describe Branches::CreateService do
subject(:service) { described_class.new(project, user) }
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
let_it_be(:project) { create(:project_empty_repo) }
let_it_be(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
describe '#execute' do
context 'when repository is empty' do
it 'creates master branch' do
service.execute('my-feature', 'master')
expect(project.repository.branch_exists?('master')).to be_truthy
end
2020-05-24 23:13:21 +05:30
it 'creates another-feature branch' do
service.execute('another-feature', 'master')
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(project.repository.branch_exists?('another-feature')).to be_truthy
2017-08-17 22:00:37 +05:30
end
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
context 'when branch already exists' do
it 'returns an error' do
result = service.execute('master', 'master')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Branch already exists')
end
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
context 'when incorrect reference is provided' do
2019-12-26 22:10:19 +05:30
before do
allow(project.repository).to receive(:add_branch).and_return(false)
end
2020-05-24 23:13:21 +05:30
it 'returns an error with a reference name' do
result = service.execute('new-feature', 'unknown')
2019-12-26 22:10:19 +05:30
expect(result[:status]).to eq(:error)
2020-05-24 23:13:21 +05:30
expect(result[:message]).to eq('Invalid reference name: unknown')
2019-12-26 22:10:19 +05:30
end
end
2017-08-17 22:00:37 +05:30
end
end