summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-09-05 19:14:22 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-09-16 10:56:48 -0300
commit8a482b7eb3ae310c6bb1a9258c3891dc95dcd7f3 (patch)
tree6533bdaad71c2bae274cb4630281ee83995c1d0b
parent825de2ec79567ec0cb57972ce5190ef15bef3ca8 (diff)
downloadgitlab-ce-8a482b7eb3ae310c6bb1a9258c3891dc95dcd7f3.tar.gz
Fix Gitlab::ImportExport::ProjectTreeRestorer
-rw-r--r--app/models/label.rb2
-rw-r--r--lib/gitlab/import_export/relation_factory.rb2
-rw-r--r--spec/lib/gitlab/import_export/project.json3
-rw-r--r--spec/models/label_spec.rb3
4 files changed, 6 insertions, 4 deletions
diff --git a/app/models/label.rb b/app/models/label.rb
index 1a0ad02567b..9b5f0044544 100644
--- a/app/models/label.rb
+++ b/app/models/label.rb
@@ -20,7 +20,7 @@ class Label < ActiveRecord::Base
has_many :merge_requests, through: :label_links, source: :target, source_type: 'MergeRequest'
validates :color, color: true, allow_blank: false
- validates :subject, presence: true, unless: Proc.new { |service| service.template? }
+ validates :subject_id, :subject_type, presence: true, unless: Proc.new { |service| service.template? }
# Don't allow ',' for label titles
validates :title,
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index b0726268ca6..69c5158b420 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -161,7 +161,7 @@ module Gitlab
# Otherwise always create the record, skipping the extra SELECT clause.
@existing_or_new_object ||= begin
if EXISTING_OBJECT_CHECK.include?(@relation_name)
- existing_object = relation_class.find_or_initialize_by(parsed_relation_hash.slice('title', 'project_id'))
+ existing_object = relation_class.find_or_initialize_by(parsed_relation_hash.slice('title', 'project_id', 'subject_id', 'subject_type'))
existing_object.assign_attributes(parsed_relation_hash)
existing_object
else
diff --git a/spec/lib/gitlab/import_export/project.json b/spec/lib/gitlab/import_export/project.json
index 5114f9c55e1..5e4a10a42b8 100644
--- a/spec/lib/gitlab/import_export/project.json
+++ b/spec/lib/gitlab/import_export/project.json
@@ -59,7 +59,8 @@
"id": 2,
"title": "test2",
"color": "#428bca",
- "project_id": 8,
+ "subject_id": 8,
+ "subject_type": "Project",
"created_at": "2016-07-22T08:55:44.161Z",
"updated_at": "2016-07-22T08:55:44.161Z",
"template": false,
diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb
index bdd75cc760e..a8bd01e1a73 100644
--- a/spec/models/label_spec.rb
+++ b/spec/models/label_spec.rb
@@ -18,7 +18,8 @@ describe Label, models: true do
end
describe 'validation' do
- it { is_expected.to validate_presence_of(:subject) }
+ it { is_expected.to validate_presence_of(:subject_id) }
+ it { is_expected.to validate_presence_of(:subject_type) }
it 'validates color code' do
expect(label).not_to allow_value('G-ITLAB').for(:color)