Welcome to mirror list, hosted at ThFree Co, Russian Federation.

namespace_settings_pipeline_spec.rb « pipelines « groups « bulk_imports « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 90b63453b88f89c877f22b3a40065ad7dce537f3 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::Groups::Pipelines::NamespaceSettingsPipeline do
  subject(:pipeline) { described_class.new(context) }

  let_it_be(:user) { create(:user) }
  let_it_be(:group) { create(:group, namespace_settings: create(:namespace_settings) ) }
  let_it_be(:bulk_import) { create(:bulk_import, user: user) }
  let_it_be(:entity) { create(:bulk_import_entity, :group_entity, group: group, bulk_import: bulk_import) }
  let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) }
  let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) }

  before do
    group.add_owner(user)
  end

  describe '#run' do
    before do
      allow_next_instance_of(BulkImports::Common::Extractors::NdjsonExtractor) do |extractor|
        namespace_settings_attributes = {
          'namespace_id' => 22,
          'prevent_forking_outside_group' => true,
          'prevent_sharing_groups_outside_hierarchy' => true
        }
        allow(extractor).to receive(:extract).and_return(
          BulkImports::Pipeline::ExtractedData.new(data: [[namespace_settings_attributes, 0]])
        )
      end
    end

    it 'imports allowed namespace settings attributes' do
      expect(Groups::UpdateService).to receive(:new).with(
        group, user, { prevent_sharing_groups_outside_hierarchy: true }
      ).and_call_original

      pipeline.run

      expect(group.namespace_settings).to have_attributes(prevent_sharing_groups_outside_hierarchy: true)
    end
  end

  describe '#transform' do
    it 'fetches only allowed attributes and symbolize keys' do
      all_model_attributes = NamespaceSetting.new.attributes

      transformed_data = pipeline.transform(context, [all_model_attributes, 0])

      expect(transformed_data.keys).to match_array([:prevent_sharing_groups_outside_hierarchy])
    end

    context 'when there is no data to transform' do
      it do
        namespace_settings_attributes = nil

        transformed_data = pipeline.transform(context, namespace_settings_attributes)

        expect(transformed_data).to eq(nil)
      end
    end
  end

  describe '#after_run' do
    it 'calls extractor#remove_tmpdir' do
      expect_next_instance_of(BulkImports::Common::Extractors::NdjsonExtractor) do |extractor|
        expect(extractor).to receive(:remove_tmpdir)
      end

      context = instance_double(BulkImports::Pipeline::Context)

      pipeline.after_run(context)
    end
  end
end