delete_branch_service_spec.rb 1.11 KB
Newer Older
1 2
require 'spec_helper'

3
describe DeleteBranchService do
4
  let(:project) { create(:project, :repository) }
5
  let(:repository) { project.repository }
6 7 8 9 10 11
  let(:user) { create(:user) }
  let(:service) { described_class.new(project, user) }

  describe '#execute' do
    context 'when user has access to push to repository' do
      before do
12
        project.add_developer(user)
13 14 15
      end

      it 'removes the branch' do
16 17 18 19
        expect(branch_exists?('feature')).to be true

        result = service.execute('feature')

20
        expect(result[:status]).to eq :success
21
        expect(branch_exists?('feature')).to be false
22 23 24 25 26
      end
    end

    context 'when user does not have access to push to repository' do
      it 'does not remove branch' do
27 28 29 30
        expect(branch_exists?('feature')).to be true

        result = service.execute('feature')

31 32
        expect(result[:status]).to eq :error
        expect(result[:message]).to eq 'You dont have push access to repo'
33
        expect(branch_exists?('feature')).to be true
34 35 36
      end
    end
  end
37 38 39 40

  def branch_exists?(branch_name)
    repository.ref_exists?("refs/heads/#{branch_name}")
  end
41
end