after_import_service_spec.rb 1.46 KB
Newer Older
Lin Jen-Shin's avatar
Lin Jen-Shin committed
1 2
require 'spec_helper'

Lin Jen-Shin's avatar
Lin Jen-Shin committed
3
describe Projects::AfterImportService do
4 5
  include GitHelpers

Lin Jen-Shin's avatar
Lin Jen-Shin committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  subject { described_class.new(project) }

  let(:project) { create(:project, :repository) }
  let(:repository) { project.repository }
  let(:sha) { project.commit.sha }
  let(:housekeeping_service) { double(:housekeeping_service) }

  describe '#execute' do
    before do
      allow(Projects::HousekeepingService)
        .to receive(:new).with(project).and_return(housekeeping_service)

      allow(housekeeping_service)
        .to receive(:execute).and_yield
    end

    it 'performs housekeeping' do
      subject.execute

      expect(housekeeping_service).to have_received(:execute)
    end

    context 'with some refs in refs/pull/**/*' do
      before do
        repository.write_ref('refs/pull/1/head', sha)
        repository.write_ref('refs/pull/1/merge', sha)

        subject.execute
      end

      it 'removes refs/pull/**/*' do
37
        expect(rugged.references.map(&:name))
Lin Jen-Shin's avatar
Lin Jen-Shin committed
38 39 40 41
          .not_to include(%r{\Arefs/pull/})
      end
    end

42
    Repository::RESERVED_REFS_NAMES.each do |name|
Lin Jen-Shin's avatar
Lin Jen-Shin committed
43 44 45 46 47 48 49 50
      context "with a ref in refs/#{name}/tmp" do
        before do
          repository.write_ref("refs/#{name}/tmp", sha)

          subject.execute
        end

        it "does not remove refs/#{name}/tmp" do
51
          expect(rugged.references.map(&:name))
Lin Jen-Shin's avatar
Lin Jen-Shin committed
52 53 54 55
            .to include("refs/#{name}/tmp")
        end
      end
    end
56 57

    def rugged
58
      rugged_repo(repository)
59
    end
Lin Jen-Shin's avatar
Lin Jen-Shin committed
60 61
  end
end