Commit 112e7495 authored by James Lopez's avatar James Lopez
Browse files

fix some more edge cases

parent c0c3b3b4485c
......@@ -80,8 +80,7 @@ def setup_models
case @relation_name
when :merge_request_diff_files then setup_diff
when :notes then setup_note
when :milestone, :milestones,
:project_label, :project_labels then setup_project_group
when *(EXISTING_OBJECT_CHECK - [:project_feature]) then setup_project_group
when 'Ci::Pipeline' then setup_pipeline
else
@relation_hash['project_id'] = @project.id
......@@ -275,7 +274,11 @@ def unknown_service?
end
def find_or_create_object!
finder_hash = parsed_relation_hash.slice('title', 'project_id', 'group_id')
# Can't use IDs as validation exists calilng `.group` or `.project`
finder_hash = { project: @project }.tap do |hash|
hash[:group] = @project.group if relation_class.attribute_method?('group_id')
hash[:title] = parsed_relation_hash['title'] if parsed_relation_hash['title']
end
if label?
label = GroupProjectFinder.find_or_new(Label, finder_hash)
......@@ -288,8 +291,10 @@ def find_or_create_object!
object = GroupProjectFinder.find_or_create(relation_class, finder_hash)
if milestone?
parsed_relation_hash.delete('group_id') if object.project_id
parsed_relation_hash.delete('project_id') if object.group_id
parsed_relation_hash.delete('group_id') if object.project
parsed_relation_hash.delete('project_id') if object.group
parsed_relation_hash.delete('iid')
parsed_relation_hash.delete('id')
end
object
......
......@@ -246,13 +246,6 @@
expect(project.issues.size).to eq(results.fetch(:issues, 0))
end
it 'has issue with group label and project label' do
labels = project.issues.first.labels
expect(labels.where(type: "ProjectLabel").count).to eq(results.fetch(:first_issue_labels, 0))
expect(labels.where(type: "ProjectLabel").where.not(group_id: nil).count).to eq(0)
end
it 'does not set params that are excluded from import_export settings' do
expect(project.import_type).to be_nil
expect(project.creator_id).not_to eq 123
......@@ -268,12 +261,6 @@
it 'has group milestone' do
expect(project.group.milestones.size).to eq(results.fetch(:milestones, 0))
end
it 'has issue with group label' do
labels = project.issues.first.labels
expect(labels.where(type: "GroupLabel").count).to eq(results.fetch(:first_issue_labels, 0))
end
end
context 'Light JSON' do
......@@ -360,12 +347,12 @@
it_behaves_like 'restores project correctly',
issues: 2,
labels: 1,
milestones: 1,
milestones: 2,
first_issue_labels: 1
it_behaves_like 'restores group correctly',
labels: 1,
milestones: 1,
labels: 0,
milestones: 0,
first_issue_labels: 1
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment