debian-mirror-gitlab/spec/lib/bulk_imports/pipeline_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

149 lines
4.7 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'fast_spec_helper'
2021-01-29 00:20:46 +05:30
2021-02-22 17:27:13 +05:30
RSpec.describe BulkImports::Pipeline do
2021-04-29 21:17:54 +05:30
let(:context) { instance_double(BulkImports::Pipeline::Context, tracker: nil) }
2021-04-17 20:07:23 +05:30
before do
stub_const('BulkImports::Extractor', Class.new)
stub_const('BulkImports::Transformer', Class.new)
stub_const('BulkImports::Loader', Class.new)
2021-02-22 17:27:13 +05:30
2021-04-17 20:07:23 +05:30
klass = Class.new do
include BulkImports::Pipeline
2021-01-29 00:20:46 +05:30
2021-04-17 20:07:23 +05:30
abort_on_failure!
2021-01-29 00:20:46 +05:30
2021-04-17 20:07:23 +05:30
extractor BulkImports::Extractor, foo: :bar
transformer BulkImports::Transformer, foo: :bar
loader BulkImports::Loader, foo: :bar
2021-01-29 00:20:46 +05:30
end
2022-11-25 23:54:43 +05:30
stub_const('BulkImports::TestWikiPipeline', klass)
2021-04-17 20:07:23 +05:30
end
describe 'pipeline attributes' do
2021-01-29 00:20:46 +05:30
describe 'getters' do
it 'retrieves class attributes' do
2022-11-25 23:54:43 +05:30
expect(BulkImports::TestWikiPipeline.get_extractor).to eq({ klass: BulkImports::Extractor, options: { foo: :bar } })
expect(BulkImports::TestWikiPipeline.transformers).to contain_exactly({ klass: BulkImports::Transformer, options: { foo: :bar } })
expect(BulkImports::TestWikiPipeline.get_loader).to eq({ klass: BulkImports::Loader, options: { foo: :bar } })
expect(BulkImports::TestWikiPipeline.abort_on_failure?).to eq(true)
expect(BulkImports::TestWikiPipeline.relation).to eq('test_wiki')
2021-01-29 00:20:46 +05:30
end
2021-04-17 20:07:23 +05:30
context 'when extractor and loader are defined within the pipeline' do
before do
klass = Class.new do
include BulkImports::Pipeline
def extract; end
def load; end
end
stub_const('BulkImports::AnotherPipeline', klass)
end
it 'returns itself when retrieving extractor & loader' do
2021-04-29 21:17:54 +05:30
pipeline = BulkImports::AnotherPipeline.new(context)
2021-04-17 20:07:23 +05:30
expect(pipeline.send(:extractor)).to eq(pipeline)
expect(pipeline.send(:loader)).to eq(pipeline)
end
end
2021-01-29 00:20:46 +05:30
end
describe 'setters' do
it 'sets class attributes' do
klass = Class.new
options = { test: :test }
2022-11-25 23:54:43 +05:30
BulkImports::TestWikiPipeline.extractor(klass, options)
BulkImports::TestWikiPipeline.transformer(klass, options)
BulkImports::TestWikiPipeline.loader(klass, options)
BulkImports::TestWikiPipeline.abort_on_failure!
BulkImports::TestWikiPipeline.file_extraction_pipeline!
2021-01-29 00:20:46 +05:30
2022-11-25 23:54:43 +05:30
expect(BulkImports::TestWikiPipeline.get_extractor).to eq({ klass: klass, options: options })
2021-01-29 00:20:46 +05:30
2022-11-25 23:54:43 +05:30
expect(BulkImports::TestWikiPipeline.transformers)
2021-01-29 00:20:46 +05:30
.to contain_exactly(
{ klass: BulkImports::Transformer, options: { foo: :bar } },
{ klass: klass, options: options })
2022-11-25 23:54:43 +05:30
expect(BulkImports::TestWikiPipeline.get_loader).to eq({ klass: klass, options: options })
2021-02-22 17:27:13 +05:30
2022-11-25 23:54:43 +05:30
expect(BulkImports::TestWikiPipeline.abort_on_failure?).to eq(true)
expect(BulkImports::TestWikiPipeline.file_extraction_pipeline?).to eq(true)
2021-01-29 00:20:46 +05:30
end
end
end
2021-04-17 20:07:23 +05:30
describe '#instantiate' do
context 'when options are present' do
it 'instantiates new object with options' do
expect(BulkImports::Extractor).to receive(:new).with(foo: :bar)
expect(BulkImports::Transformer).to receive(:new).with(foo: :bar)
expect(BulkImports::Loader).to receive(:new).with(foo: :bar)
2022-11-25 23:54:43 +05:30
pipeline = BulkImports::TestWikiPipeline.new(context)
2021-04-17 20:07:23 +05:30
pipeline.send(:extractor)
pipeline.send(:transformers)
pipeline.send(:loader)
end
end
context 'when options are missing' do
before do
klass = Class.new do
include BulkImports::Pipeline
extractor BulkImports::Extractor
transformer BulkImports::Transformer
loader BulkImports::Loader
end
stub_const('BulkImports::NoOptionsPipeline', klass)
end
it 'instantiates new object without options' do
expect(BulkImports::Extractor).to receive(:new).with(no_args)
expect(BulkImports::Transformer).to receive(:new).with(no_args)
expect(BulkImports::Loader).to receive(:new).with(no_args)
2021-04-29 21:17:54 +05:30
pipeline = BulkImports::NoOptionsPipeline.new(context)
2021-04-17 20:07:23 +05:30
pipeline.send(:extractor)
pipeline.send(:transformers)
pipeline.send(:loader)
end
end
end
describe '#transformers' do
before do
klass = Class.new do
include BulkImports::Pipeline
transformer BulkImports::Transformer
def transform; end
end
stub_const('BulkImports::TransformersPipeline', klass)
end
it 'has instance transform method first to run' do
transformer = double
allow(BulkImports::Transformer).to receive(:new).and_return(transformer)
2021-04-29 21:17:54 +05:30
pipeline = BulkImports::TransformersPipeline.new(context)
2021-04-17 20:07:23 +05:30
expect(pipeline.send(:transformers)).to eq([pipeline, transformer])
end
end
2021-01-29 00:20:46 +05:30
end