Commit 3a32e605 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch...

Merge branch '338996-when-removing-a-tags-text-description-completely-it-fails-to-remove' into 'master'

Updated label description to accept empty string

See merge request gitlab-org/gitlab!78948
parents 10f44ef6 2c37b583
......@@ -217,11 +217,19 @@ class Label < ApplicationRecord
end
def title=(value)
write_attribute(:title, sanitize_value(value)) if value.present?
if value.blank?
super
else
write_attribute(:title, sanitize_value(value))
end
end
def description=(value)
write_attribute(:description, sanitize_value(value)) if value.present?
if value.blank?
super
else
write_attribute(:description, sanitize_value(value))
end
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