summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2019-03-20 17:01:27 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2019-03-20 17:44:29 -0300
commit6264694d572c48f4517f8999a61cc6e0fb32ccae (patch)
treeea9c19c46eb4d37bf5e3f70328e1992bfe902805
parent69dc893da3f19d465c12c6c183270daf38df14b3 (diff)
downloadgitlab-ce-6264694d572c48f4517f8999a61cc6e0fb32ccae.tar.gz
Rename the hidden option to whitelisted
-rw-r--r--app/models/broadcast_message.rb2
-rw-r--r--app/models/concerns/cache_markdown_field.rb13
-rw-r--r--spec/models/concerns/cache_markdown_field_spec.rb4
3 files changed, 10 insertions, 9 deletions
diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb
index e77a1236c39..1c95abdd9ee 100644
--- a/app/models/broadcast_message.rb
+++ b/app/models/broadcast_message.rb
@@ -4,7 +4,7 @@ class BroadcastMessage < ActiveRecord::Base
include CacheMarkdownField
include Sortable
- cache_markdown_field :message, pipeline: :broadcast_message, hidden: false
+ cache_markdown_field :message, pipeline: :broadcast_message, whitelisted: true
validates :message, presence: true
validates :starts_at, presence: true
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb
index 4212224b66a..15d8d58b9b5 100644
--- a/app/models/concerns/cache_markdown_field.rb
+++ b/app/models/concerns/cache_markdown_field.rb
@@ -7,7 +7,7 @@
# cache_markdown_field :foo
# cache_markdown_field :bar
# cache_markdown_field :baz, pipeline: :single_line
-# cache_markdown_field :baz, hidden: false
+# cache_markdown_field :baz, whitelisted: true
#
# Corresponding foo_html, bar_html and baz_html fields should exist.
module CacheMarkdownField
@@ -41,9 +41,9 @@ module CacheMarkdownField
markdown_fields.map { |field| html_field(field) }
end
- def hidden_html_fields
+ def html_fields_whitelisted
markdown_fields.each_with_object([]) do |field, fields|
- if @data[field].fetch(:hidden, true)
+ if @data[field].fetch(:whitelisted, false)
fields << html_field(field)
end
end
@@ -159,13 +159,14 @@ module CacheMarkdownField
def attributes
attrs = attributes_before_markdown_cache
html_fields = cached_markdown_fields.html_fields
- hidden_html_fields = cached_markdown_fields.hidden_html_fields
+ whitelisted = cached_markdown_fields.html_fields_whitelisted
+ exclude_fields = html_fields - whitelisted
- hidden_html_fields.each do |field|
+ exclude_fields.each do |field|
attrs.delete(field)
end
- if (html_fields - hidden_html_fields).empty?
+ if whitelisted.empty?
attrs.delete('cached_markdown_version')
end
diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb
index a2e19f7d687..7d555f15e39 100644
--- a/spec/models/concerns/cache_markdown_field_spec.rb
+++ b/spec/models/concerns/cache_markdown_field_spec.rb
@@ -23,7 +23,7 @@ describe CacheMarkdownField do
include CacheMarkdownField
cache_markdown_field :foo
cache_markdown_field :baz, pipeline: :single_line
- cache_markdown_field :zoo, hidden: false
+ cache_markdown_field :zoo, whitelisted: true
def self.add_attr(name)
self.attribute_names += [name]
@@ -85,7 +85,7 @@ describe CacheMarkdownField do
end
describe '.attributes' do
- it 'excludes cache attributes that is hidden by default' do
+ it 'excludes cache attributes that is blacklisted by default' do
expect(thing.attributes.keys.sort).to eq(%w[bar baz cached_markdown_version foo zoo zoo_html])
end
end