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

43 lines
1.1 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
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
2020-01-01 13:55:28 +05:30
subject(:service) { described_class.new(project, user) }
2017-08-17 22:00:37 +05:30
describe '#execute' do
context 'when repository is empty' do
let(:project) { create(:project_empty_repo) }
it 'creates master branch' do
service.execute('my-feature', 'master')
expect(project.repository.branch_exists?('master')).to be_truthy
end
it 'creates my-feature branch' do
service.execute('my-feature', 'master')
expect(project.repository.branch_exists?('my-feature')).to be_truthy
end
end
2019-12-26 22:10:19 +05:30
context 'when creating a branch fails' do
let(:project) { create(:project_empty_repo) }
before do
allow(project.repository).to receive(:add_branch).and_return(false)
end
2020-01-01 13:55:28 +05:30
it 'returns an error with the branch name' do
2019-12-26 22:10:19 +05:30
result = service.execute('my-feature', 'master')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq("Invalid reference name: my-feature")
end
end
2017-08-17 22:00:37 +05:30
end
end