Commit 3df6c529 authored by George Koltsov's avatar George Koltsov

Fix user reference transformation in EpicsPipeline

parent 1d5f280e
---
title: Fix user reference transformation in EpicsPipeline
merge_request: 58913
author:
type: fixed
...@@ -11,8 +11,7 @@ module EE ...@@ -11,8 +11,7 @@ module EE
query: EE::BulkImports::Groups::Graphql::GetEpicsQuery query: EE::BulkImports::Groups::Graphql::GetEpicsQuery
transformer ::BulkImports::Common::Transformers::ProhibitedAttributesTransformer transformer ::BulkImports::Common::Transformers::ProhibitedAttributesTransformer
transformer ::BulkImports::Common::Transformers::UserReferenceTransformer, transformer ::BulkImports::Common::Transformers::UserReferenceTransformer, reference: 'author'
reference: :author
transformer EE::BulkImports::Groups::Transformers::EpicAttributesTransformer transformer EE::BulkImports::Groups::Transformers::EpicAttributesTransformer
def transform(_, data) def transform(_, data)
......
...@@ -125,7 +125,7 @@ RSpec.describe EE::BulkImports::Groups::Pipelines::EpicsPipeline, :clean_gitlab_ ...@@ -125,7 +125,7 @@ RSpec.describe EE::BulkImports::Groups::Pipelines::EpicsPipeline, :clean_gitlab_
expect(described_class.transformers) expect(described_class.transformers)
.to contain_exactly( .to contain_exactly(
{ klass: BulkImports::Common::Transformers::ProhibitedAttributesTransformer, options: nil }, { klass: BulkImports::Common::Transformers::ProhibitedAttributesTransformer, options: nil },
{ klass: BulkImports::Common::Transformers::UserReferenceTransformer, options: { reference: :author } }, { klass: BulkImports::Common::Transformers::UserReferenceTransformer, options: { reference: 'author' } },
{ klass: EE::BulkImports::Groups::Transformers::EpicAttributesTransformer, options: nil } { klass: EE::BulkImports::Groups::Transformers::EpicAttributesTransformer, options: nil }
) )
end end
......
...@@ -12,7 +12,7 @@ module BulkImports ...@@ -12,7 +12,7 @@ module BulkImports
DEFAULT_REFERENCE = 'user' DEFAULT_REFERENCE = 'user'
def initialize(options = {}) def initialize(options = {})
@reference = options[:reference] || DEFAULT_REFERENCE @reference = options[:reference].to_s.presence || DEFAULT_REFERENCE
@suffixed_reference = "#{@reference}_id" @suffixed_reference = "#{@reference}_id"
end end
......
...@@ -52,19 +52,26 @@ RSpec.describe BulkImports::Common::Transformers::UserReferenceTransformer do ...@@ -52,19 +52,26 @@ RSpec.describe BulkImports::Common::Transformers::UserReferenceTransformer do
end end
context 'when custom reference is provided' do context 'when custom reference is provided' do
it 'updates provided reference' do shared_examples 'updates provided reference' do |reference|
hash = { let(:hash) do
'author' => { {
'public_email' => user.email 'author' => {
'public_email' => user.email
}
} }
} end
transformer = described_class.new(reference: 'author') it 'updates provided reference' do
result = transformer.transform(context, hash) transformer = described_class.new(reference: reference)
result = transformer.transform(context, hash)
expect(result['author']).to be_nil expect(result['author']).to be_nil
expect(result['author_id']).to eq(user.id) expect(result['author_id']).to eq(user.id)
end
end end
include_examples 'updates provided reference', 'author'
include_examples 'updates provided reference', :author
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment