diff options
-rw-r--r-- | app/models/concerns/cache_markdown_field.rb | 6 | ||||
-rw-r--r-- | spec/models/concerns/cache_markdown_field_spec.rb | 19 |
2 files changed, 23 insertions, 2 deletions
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb index 98776eab424..a3a385825b7 100644 --- a/app/models/concerns/cache_markdown_field.rb +++ b/app/models/concerns/cache_markdown_field.rb @@ -85,8 +85,10 @@ module CacheMarkdownField def cached_html_up_to_date?(markdown_field) html_field = cached_markdown_fields.html_field(markdown_field) - cached = cached_html_for(markdown_field).present? && __send__(markdown_field).present? # rubocop:disable GitlabSecurity/PublicSend - return false unless cached + original = __send__(markdown_field) # rubocop:disable GitlabSecurity/PublicSend + cached = cached_html_for(markdown_field) + return true if original.blank? && cached.blank? + return false unless original.present? && cached.present? markdown_changed = attribute_changed?(markdown_field) || false html_changed = attribute_changed?(html_field) || false diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb index 129dfa07f15..12e568f2008 100644 --- a/spec/models/concerns/cache_markdown_field_spec.rb +++ b/spec/models/concerns/cache_markdown_field_spec.rb @@ -171,6 +171,25 @@ describe CacheMarkdownField do is_expected.to be_truthy end + it 'returns true if markdown and html are both empty' do + thing.foo = '' + thing.foo_html = '' + + is_expected.to be_truthy + end + + it 'returns false if markdown is empty but html is not' do + thing.foo = '' + + is_expected.to be_falsey + end + + it 'returns false if html is empty but markdown is not' do + thing.foo_html = '' + + is_expected.to be_falsey + end + it 'returns false if the markdown field is set but the html is not' do thing.foo_html = nil |