diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-08-23 21:51:21 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-08-23 21:51:21 +0800 |
commit | 140ac8d2ad81f03f67dddcb565458e9baee79755 (patch) | |
tree | d1403d9f02eb8d4ffa6b91d4c7f51606c13a3078 /spec/services | |
parent | 5f811894a8ba0d85298cc695c360f171d30c193c (diff) | |
download | gitlab-ce-140ac8d2ad81f03f67dddcb565458e9baee79755.tar.gz |
Add changelog and tests
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/projects/housekeeping_service_spec.rb | 13 | ||||
-rw-r--r-- | spec/services/projects/import_export/cleanup_service_spec.rb | 55 |
2 files changed, 68 insertions, 0 deletions
diff --git a/spec/services/projects/housekeeping_service_spec.rb b/spec/services/projects/housekeeping_service_spec.rb index 385f56e447f..6e916a523fe 100644 --- a/spec/services/projects/housekeeping_service_spec.rb +++ b/spec/services/projects/housekeeping_service_spec.rb @@ -23,6 +23,12 @@ describe Projects::HousekeepingService do expect(project.reload.pushes_since_gc).to eq(0) end + it 'yields the block if given' do + expect do |b| + subject.execute(&b) + end.to yield_with_no_args + end + context 'when no lease can be obtained' do before do expect(subject).to receive(:try_obtain_lease).and_return(false) @@ -39,6 +45,13 @@ describe Projects::HousekeepingService do expect { subject.execute }.to raise_error(Projects::HousekeepingService::LeaseTaken) end.not_to change { project.pushes_since_gc } end + + it 'does not yield' do + expect do |b| + expect { subject.execute(&b) } + .to raise_error(Projects::HousekeepingService::LeaseTaken) + end.not_to yield_with_no_args + end end end diff --git a/spec/services/projects/import_export/cleanup_service_spec.rb b/spec/services/projects/import_export/cleanup_service_spec.rb new file mode 100644 index 00000000000..b46efc40a2f --- /dev/null +++ b/spec/services/projects/import_export/cleanup_service_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Projects::ImportExport::CleanupService do + 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 + expect(repository.rugged.references.map(&:name)) + .not_to include(%r{\Arefs/pull/}) + end + end + + described_class::RESERVED_REFS_NAMES.each do |name| + 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(repository.rugged.references.map(&:name)) + .to include("refs/#{name}/tmp") + end + end + end + end +end |