diff options
Diffstat (limited to 'spec/lib/gitlab/discussions_diff')
-rw-r--r-- | spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb | 88 |
1 files changed, 56 insertions, 32 deletions
diff --git a/spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb b/spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb index 30981e4bd7d..0dc0f50b104 100644 --- a/spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb +++ b/spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb @@ -41,57 +41,81 @@ RSpec.describe Gitlab::DiscussionsDiff::HighlightCache, :clean_gitlab_redis_cach end describe '#read_multiple' do - it 'reads multiple keys and serializes content into Gitlab::Diff::Line objects' do - described_class.write_multiple(mapping) + shared_examples 'read multiple keys' do + it 'reads multiple keys and serializes content into Gitlab::Diff::Line objects' do + described_class.write_multiple(mapping) - found = described_class.read_multiple(mapping.keys) + found = described_class.read_multiple(mapping.keys) - expect(found.size).to eq(2) - expect(found.first.size).to eq(2) - expect(found.first).to all(be_a(Gitlab::Diff::Line)) - end + expect(found.size).to eq(2) + expect(found.first.size).to eq(2) + expect(found.first).to all(be_a(Gitlab::Diff::Line)) + end - it 'returns nil when cached key is not found' do - described_class.write_multiple(mapping) + it 'returns nil when cached key is not found' do + described_class.write_multiple(mapping) - found = described_class.read_multiple([2, 3]) + found = described_class.read_multiple([2, 3]) - expect(found.size).to eq(2) + expect(found.size).to eq(2) - expect(found.first).to eq(nil) - expect(found.second.size).to eq(2) - expect(found.second).to all(be_a(Gitlab::Diff::Line)) - end + expect(found.first).to eq(nil) + expect(found.second.size).to eq(2) + expect(found.second).to all(be_a(Gitlab::Diff::Line)) + end - it 'returns lines which rich_text are HTML-safe' do - described_class.write_multiple(mapping) + it 'returns lines which rich_text are HTML-safe' do + described_class.write_multiple(mapping) + + found = described_class.read_multiple(mapping.keys) + rich_texts = found.flatten.map(&:rich_text) + + expect(rich_texts).to all(be_html_safe) + end + end - found = described_class.read_multiple(mapping.keys) - rich_texts = found.flatten.map(&:rich_text) + context 'when feature flag is disabled' do + before do + stub_feature_flags(use_pipeline_over_multikey: false) + end - expect(rich_texts).to all(be_html_safe) + it_behaves_like 'read multiple keys' end + + it_behaves_like 'read multiple keys' end describe '#clear_multiple' do - it 'removes all named keys' do - described_class.write_multiple(mapping) + shared_examples 'delete multiple keys' do + it 'removes all named keys' do + described_class.write_multiple(mapping) - described_class.clear_multiple(mapping.keys) + described_class.clear_multiple(mapping.keys) - expect(described_class.read_multiple(mapping.keys)).to all(be_nil) - end + expect(described_class.read_multiple(mapping.keys)).to all(be_nil) + end - it 'only removed named keys' do - to_clear, to_leave = mapping.keys + it 'only removed named keys' do + to_clear, to_leave = mapping.keys - described_class.write_multiple(mapping) - described_class.clear_multiple([to_clear]) + described_class.write_multiple(mapping) + described_class.clear_multiple([to_clear]) - cleared, left = described_class.read_multiple([to_clear, to_leave]) + cleared, left = described_class.read_multiple([to_clear, to_leave]) - expect(cleared).to be_nil - expect(left).to all(be_a(Gitlab::Diff::Line)) + expect(cleared).to be_nil + expect(left).to all(be_a(Gitlab::Diff::Line)) + end end + + context 'when feature flag is disabled' do + before do + stub_feature_flags(use_pipeline_over_multikey: false) + end + + it_behaves_like 'delete multiple keys' + end + + it_behaves_like 'delete multiple keys' end end |