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

attributes_spec.rb « pipeline « bulk_imports « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 54c5dbd4cae1c9a7e9393c9552007148eb1f67cc (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::Pipeline::Attributes do
  describe 'pipeline attributes' do
    before do
      stub_const('BulkImports::Extractor', Class.new)
      stub_const('BulkImports::Transformer', Class.new)
      stub_const('BulkImports::Loader', Class.new)

      klass = Class.new do
        include BulkImports::Pipeline::Attributes

        extractor BulkImports::Extractor, { foo: :bar }
        transformer BulkImports::Transformer, { foo: :bar }
        loader BulkImports::Loader, { foo: :bar }
      end

      stub_const('BulkImports::MyPipeline', klass)
    end

    describe 'getters' do
      it 'retrieves class attributes' do
        expect(BulkImports::MyPipeline.extractors).to contain_exactly({ klass: BulkImports::Extractor, options: { foo: :bar } })
        expect(BulkImports::MyPipeline.transformers).to contain_exactly({ klass: BulkImports::Transformer, options: { foo: :bar } })
        expect(BulkImports::MyPipeline.loaders).to contain_exactly({ klass: BulkImports::Loader, options: { foo: :bar } })
      end
    end

    describe 'setters' do
      it 'sets class attributes' do
        klass = Class.new
        options = { test: :test }

        BulkImports::MyPipeline.extractor(klass, options)
        BulkImports::MyPipeline.transformer(klass, options)
        BulkImports::MyPipeline.loader(klass, options)

        expect(BulkImports::MyPipeline.extractors)
          .to contain_exactly(
            { klass: BulkImports::Extractor, options: { foo: :bar } },
            { klass: klass, options: options })

        expect(BulkImports::MyPipeline.transformers)
          .to contain_exactly(
            { klass: BulkImports::Transformer, options: { foo: :bar } },
            { klass: klass, options: options })

        expect(BulkImports::MyPipeline.loaders)
          .to contain_exactly(
            { klass: BulkImports::Loader, options: { foo: :bar } },
            { klass: klass, options: options })
      end
    end
  end
end