diff options
Diffstat (limited to 'spec/lib/gitlab/import_export/json')
3 files changed, 54 insertions, 8 deletions
diff --git a/spec/lib/gitlab/import_export/json/legacy_reader/file_spec.rb b/spec/lib/gitlab/import_export/json/legacy_reader/file_spec.rb index 9c7f41cbb89..e092891f236 100644 --- a/spec/lib/gitlab/import_export/json/legacy_reader/file_spec.rb +++ b/spec/lib/gitlab/import_export/json/legacy_reader/file_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -require_relative 'shared_example.rb' +require_relative 'shared_example' RSpec.describe Gitlab::ImportExport::JSON::LegacyReader::File do it_behaves_like 'import/export json legacy reader' do diff --git a/spec/lib/gitlab/import_export/json/legacy_reader/hash_spec.rb b/spec/lib/gitlab/import_export/json/legacy_reader/hash_spec.rb index d0899accf59..e47122b6151 100644 --- a/spec/lib/gitlab/import_export/json/legacy_reader/hash_spec.rb +++ b/spec/lib/gitlab/import_export/json/legacy_reader/hash_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -require_relative 'shared_example.rb' +require_relative 'shared_example' RSpec.describe Gitlab::ImportExport::JSON::LegacyReader::Hash do it_behaves_like 'import/export json legacy reader' do diff --git a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb index 762687beedb..a0b2faaecfe 100644 --- a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb +++ b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb @@ -30,12 +30,14 @@ RSpec.describe Gitlab::ImportExport::JSON::StreamingSerializer do let(:json_writer) { instance_double('Gitlab::ImportExport::JSON::LegacyWriter') } let(:hash) { { name: exportable.name, description: exportable.description }.stringify_keys } let(:include) { [] } + let(:custom_orderer) { nil } let(:relations_schema) do { only: [:name, :description], include: include, - preload: { issues: nil } + preload: { issues: nil }, + export_reorder: custom_orderer } end @@ -57,19 +59,63 @@ RSpec.describe Gitlab::ImportExport::JSON::StreamingSerializer do [{ issues: { include: [] } }] end + before do + create_list(:issue, 3, project: exportable, relative_position: 10000) # ascending ids, same position positive + create_list(:issue, 3, project: exportable, relative_position: -5000) # ascending ids, same position negative + create_list(:issue, 3, project: exportable, relative_position: 0) # ascending ids, duplicate positions + create_list(:issue, 3, project: exportable, relative_position: nil) # no position + create_list(:issue, 3, :with_desc_relative_position, project: exportable ) # ascending ids, descending position + end + it 'calls json_writer.write_relation_array with proper params' do expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, array_including(issue.to_json)) subject.execute end - context 'relation ordering' do - before do - create_list(:issue, 5, project: exportable) + context 'default relation ordering' do + it 'orders exported issues by primary key(:id)' do + expected_issues = exportable.issues.reorder(:id).map(&:to_json) + + expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, expected_issues) + + subject.execute end + end - it 'orders exported issues by primary key' do - expected_issues = exportable.issues.reorder(:id).map(&:to_json) + context 'custom relation ordering ascending' do + let(:custom_orderer) do + { + issues: { + column: :relative_position, + direction: :asc, + nulls_position: :nulls_last + } + } + end + + it 'orders exported issues by custom column(relative_position)' do + expected_issues = exportable.issues.reorder(:relative_position, :id).map(&:to_json) + + expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, expected_issues) + + subject.execute + end + end + + context 'custom relation ordering descending' do + let(:custom_orderer) do + { + issues: { + column: :relative_position, + direction: :desc, + nulls_position: :nulls_first + } + } + end + + it 'orders exported issues by custom column(relative_position)' do + expected_issues = exportable.issues.order_relative_position_desc.order(id: :desc).map(&:to_json) expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, expected_issues) |