summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-06-14 10:12:41 +0200
committerJames Lopez <james@jameslopez.es>2016-06-14 10:12:41 +0200
commitfde90c3e7fe97420e029c1e7c02227d3e8773c7f (patch)
tree2422b00d78ff9fbc3baac068f94a4c2eeb8cdc6a
parent4020b0f55fa7df3a410a11debfd155527b1a79ee (diff)
downloadgitlab-ce-fde90c3e7fe97420e029c1e7c02227d3e8773c7f.tar.gz
better coverage for Reader
-rw-r--r--spec/lib/gitlab/import_export/reader_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import_export/reader_spec.rb b/spec/lib/gitlab/import_export/reader_spec.rb
index f16b4f8e2bd..d7029c2efe6 100644
--- a/spec/lib/gitlab/import_export/reader_spec.rb
+++ b/spec/lib/gitlab/import_export/reader_spec.rb
@@ -23,4 +23,65 @@ describe Gitlab::ImportExport::Reader, lib: true do
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