diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/markdown_cache | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/markdown_cache')
4 files changed, 49 insertions, 6 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 5b6c769d6eb..be562d916d3 100644 --- a/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb +++ b/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Gitlab::MarkdownCache::ActiveRecord::Extension do +RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do let(:klass) do Class.new(ActiveRecord::Base) do self.table_name = 'issues' diff --git a/spec/lib/gitlab/markdown_cache/field_data_spec.rb b/spec/lib/gitlab/markdown_cache/field_data_spec.rb index 393bf85aa43..76d8cbe6b7d 100644 --- a/spec/lib/gitlab/markdown_cache/field_data_spec.rb +++ b/spec/lib/gitlab/markdown_cache/field_data_spec.rb @@ -2,7 +2,7 @@ require 'fast_spec_helper' -describe Gitlab::MarkdownCache::FieldData do +RSpec.describe Gitlab::MarkdownCache::FieldData do subject(:field_data) { described_class.new } before do diff --git a/spec/lib/gitlab/markdown_cache/redis/extension_spec.rb b/spec/lib/gitlab/markdown_cache/redis/extension_spec.rb index b6a781de426..3dcb9f160ba 100644 --- a/spec/lib/gitlab/markdown_cache/redis/extension_spec.rb +++ b/spec/lib/gitlab/markdown_cache/redis/extension_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Gitlab::MarkdownCache::Redis::Extension, :clean_gitlab_redis_cache do +RSpec.describe Gitlab::MarkdownCache::Redis::Extension, :clean_gitlab_redis_cache do let(:klass) do Class.new do include CacheMarkdownField @@ -49,6 +49,31 @@ describe Gitlab::MarkdownCache::Redis::Extension, :clean_gitlab_redis_cache do expect(thing.cached_markdown_version).to eq(cache_version) end + describe '.preload_markdown_cache!' do + before do + Gitlab::Redis::Cache.with do |r| + r.mapped_hmset(expected_cache_key, + title_html: 'hello', + description_html: 'world', + cached_markdown_version: cache_version) + end + end + + it 'does not preload the markdown twice' do + expect(Gitlab::MarkdownCache::Redis::Store).to receive(:bulk_read).and_call_original + expect(Gitlab::Redis::Cache).to receive(:with).twice.and_call_original + + klass.preload_markdown_cache!([thing]) + + aggregate_failures do + expect(Gitlab::Redis::Cache).not_to receive(:with) + expect(thing.title_html).to eq('hello') + expect(thing.description_html).to eq('world') + expect(thing.cached_markdown_version).to eq(cache_version) + end + end + end + describe "#refresh_markdown_cache!" do it "stores the value in redis" do expected_results = { "title_html" => "`Hello`", diff --git a/spec/lib/gitlab/markdown_cache/redis/store_spec.rb b/spec/lib/gitlab/markdown_cache/redis/store_spec.rb index 95c68e7d491..40ff9a765a6 100644 --- a/spec/lib/gitlab/markdown_cache/redis/store_spec.rb +++ b/spec/lib/gitlab/markdown_cache/redis/store_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do +RSpec.describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do let(:storable_class) do Class.new do cattr_reader :cached_markdown_fields do @@ -37,6 +37,23 @@ describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do end end + describe '.bulk_read' do + before do + store.save(field_1_html: "hello", field_2_html: "world", cached_markdown_version: 1) + end + + it 'returns a hash of values from store' do + Gitlab::Redis::Cache.with do |redis| + expect(redis).to receive(:pipelined).and_call_original + end + + results = described_class.bulk_read([storable]) + + expect(results[storable.cache_key].value.symbolize_keys) + .to eq(field_1_html: "hello", field_2_html: "world", cached_markdown_version: "1") + end + end + describe '#save' do it 'stores updates to html fields and version' do values_to_store = { field_1_html: "hello", field_2_html: "world", cached_markdown_version: 1 } @@ -44,7 +61,7 @@ describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do store.save(values_to_store) expect(read_values) - .to eq({ field_1_html: "hello", field_2_html: "world", cached_markdown_version: "1" }) + .to eq(field_1_html: "hello", field_2_html: "world", cached_markdown_version: "1") end end @@ -54,7 +71,8 @@ describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do store_values(stored_values) - expect(store.read.symbolize_keys).to eq(stored_values) + expect(store.read.symbolize_keys) + .to eq(field_1_html: "hello", field_2_html: "world", cached_markdown_version: "1") end it 'is mared loaded after reading' do |