summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2018-12-20 20:22:27 -0600
committerBrett Walker <bwalker@gitlab.com>2019-01-21 13:45:16 -0600
commit45a04f93747a128588268395071f00d0af70acd7 (patch)
tree308c01c9537fa30f72f6a8649ce699a8045fe652 /spec/models
parentc141d0afb15366beb1cae8a240faf6aaeb632214 (diff)
downloadgitlab-ce-45a04f93747a128588268395071f00d0af70acd7.tar.gz
Enable CommonMark source line position information
This adds 'data-sourcepos' to tags, indicating which line of markdown it came from. Sets the stage for intelligently manipulating specific lines of markdown.
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/concerns/cache_markdown_field_spec.rb17
-rw-r--r--spec/models/concerns/cacheable_attributes_spec.rb2
-rw-r--r--spec/models/concerns/redactable_spec.rb2
3 files changed, 14 insertions, 7 deletions
diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb
index f8d50e89d40..da5f184af06 100644
--- a/spec/models/concerns/cache_markdown_field_spec.rb
+++ b/spec/models/concerns/cache_markdown_field_spec.rb
@@ -67,10 +67,11 @@ describe CacheMarkdownField do
end
let(:markdown) { '`Foo`' }
- let(:html) { '<p dir="auto"><code>Foo</code></p>' }
+ let(:html) { '<p data-sourcepos="1:1-1:5" dir="auto"><code>Foo</code></p>' }
let(:updated_markdown) { '`Bar`' }
- let(:updated_html) { '<p dir="auto"><code>Bar</code></p>' }
+ let(:updated_html) { '<p data-sourcepos="1:1-1:5" dir="auto"><code>Bar</code></p>' }
+ let(:updated_redcarpet_html) { '<p dir="auto"><code>Bar</code></p>' }
let(:thing) { ThingWithMarkdownFields.new(foo: markdown, foo_html: html, cached_markdown_version: CacheMarkdownField::CACHE_COMMONMARK_VERSION) }
@@ -95,13 +96,16 @@ describe CacheMarkdownField do
context 'a changed markdown field' do
shared_examples 'with cache version' do |cache_version|
let(:thing) { ThingWithMarkdownFields.new(foo: markdown, foo_html: html, cached_markdown_version: cache_version) }
+ let(:updated_version_html) do
+ cache_version == CacheMarkdownField::CACHE_REDCARPET_VERSION ? updated_redcarpet_html : updated_html
+ end
before do
thing.foo = updated_markdown
thing.save
end
- it { expect(thing.foo_html).to eq(updated_html) }
+ it { expect(thing.foo_html).to eq(updated_version_html) }
it { expect(thing.cached_markdown_version).to eq(cache_version) }
end
@@ -268,6 +272,9 @@ describe CacheMarkdownField do
describe '#refresh_markdown_cache!' do
shared_examples 'with cache version' do |cache_version|
let(:thing) { ThingWithMarkdownFields.new(foo: markdown, foo_html: html, cached_markdown_version: cache_version) }
+ let(:updated_version_html) do
+ cache_version == CacheMarkdownField::CACHE_REDCARPET_VERSION ? updated_redcarpet_html : updated_html
+ end
before do
thing.foo = updated_markdown
@@ -276,7 +283,7 @@ describe CacheMarkdownField do
it 'fills all html fields' do
thing.refresh_markdown_cache!
- expect(thing.foo_html).to eq(updated_html)
+ expect(thing.foo_html).to eq(updated_version_html)
expect(thing.foo_html_changed?).to be_truthy
expect(thing.baz_html_changed?).to be_truthy
end
@@ -291,7 +298,7 @@ describe CacheMarkdownField do
it 'saves the changes using #update_columns' do
expect(thing).to receive(:persisted?).and_return(true)
expect(thing).to receive(:update_columns)
- .with("foo_html" => updated_html, "baz_html" => "", "cached_markdown_version" => cache_version)
+ .with("foo_html" => updated_version_html, "baz_html" => "", "cached_markdown_version" => cache_version)
thing.refresh_markdown_cache!
end
diff --git a/spec/models/concerns/cacheable_attributes_spec.rb b/spec/models/concerns/cacheable_attributes_spec.rb
index 689e7d3058f..9bc381694d6 100644
--- a/spec/models/concerns/cacheable_attributes_spec.rb
+++ b/spec/models/concerns/cacheable_attributes_spec.rb
@@ -177,7 +177,7 @@ describe CacheableAttributes do
cache_record = Appearance.current
expect(cache_record.description).to eq('**Hello**')
- expect(cache_record.description_html).to eq('<p dir="auto"><strong>Hello</strong></p>')
+ expect(cache_record.description_html).to eq('<p data-sourcepos="1:1-1:9" dir="auto"><strong>Hello</strong></p>')
end
end
end
diff --git a/spec/models/concerns/redactable_spec.rb b/spec/models/concerns/redactable_spec.rb
index 7d320edd492..fe17970d75f 100644
--- a/spec/models/concerns/redactable_spec.rb
+++ b/spec/models/concerns/redactable_spec.rb
@@ -35,7 +35,7 @@ describe Redactable do
expected = 'some text /sent_notifications/REDACTED/unsubscribe more text'
expect(model[field]).to eq expected
- expect(model["#{field}_html"]).to eq "<p dir=\"auto\">#{expected}</p>"
+ expect(model["#{field}_html"]).to eq "<p data-sourcepos=\"1:1-1:60\" dir=\"auto\">#{expected}</p>"
end
end