summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb
blob: 3b7ed7cb32bde7f599473e4d466abb5c353c07d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::ImportExport::LegacyRelationTreeSaver do
  let(:exportable) { create(:group) }
  let(:relation_tree_saver) { described_class.new }
  let(:tree) { {} }

  describe '#serialize' do
    shared_examples 'FastHashSerializer with batch size' do |batch_size|
      let(:serializer) { instance_double(Gitlab::ImportExport::FastHashSerializer) }

      it 'uses FastHashSerializer' do
        expect(Gitlab::ImportExport::FastHashSerializer)
          .to receive(:new)
          .with(exportable, tree, batch_size: batch_size)
          .and_return(serializer)

        expect(serializer).to receive(:execute)

        relation_tree_saver.serialize(exportable, tree)
      end
    end

    context 'when export_reduce_relation_batch_size feature flag is enabled' do
      before do
        stub_feature_flags(export_reduce_relation_batch_size: true)
      end

      include_examples 'FastHashSerializer with batch size', Gitlab::ImportExport::Json::StreamingSerializer::SMALLER_BATCH_SIZE
    end

    context 'when export_reduce_relation_batch_size feature flag is disabled' do
      before do
        stub_feature_flags(export_reduce_relation_batch_size: false)
      end

      include_examples 'FastHashSerializer with batch size', Gitlab::ImportExport::Json::StreamingSerializer::BATCH_SIZE
    end
  end
end