2eecfd8f9d
This allows using `CacheMarkdownField` for models that are not backed by ActiveRecord. When the including class inherits `ActiveRecord::Base` we include `Gitlab::MarkdownCache::ActiveRecord::Extension`. This will cause the markdown fields to be rendered and the generated HTML stored in a `<field>_html` attribute on the record. We also store the version used for generating the markdown. All other classes that include this model will include the `Gitlab::MarkdownCache::Redis::Extension`. This add the `<field>_html` attributes to that model and will generate the html in them. The generated HTML will be cached in redis under the key `markdown_cache:<class>:<id>`. The class this included in must therefore respond to `id`.
15 lines
394 B
Ruby
15 lines
394 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
describe Gitlab::MarkdownCache::FieldData do
|
|
subject(:field_data) { described_class.new }
|
|
|
|
before do
|
|
field_data[:description] = { project: double('project in context') }
|
|
end
|
|
|
|
it 'translates a markdown field name into a html field name' do
|
|
expect(field_data.html_field(:description)).to eq("description_html")
|
|
end
|
|
end
|