Commit 31e90033 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'georgekoltsov/object_builder_convert_empty_strings' into 'master'

Convert empty strings to nil in ImportExport::BaseObjectBuilder

See merge request gitlab-org/gitlab!25187
parents 1765d225 4783fab6
---
title: Fix Group Import existing objects lookup when description attribute is an empty
string
merge_request: 25187
author:
type: fixed
......@@ -18,12 +18,21 @@ module Gitlab
super
@group = @attributes['group']
update_description
end
private
attr_reader :group
# Convert description empty string to nil
# due to existing object being saved with description: nil
# Which makes object lookup to fail since nil != ''
def update_description
attributes['description'] = nil if attributes['description'] == ''
end
def where_clauses
[
where_clause_base,
......
......@@ -26,6 +26,16 @@ describe Gitlab::ImportExport::GroupObjectBuilder do
expect(label.persisted?).to be true
end
context 'when description is an empty string' do
let(:label_attributes) { base_attributes.merge('type' => 'GroupLabel', 'description' => '') }
it 'finds the existing group label' do
group_label = create(:group_label, label_attributes)
expect(described_class.build(Label, label_attributes)).to eq(group_label)
end
end
end
context 'milestones' do
......@@ -41,4 +51,16 @@ describe Gitlab::ImportExport::GroupObjectBuilder do
expect(milestone.persisted?).to be true
end
end
describe '#initialize' do
context 'when attributes contain description as empty string' do
let(:attributes) { base_attributes.merge('description' => '') }
it 'converts empty string to nil' do
builder = described_class.new(Label, attributes)
expect(builder.send(:attributes)).to include({ 'description' => nil })
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