Commit c3f45828 authored by Donald Cook's avatar Donald Cook

Updated label description to accept empty string

Removed unneeded lookup hack
parent d7793c0e
......@@ -217,11 +217,15 @@ class Label < ApplicationRecord
end
def title=(value)
write_attribute(:title, sanitize_value(value)) if value.present?
super if value.blank?
write_attribute(:title, sanitize_value(value))
end
def description=(value)
write_attribute(:description, sanitize_value(value)) if value.present?
return super if value.blank?
write_attribute(:description, sanitize_value(value))
end
##
......
......@@ -13,21 +13,12 @@ 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,
......
......@@ -51,16 +51,4 @@ RSpec.describe Gitlab::ImportExport::Group::ObjectBuilder 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
......@@ -104,6 +104,12 @@ RSpec.describe Label do
label = described_class.new(description: '<b>foo & bar?</b>')
expect(label.description).to eq('foo & bar?')
end
it 'accepts an empty string' do
label = described_class.new(title: 'foo', description: 'bar')
label.update!(description: '')
expect(label.description).to eq('')
end
end
describe 'priorization' do
......
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