project_tree_restorer_spec.rb 2.4 KB
Newer Older
1
2
3
require 'spec_helper'

describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
4
  describe 'restore project tree' do
5
    let(:user) { create(:user) }
6
    let(:namespace) { create(:namespace, owner: user) }
James Lopez's avatar
James Lopez committed
7
    let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: "", project_path: 'path') }
8
9
    let(:project) { create(:empty_project, name: 'project', path: 'project') }
    let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) }
James Lopez's avatar
James Lopez committed
10
11
12
13
14
    let(:restored_project_json) { project_tree_restorer.restore }

    before do
      allow(shared).to receive(:export_path).and_return('spec/lib/gitlab/import_export/')
    end
15
16
17
18
19

    context 'JSON' do
      it 'restores models based on JSON' do
        expect(restored_project_json).to be true
      end
James Lopez's avatar
James Lopez committed
20
21
22
23
24
25

      it 'creates a valid pipeline note' do
        restored_project_json

        expect(Ci::Pipeline.first.notes).not_to be_empty
      end
26

27
      it 'restores the correct event with symbolised data' do
28
29
30
31
        restored_project_json

        expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty
      end
32

33
34
35
36
37
38
39
40
      it 'preserves updated_at on issues' do
        restored_project_json

        issue = Issue.where(description: 'Aliquam enim illo et possimus.').first

        expect(issue.reload.updated_at.to_s).to eq('2016-06-14 15:02:47 UTC')
      end

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
      context 'event at forth level of the tree' do
        let(:event) { Event.where(title: 'test levels').first }

        before do
          restored_project_json
        end

        it 'restores the event' do
          expect(event).not_to be_nil
        end

        it 'event belongs to note, belongs to merge request, belongs to a project' do
          expect(event.note.noteable.project).not_to be_nil
        end
      end
James Lopez's avatar
James Lopez committed
56
57
58
59
60
61

      it 'has the correct data for merge request st_diffs' do
        # makes sure we are renaming the custom method +utf8_st_diffs+ into +st_diffs+

        expect { restored_project_json }.to change(MergeRequestDiff.where.not(st_diffs: nil), :count).by(9)
      end
62
63
64
65
66
67
68
69
70
71
72
73

      it 'has labels associated to label links, associated to issues' do
        restored_project_json

        expect(Label.first.label_links.first.target).not_to be_nil
      end

      it 'has milestones associated to issues' do
        restored_project_json

        expect(Milestone.find_by_description('test milestone').issues).not_to be_empty
      end
74
75
76
    end
  end
end