diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-26 21:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-26 21:09:24 +0300 |
commit | 619d0b6922a6cf95d291fbbf5fa3d09e772a1ea8 (patch) | |
tree | fb8f8e036cec1b32166206bb5102af6c5dca8cfe /spec/lib/gitlab/import_export/project/tree_loader_spec.rb | |
parent | 17ab40ca089e1aef61a83f77ab6df62a72f6ce06 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/import_export/project/tree_loader_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import_export/project/tree_loader_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import_export/project/tree_loader_spec.rb b/spec/lib/gitlab/import_export/project/tree_loader_spec.rb new file mode 100644 index 00000000000..e683eefa7c0 --- /dev/null +++ b/spec/lib/gitlab/import_export/project/tree_loader_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::ImportExport::Project::TreeLoader do + let(:fixture) { 'spec/fixtures/lib/gitlab/import_export/with_duplicates.json' } + let(:project_tree) { JSON.parse(File.read(fixture)) } + + context 'without de-duplicating entries' do + let(:parsed_tree) do + subject.load(fixture) + end + + it 'parses the JSON into the expected tree' do + expect(parsed_tree).to eq(project_tree) + end + + it 'does not de-duplicate entries' do + expect(parsed_tree['duped_hash_with_id']).not_to be(parsed_tree['array'][0]['duped_hash_with_id']) + end + end + + context 'with de-duplicating entries' do + let(:parsed_tree) do + subject.load(fixture, dedup_entries: true) + end + + it 'parses the JSON into the expected tree' do + expect(parsed_tree).to eq(project_tree) + end + + it 'de-duplicates equal values' do + expect(parsed_tree['duped_hash_with_id']).to be(parsed_tree['array'][0]['duped_hash_with_id']) + expect(parsed_tree['duped_hash_with_id']).to be(parsed_tree['nested']['duped_hash_with_id']) + expect(parsed_tree['duped_array']).to be(parsed_tree['array'][1]['duped_array']) + expect(parsed_tree['duped_array']).to be(parsed_tree['nested']['duped_array']) + end + + it 'does not de-duplicate hashes without IDs' do + expect(parsed_tree['duped_hash_no_id']).to eq(parsed_tree['array'][2]['duped_hash_no_id']) + expect(parsed_tree['duped_hash_no_id']).not_to be(parsed_tree['array'][2]['duped_hash_no_id']) + end + + it 'keeps single entries intact' do + expect(parsed_tree['simple']).to eq(42) + expect(parsed_tree['nested']['array']).to eq(["don't touch"]) + end + end +end |