diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/markdown_cache | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/markdown_cache')
-rw-r--r-- | spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb b/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb index 23dbd4a5bb3..98385cd80cc 100644 --- a/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb +++ b/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb @@ -178,4 +178,66 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do thing.refresh_markdown_cache! end end + + context 'with note' do + let(:klass) do + Class.new(ActiveRecord::Base) do + self.table_name = 'notes' + include CacheMarkdownField + include Importable + include Mentionable + + attr_mentionable :note, pipeline: :note + cache_markdown_field :note, pipeline: :note + end + end + + let(:thing) { klass.new(note: markdown) } + + before do + thing.note = "hello world" + end + + it 'calls store_mentions!' do + expect(thing).to receive(:store_mentions!).and_call_original + + thing.save! + end + + context 'during import' do + before do + thing.importing = true + end + + it 'does not call store_mentions!' do + expect(thing).not_to receive(:store_mentions!) + + thing.save! + end + end + end + + context 'when persisted cache is newer than current version' do + before do + thing.update_column(:cached_markdown_version, thing.cached_markdown_version + 1) + end + + it 'does not save the generated HTML' do + expect(thing).not_to receive(:update_columns) + + thing.refresh_markdown_cache! + end + end + + context 'when persisted cache is nil' do + before do + thing.update_column(:cached_markdown_version, nil) + end + + it 'does not save the generated HTML' do + expect(thing).to receive(:update_columns) + + thing.refresh_markdown_cache! + end + end end |