Rename the hidden option to whitelisted

parent 69dc893d
......@@ -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
......
......@@ -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
......
......@@ -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
......
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