2017-08-23 09:51:21 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-25 10:38:07 -04:00
|
|
|
describe Projects::AfterImportService do
|
2018-10-01 23:21:46 -04:00
|
|
|
include GitHelpers
|
|
|
|
|
2017-08-23 09:51:21 -04:00
|
|
|
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
|
2018-06-05 11:58:28 -04:00
|
|
|
expect(rugged.references.map(&:name))
|
2017-08-23 09:51:21 -04:00
|
|
|
.not_to include(%r{\Arefs/pull/})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-25 11:00:06 -04:00
|
|
|
Repository::RESERVED_REFS_NAMES.each do |name|
|
2017-08-23 09:51:21 -04:00
|
|
|
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
|
2018-06-05 11:58:28 -04:00
|
|
|
expect(rugged.references.map(&:name))
|
2017-08-23 09:51:21 -04:00
|
|
|
.to include("refs/#{name}/tmp")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-06-05 11:58:28 -04:00
|
|
|
|
|
|
|
def rugged
|
2018-10-01 23:21:46 -04:00
|
|
|
rugged_repo(repository)
|
2018-06-05 11:58:28 -04:00
|
|
|
end
|
2017-08-23 09:51:21 -04:00
|
|
|
end
|
|
|
|
end
|