summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/fixtures/static/issue_with_mermaid_graph.html4
-rw-r--r--spec/models/concerns/cache_markdown_field_spec.rb8
-rw-r--r--spec/support/shared_examples/models/mentionable_shared_examples.rb60
3 files changed, 41 insertions, 31 deletions
diff --git a/spec/frontend/fixtures/static/issue_with_mermaid_graph.html b/spec/frontend/fixtures/static/issue_with_mermaid_graph.html
index 4b60842a655..e9fa75c8ba9 100644
--- a/spec/frontend/fixtures/static/issue_with_mermaid_graph.html
+++ b/spec/frontend/fixtures/static/issue_with_mermaid_graph.html
@@ -15,14 +15,14 @@
<g class="edgeLabels"></g>
<g class="nodes">
<g
- class="node js-issuable-actions btn-close clickable"
+ class="node js-issuable-buttons btn-close clickable"
style="opacity: 1;"
id="A"
transform="translate(92.67500305175781,25.25)"
title="click to PUT"
>
<a
- class="js-issuable-actions btn-close clickable"
+ class="js-issuable-buttons btn-close clickable"
href="https://invalid"
rel="noopener"
>
diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb
index 193144fcb0e..c46ebcf324c 100644
--- a/spec/models/concerns/cache_markdown_field_spec.rb
+++ b/spec/models/concerns/cache_markdown_field_spec.rb
@@ -209,8 +209,8 @@ describe CacheMarkdownField, :clean_gitlab_redis_cache do
thing.cached_markdown_version += 1
end
- it 'calls #refresh_markdown_cache' do
- expect(thing).to receive(:refresh_markdown_cache)
+ it 'calls #refresh_markdown_cache!' do
+ expect(thing).to receive(:refresh_markdown_cache!)
expect(thing.updated_cached_html_for(:description)).to eq(html)
end
@@ -227,8 +227,8 @@ describe CacheMarkdownField, :clean_gitlab_redis_cache do
thing.try(:save)
end
- it 'does not call #refresh_markdown_cache' do
- expect(thing).not_to receive(:refresh_markdown_cache)
+ it 'does not call #refresh_markdown_cache!' do
+ expect(thing).not_to receive(:refresh_markdown_cache!)
expect(thing.updated_cached_html_for(:description)).to eq(html)
end
diff --git a/spec/support/shared_examples/models/mentionable_shared_examples.rb b/spec/support/shared_examples/models/mentionable_shared_examples.rb
index d3e9035393f..dda5fa37b26 100644
--- a/spec/support/shared_examples/models/mentionable_shared_examples.rb
+++ b/spec/support/shared_examples/models/mentionable_shared_examples.rb
@@ -80,25 +80,21 @@ RSpec.shared_examples 'a mentionable' do
context 'when there are cached markdown fields' do
before do
- if subject.is_a?(CacheMarkdownField)
- subject.refresh_markdown_cache
- end
+ skip unless subject.is_a?(CacheMarkdownField)
end
it 'sends in cached markdown fields when appropriate' do
- if subject.is_a?(CacheMarkdownField) && subject.extractors[author].blank?
- expect_next_instance_of(Gitlab::ReferenceExtractor) do |ext|
- attrs = subject.class.mentionable_attrs.collect(&:first) & subject.cached_markdown_fields.markdown_fields
- attrs.each do |field|
- expect(ext).to receive(:analyze).with(subject.send(field), hash_including(rendered: anything))
- end
+ subject.extractors[author] = nil
+ expect_next_instance_of(Gitlab::ReferenceExtractor) do |ext|
+ attrs = subject.class.mentionable_attrs.collect(&:first) & subject.cached_markdown_fields.markdown_fields
+ attrs.each do |field|
+ expect(ext).to receive(:analyze).with(subject.send(field), hash_including(rendered: anything))
end
+ end
- expect(subject).not_to receive(:refresh_markdown_cache)
- expect(subject).to receive(:cached_markdown_fields).at_least(:once).and_call_original
+ expect(subject).to receive(:cached_markdown_fields).at_least(:once).and_call_original
- subject.all_references(author)
- end
+ subject.all_references(author)
end
end
@@ -126,26 +122,40 @@ RSpec.shared_examples 'an editable mentionable' do
context 'when there are cached markdown fields' do
before do
- if subject.is_a?(CacheMarkdownField)
- subject.refresh_markdown_cache
- end
- end
+ skip unless subject.is_a?(CacheMarkdownField)
- it 'refreshes markdown cache if necessary' do
subject.save!
+ end
+ it 'refreshes markdown cache if necessary' do
set_mentionable_text.call('This is a text')
- if subject.is_a?(CacheMarkdownField) && subject.extractors[author].blank?
- expect_next_instance_of(Gitlab::ReferenceExtractor) do |ext|
- subject.cached_markdown_fields.markdown_fields.each do |field|
- expect(ext).to receive(:analyze).with(subject.send(field), hash_including(rendered: anything))
- end
+ subject.extractors[author] = nil
+ expect_next_instance_of(Gitlab::ReferenceExtractor) do |ext|
+ subject.cached_markdown_fields.markdown_fields.each do |field|
+ expect(ext).to receive(:analyze).with(subject.send(field), hash_including(rendered: anything))
end
+ end
- expect(subject).to receive(:refresh_markdown_cache)
- expect(subject).to receive(:cached_markdown_fields).at_least(:once).and_call_original
+ expect(subject).to receive(:refresh_markdown_cache).and_call_original
+ expect(subject).to receive(:cached_markdown_fields).at_least(:once).and_call_original
+
+ subject.all_references(author)
+ end
+
+ context 'when the markdown cache is stale' do
+ before do
+ expect(subject).to receive(:latest_cached_markdown_version).at_least(:once) do
+ (Gitlab::MarkdownCache::CACHE_COMMONMARK_VERSION + 1) << 16
+ end
+ end
+
+ it 'persists the refreshed cache so that it does not have to be refreshed every time' do
+ expect(subject).to receive(:refresh_markdown_cache).once.and_call_original
+
+ subject.all_references(author)
+ subject.reload
subject.all_references(author)
end
end