diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 18:19:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 18:19:03 +0300 |
commit | 14bd84b61276ef29b97d23642d698de769bacfd2 (patch) | |
tree | f9eba90140c1bd874211dea17750a0d422c04080 /spec/lib/bulk_imports/ndjson_pipeline_spec.rb | |
parent | 891c388697b2db0d8ee0c8358a9bdbf6dc56d581 (diff) |
Add latest changes from gitlab-org/gitlab@15-10-stable-eev15.10.0-rc42
Diffstat (limited to 'spec/lib/bulk_imports/ndjson_pipeline_spec.rb')
-rw-r--r-- | spec/lib/bulk_imports/ndjson_pipeline_spec.rb | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/spec/lib/bulk_imports/ndjson_pipeline_spec.rb b/spec/lib/bulk_imports/ndjson_pipeline_spec.rb index 25edc9feea8..29f42ab3366 100644 --- a/spec/lib/bulk_imports/ndjson_pipeline_spec.rb +++ b/spec/lib/bulk_imports/ndjson_pipeline_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe BulkImports::NdjsonPipeline do +RSpec.describe BulkImports::NdjsonPipeline, feature_category: :importers do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } @@ -150,13 +150,63 @@ RSpec.describe BulkImports::NdjsonPipeline do describe '#load' do context 'when object is not persisted' do + it 'saves the object using RelationObjectSaver' do + object = double(persisted?: false, new_record?: true) + + allow(subject).to receive(:relation_definition) + + expect_next_instance_of(Gitlab::ImportExport::Base::RelationObjectSaver) do |saver| + expect(saver).to receive(:execute) + end + + subject.load(nil, object) + end + + context 'when object is invalid' do + it 'captures invalid subrelations' do + entity = create(:bulk_import_entity, group: group) + tracker = create(:bulk_import_tracker, entity: entity) + context = BulkImports::Pipeline::Context.new(tracker) + + allow(subject).to receive(:context).and_return(context) + + object = group.labels.new(priorities: [LabelPriority.new]) + object.validate + + allow_next_instance_of(Gitlab::ImportExport::Base::RelationObjectSaver) do |saver| + allow(saver).to receive(:execute) + allow(saver).to receive(:invalid_subrelations).and_return(object.priorities) + end + + subject.load(context, object) + + failure = entity.failures.first + + expect(failure.pipeline_class).to eq(tracker.pipeline_name) + expect(failure.exception_class).to eq('RecordInvalid') + 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 object is persisted' do it 'saves the object' do - object = double(persisted?: false) + object = double(new_record?: false, invalid?: false) expect(object).to receive(:save!) subject.load(nil, object) end + + context 'when object is invalid' do + it 'raises ActiveRecord::RecordInvalid exception' do + object = build_stubbed(:issue) + + expect(Gitlab::Import::Errors).to receive(:merge_nested_errors).with(object) + + expect { subject.load(nil, object) }.to raise_error(ActiveRecord::RecordInvalid) + end + end end context 'when object is missing' do |