Skip to content
after_import_service_spec.rb 1.46 KiB
Newer Older
Lin Jen-Shin's avatar
Lin Jen-Shin committed
require 'spec_helper'

describe Projects::AfterImportService do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
  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, :gc).and_return(housekeeping_service)
Lin Jen-Shin's avatar
Lin Jen-Shin committed

      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
        expect(rugged.references.map(&:name))
Lin Jen-Shin's avatar
Lin Jen-Shin committed
          .not_to include(%r{\Arefs/pull/})
      end
    end

    Repository::RESERVED_REFS_NAMES.each do |name|
Lin Jen-Shin's avatar
Lin Jen-Shin committed
      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
          expect(rugged.references.map(&:name))
Lin Jen-Shin's avatar
Lin Jen-Shin committed
            .to include("refs/#{name}/tmp")
        end
      end
    end
Lin Jen-Shin's avatar
Lin Jen-Shin committed
  end
end