diff options
Diffstat (limited to 'spec/lib/gitlab/import_export/group/relation_tree_restorer_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import_export/group/relation_tree_restorer_spec.rb | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/spec/lib/gitlab/import_export/group/relation_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/group/relation_tree_restorer_spec.rb index 5e84284a060..07971d6271c 100644 --- a/spec/lib/gitlab/import_export/group/relation_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/group/relation_tree_restorer_spec.rb @@ -9,7 +9,7 @@ require 'spec_helper' -RSpec.describe Gitlab::ImportExport::Group::RelationTreeRestorer do +RSpec.describe Gitlab::ImportExport::Group::RelationTreeRestorer, feature_category: :importers do let(:group) { create(:group).tap { |g| g.add_owner(user) } } let(:importable) { create(:group, parent: group) } @@ -60,4 +60,81 @@ RSpec.describe Gitlab::ImportExport::Group::RelationTreeRestorer do subject end + + describe 'relation object saving' do + let(:importable) { create(:group) } + let(:relation_reader) do + Gitlab::ImportExport::Json::LegacyReader::File.new( + path, + relation_names: [:labels]) + end + + before do + allow(shared.logger).to receive(:info).and_call_original + allow(relation_reader).to receive(:consume_relation).and_call_original + + allow(relation_reader) + .to receive(:consume_relation) + .with(nil, 'labels') + .and_return([[label, 0]]) + end + + context 'when relation object is new' do + context 'when relation object has invalid subrelations' do + let(:label) do + { + 'title' => 'test', + 'priorities' => [LabelPriority.new, LabelPriority.new], + 'type' => 'GroupLabel' + } + end + + it 'logs invalid subrelations' do + expect(shared.logger) + .to receive(:info) + .with( + message: '[Project/Group Import] Invalid subrelation', + group_id: importable.id, + relation_key: 'labels', + error_messages: "Project can't be blank, Priority can't be blank, and Priority is not a number" + ) + + subject + + label = importable.labels.first + failure = importable.import_failures.first + + expect(importable.import_failures.count).to eq(2) + expect(label.title).to eq('test') + expect(failure.exception_class).to eq('ActiveRecord::RecordInvalid') + expect(failure.source).to eq('RelationTreeRestorer#save_relation_object') + expect(failure.exception_message) + .to eq("Project can't be blank, Priority can't be blank, and Priority is not a number") + end + end + end + + context 'when relation object is persisted' do + context 'when relation object is invalid' do + let(:label) { create(:group_label, group: group, title: 'test') } + + it 'saves import failure with nested errors' do + label.priorities << [LabelPriority.new, LabelPriority.new] + + subject + + failure = importable.import_failures.first + + expect(importable.labels.count).to eq(0) + expect(importable.import_failures.count).to eq(1) + expect(failure.exception_class).to eq('ActiveRecord::RecordInvalid') + expect(failure.source).to eq('process_relation_item!') + expect(failure.exception_message) + .to eq("Validation failed: Priorities is invalid, Project can't be blank, Priority can't be blank, " \ + "Priority is not a number, Project can't be blank, Priority can't be blank, " \ + "Priority is not a number") + end + end + end + end end |