From 8a482b7eb3ae310c6bb1a9258c3891dc95dcd7f3 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 5 Sep 2016 19:14:22 -0300 Subject: Fix Gitlab::ImportExport::ProjectTreeRestorer --- app/models/label.rb | 2 +- lib/gitlab/import_export/relation_factory.rb | 2 +- spec/lib/gitlab/import_export/project.json | 3 ++- spec/models/label_spec.rb | 3 ++- 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) -- cgit v1.2.1