summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-06-14 10:18:03 +0200
committerJames Lopez <james@jameslopez.es>2016-06-14 10:18:03 +0200
commit9ff1990422eebc11e9c4b523b3b4a58d56943af2 (patch)
tree8a5eefbf2e7ac2a86e7caf7c4a3fd1409c082447
parent9fd35740b8e4b9b32fe86c438edb7e367d5f4850 (diff)
parentf6ed7c8ff8313826a08aace346f30facc55a202f (diff)
downloadgitlab-ce-9ff1990422eebc11e9c4b523b3b4a58d56943af2.tar.gz
Merge branches 'feature/project-export' and 'feature/project-import' of gitlab.com:gitlab-org/gitlab-ce into feature/project-import
-rw-r--r--lib/gitlab/import_export/project_tree_saver.rb2
-rw-r--r--lib/gitlab/import_export/reader.rb (renamed from lib/gitlab/import_export/import_export_reader.rb)2
-rw-r--r--lib/gitlab/import_export/repo_saver.rb1
-rw-r--r--lib/gitlab/import_export/version_saver.rb4
-rw-r--r--spec/lib/gitlab/import_export/import_export_reader_spec.rb26
-rw-r--r--spec/lib/gitlab/import_export/reader_spec.rb87
6 files changed, 91 insertions, 31 deletions
diff --git a/lib/gitlab/import_export/project_tree_saver.rb b/lib/gitlab/import_export/project_tree_saver.rb
index e4674b6cd0b..9153088e966 100644
--- a/lib/gitlab/import_export/project_tree_saver.rb
+++ b/lib/gitlab/import_export/project_tree_saver.rb
@@ -22,7 +22,7 @@ module Gitlab
private
def project_json_tree
- @project.to_json(Gitlab::ImportExport::ImportExportReader.new(shared: @shared).project_tree)
+ @project.to_json(Gitlab::ImportExport::Reader.new(shared: @shared).project_tree)
end
end
end
diff --git a/lib/gitlab/import_export/import_export_reader.rb b/lib/gitlab/import_export/reader.rb
index 25253330745..19defd8f03a 100644
--- a/lib/gitlab/import_export/import_export_reader.rb
+++ b/lib/gitlab/import_export/reader.rb
@@ -1,6 +1,6 @@
module Gitlab
module ImportExport
- class ImportExportReader
+ class Reader
attr_reader :tree
diff --git a/lib/gitlab/import_export/repo_saver.rb b/lib/gitlab/import_export/repo_saver.rb
index 07d71c78f33..cce43fe994b 100644
--- a/lib/gitlab/import_export/repo_saver.rb
+++ b/lib/gitlab/import_export/repo_saver.rb
@@ -12,6 +12,7 @@ module Gitlab
def save
return false if @project.empty_repo?
+
@full_path = File.join(@shared.export_path, ImportExport.project_bundle_filename)
bundle_to_disk
end
diff --git a/lib/gitlab/import_export/version_saver.rb b/lib/gitlab/import_export/version_saver.rb
index fe02a2a6d76..f7f73dc9343 100644
--- a/lib/gitlab/import_export/version_saver.rb
+++ b/lib/gitlab/import_export/version_saver.rb
@@ -9,9 +9,7 @@ module Gitlab
def save
FileUtils.mkdir_p(@shared.export_path)
- File.open(version_file, 'w') do |file|
- file.write(Gitlab::ImportExport.version)
- end
+ File.write(version_file, Gitlab::ImportExport.version, mode: 'w')
rescue => e
@shared.error(e)
false
diff --git a/spec/lib/gitlab/import_export/import_export_reader_spec.rb b/spec/lib/gitlab/import_export/import_export_reader_spec.rb
deleted file mode 100644
index 19f9bdc8d3f..00000000000
--- a/spec/lib/gitlab/import_export/import_export_reader_spec.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require 'spec_helper'
-
-describe Gitlab::ImportExport::ImportExportReader, lib: true do
- let(:shared) { Gitlab::ImportExport::Shared.new(relative_path:'') }
- let(:test_config) { 'spec/support/import_export/import_export.yml' }
- let(:project_tree_hash) do
- {
- only: [:name, :path],
- include: [:issues, :labels,
- { merge_requests: {
- only: [:id],
- except: [:iid],
- include: [:merge_request_diff, :merge_request_test]
- } },
- { commit_statuses: { include: :commit } }]
- }
- end
-
- before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:config_file).and_return(test_config)
- end
-
- it 'generates hash from project tree config' do
- expect(described_class.new(shared: shared).project_tree).to match(project_tree_hash)
- end
-end
diff --git a/spec/lib/gitlab/import_export/reader_spec.rb b/spec/lib/gitlab/import_export/reader_spec.rb
new file mode 100644
index 00000000000..d7029c2efe6
--- /dev/null
+++ b/spec/lib/gitlab/import_export/reader_spec.rb
@@ -0,0 +1,87 @@
+require 'spec_helper'
+
+describe Gitlab::ImportExport::Reader, lib: true do
+ let(:shared) { Gitlab::ImportExport::Shared.new(relative_path:'') }
+ let(:test_config) { 'spec/support/import_export/import_export.yml' }
+ let(:project_tree_hash) do
+ {
+ only: [:name, :path],
+ include: [:issues, :labels,
+ { merge_requests: {
+ only: [:id],
+ except: [:iid],
+ include: [:merge_request_diff, :merge_request_test]
+ } },
+ { commit_statuses: { include: :commit } }]
+ }
+ end
+
+ before do
+ allow_any_instance_of(Gitlab::ImportExport).to receive(:config_file).and_return(test_config)
+ end
+
+ it 'generates hash from project tree config' do
+ expect(described_class.new(shared: shared).project_tree).to match(project_tree_hash)
+ end
+
+ context 'individual scenarios' do
+
+ it 'generates the correct hash for a single project relation' do
+ setup_yaml(project_tree: [:issues])
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [:issues])
+ end
+
+ it 'generates the correct hash for a multiple project relation' do
+ setup_yaml(project_tree: [:issues, :snippets])
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [:issues, :snippets])
+ end
+
+ it 'generates the correct hash for a single sub-relation' do
+ setup_yaml(project_tree: [issues: [:notes]])
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [{ issues: { include: :notes } }])
+ end
+
+ it 'generates the correct hash for a multiple sub-relation' do
+ setup_yaml(project_tree: [merge_requests: [:notes, :merge_request_diff]])
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [{ merge_requests: { include: [:notes, :merge_request_diff] } }])
+ end
+
+ it 'generates the correct hash for a sub-relation with another sub-relation' do
+ setup_yaml(project_tree: [merge_requests: [notes: :author]])
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [{ merge_requests: { include: { notes: { include: :author } } } }])
+ end
+
+ it 'generates the correct hash for a relation with included attributes' do
+ setup_yaml(project_tree: [:issues], included_attributes: {issues: [:name, :description]})
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [{ issues: { only: [:name, :description] } }])
+ end
+
+ it 'generates the correct hash for a relation with excluded attributes' do
+ setup_yaml(project_tree: [:issues], excluded_attributes: {issues: [:name]})
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [{ issues: { except: [:name] } }])
+ end
+
+ it 'generates the correct hash for a relation with both excluded and included attributes' do
+ setup_yaml(project_tree: [:issues], excluded_attributes: {issues: [:name]}, included_attributes: {issues: [:description]})
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [{ issues: { except: [:name], only: [:description]} }])
+ end
+
+ it 'generates the correct hash for a relation with custom methods' do
+ setup_yaml(project_tree: [:issues], methods: {issues: [:name]})
+
+ expect(described_class.new(shared: shared).project_tree).to match(include: [{ issues: { methods: [:name] } }])
+ end
+
+ def setup_yaml(hash)
+ allow(YAML).to receive(:load_file).with(test_config).and_return(hash)
+ end
+ end
+end