summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/import_export/wiki_restorer_spec.rb
blob: 9409c08e280c132b040bd25d12be0574e901bf38 (plain)
1
2
3
4
5
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
37
38
39
40
41
42
43
44
45
require 'spec_helper'

describe Gitlab::ImportExport::WikiRestorer do
  describe 'restore a wiki Git repo' do
    let!(:project_with_wiki) { create(:project, :wiki_repo) }
    let!(:project_without_wiki) { create(:project) }
    let!(:project) { create(:project) }
    let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
    let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: project.full_path) }
    let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_with_wiki, shared: shared) }
    let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) }
    let(:restorer) do
      described_class.new(path_to_bundle: bundle_path,
                          shared: shared,
                          project: project.wiki,
                          wiki_enabled: true)
    end

    before do
      allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)

      bundler.save
    end

    after do
      FileUtils.rm_rf(export_path)
      Gitlab::Shell.new.remove_repository(project_with_wiki.wiki.repository_storage_path, project_with_wiki.wiki.disk_path)
      Gitlab::Shell.new.remove_repository(project.wiki.repository_storage_path, project.wiki.disk_path)
    end

    it 'restores the wiki repo successfully' do
      expect(restorer.restore).to be true
    end

    describe "no wiki in the bundle" do
      let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_without_wiki, shared: shared) }

      it 'creates an empty wiki' do
        expect(restorer.restore).to be true

        expect(project.wiki_repository_exists?).to be true
      end
    end
  end
end