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/diff | |
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/diff')
27 files changed, 361 insertions, 26 deletions
diff --git a/spec/lib/gitlab/diff/diff_refs_spec.rb b/spec/lib/gitlab/diff/diff_refs_spec.rb index 33a7cf5ae12..c1ee34ba874 100644 --- a/spec/lib/gitlab/diff/diff_refs_spec.rb +++ b/spec/lib/gitlab/diff/diff_refs_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::DiffRefs do +RSpec.describe Gitlab::Diff::DiffRefs do let(:project) { create(:project, :repository) } describe '#==' do diff --git a/spec/lib/gitlab/diff/file_collection/commit_spec.rb b/spec/lib/gitlab/diff/file_collection/commit_spec.rb index 34ed22b8941..6c109e96a53 100644 --- a/spec/lib/gitlab/diff/file_collection/commit_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/commit_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::FileCollection::Commit do +RSpec.describe Gitlab::Diff::FileCollection::Commit do let(:project) { create(:project, :repository) } it_behaves_like 'diff statistics' do diff --git a/spec/lib/gitlab/diff/file_collection/compare_spec.rb b/spec/lib/gitlab/diff/file_collection/compare_spec.rb index f330f299ac1..168d58e584e 100644 --- a/spec/lib/gitlab/diff/file_collection/compare_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/compare_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::FileCollection::Compare do +RSpec.describe Gitlab::Diff::FileCollection::Compare do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/lib/gitlab/diff/file_collection/merge_request_diff_batch_spec.rb b/spec/lib/gitlab/diff/file_collection/merge_request_diff_batch_spec.rb index 7e945d1d140..bd60c24859c 100644 --- a/spec/lib/gitlab/diff/file_collection/merge_request_diff_batch_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/merge_request_diff_batch_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do +RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do let(:merge_request) { create(:merge_request) } let(:batch_page) { 1 } let(:batch_size) { 10 } diff --git a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb index c2b6ca4164c..a5e714c90fc 100644 --- a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::FileCollection::MergeRequestDiff do +RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiff do let(:merge_request) { create(:merge_request) } let(:diffable) { merge_request.merge_request_diff } let(:subject) { described_class.new(diffable, diff_options: nil) } diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index 8dbedcf26b9..94abfcf079a 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::File do +RSpec.describe Gitlab::Diff::File do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/lib/gitlab/diff/formatters/image_formatter_spec.rb b/spec/lib/gitlab/diff/formatters/image_formatter_spec.rb index 3f88f39ba92..579776d44aa 100644 --- a/spec/lib/gitlab/diff/formatters/image_formatter_spec.rb +++ b/spec/lib/gitlab/diff/formatters/image_formatter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::Formatters::ImageFormatter do +RSpec.describe Gitlab::Diff::Formatters::ImageFormatter do let(:base_attrs) do { base_sha: 123, diff --git a/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb b/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb index 50dd597c5a7..41877a16ebf 100644 --- a/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb +++ b/spec/lib/gitlab/diff/formatters/text_formatter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::Formatters::TextFormatter do +RSpec.describe Gitlab::Diff::Formatters::TextFormatter do let!(:base) do { base_sha: 123, diff --git a/spec/lib/gitlab/diff/highlight_cache_spec.rb b/spec/lib/gitlab/diff/highlight_cache_spec.rb index 3c128aad976..80cc10051c4 100644 --- a/spec/lib/gitlab/diff/highlight_cache_spec.rb +++ b/spec/lib/gitlab/diff/highlight_cache_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do +RSpec.describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do let(:merge_request) { create(:merge_request_with_diffs) } let(:diff_hash) do { ".gitignore-false-false-false" => diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb index ff4ec75358e..283437e7fbd 100644 --- a/spec/lib/gitlab/diff/highlight_spec.rb +++ b/spec/lib/gitlab/diff/highlight_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::Highlight do +RSpec.describe Gitlab::Diff::Highlight do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/lib/gitlab/diff/inline_diff_markdown_marker_spec.rb b/spec/lib/gitlab/diff/inline_diff_markdown_marker_spec.rb index a668bb464a4..60f7f3a103f 100644 --- a/spec/lib/gitlab/diff/inline_diff_markdown_marker_spec.rb +++ b/spec/lib/gitlab/diff/inline_diff_markdown_marker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::InlineDiffMarkdownMarker do +RSpec.describe Gitlab::Diff::InlineDiffMarkdownMarker do describe '#mark' do let(:raw) { "abc 'def'" } let(:inline_diffs) { [2..5] } diff --git a/spec/lib/gitlab/diff/inline_diff_marker_spec.rb b/spec/lib/gitlab/diff/inline_diff_marker_spec.rb index 26b99870b31..6820a7df95e 100644 --- a/spec/lib/gitlab/diff/inline_diff_marker_spec.rb +++ b/spec/lib/gitlab/diff/inline_diff_marker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::InlineDiffMarker do +RSpec.describe Gitlab::Diff::InlineDiffMarker do describe '#mark' do let(:inline_diffs) { [2..5] } let(:raw) { "abc 'def'" } diff --git a/spec/lib/gitlab/diff/inline_diff_spec.rb b/spec/lib/gitlab/diff/inline_diff_spec.rb index fdbee3b4230..35284e952f7 100644 --- a/spec/lib/gitlab/diff/inline_diff_spec.rb +++ b/spec/lib/gitlab/diff/inline_diff_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::InlineDiff do +RSpec.describe Gitlab::Diff::InlineDiff do describe '.for_lines' do let(:diff) do <<-EOF.strip_heredoc diff --git a/spec/lib/gitlab/diff/line_mapper_spec.rb b/spec/lib/gitlab/diff/line_mapper_spec.rb index 6a86f885c3b..1c1f8201a81 100644 --- a/spec/lib/gitlab/diff/line_mapper_spec.rb +++ b/spec/lib/gitlab/diff/line_mapper_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::LineMapper do +RSpec.describe Gitlab::Diff::LineMapper do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/lib/gitlab/diff/line_spec.rb b/spec/lib/gitlab/diff/line_spec.rb index 7961bec9d57..e10a50afde9 100644 --- a/spec/lib/gitlab/diff/line_spec.rb +++ b/spec/lib/gitlab/diff/line_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::Line do +RSpec.describe Gitlab::Diff::Line do shared_examples 'line object initialized by hash' do it 'round-trips correctly with to_hash' do expect(described_class.safe_init_from_hash(line.to_hash).to_hash) diff --git a/spec/lib/gitlab/diff/lines_unfolder_spec.rb b/spec/lib/gitlab/diff/lines_unfolder_spec.rb index ebcbe1fb1a0..b891f9e8285 100644 --- a/spec/lib/gitlab/diff/lines_unfolder_spec.rb +++ b/spec/lib/gitlab/diff/lines_unfolder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::LinesUnfolder do +RSpec.describe Gitlab::Diff::LinesUnfolder do let(:raw_diff) do <<-DIFF.strip_heredoc @@ -7,9 +7,6 @@ diff --git a/spec/lib/gitlab/diff/parallel_diff_spec.rb b/spec/lib/gitlab/diff/parallel_diff_spec.rb index d275bf2c223..f574d7ec707 100644 --- a/spec/lib/gitlab/diff/parallel_diff_spec.rb +++ b/spec/lib/gitlab/diff/parallel_diff_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::ParallelDiff do +RSpec.describe Gitlab::Diff::ParallelDiff do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb index 00a446c4e20..7448ae0b2ea 100644 --- a/spec/lib/gitlab/diff/parser_spec.rb +++ b/spec/lib/gitlab/diff/parser_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::Parser do +RSpec.describe Gitlab::Diff::Parser do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/lib/gitlab/diff/position_collection_spec.rb b/spec/lib/gitlab/diff/position_collection_spec.rb index dd8434ab10b..b1478c774f1 100644 --- a/spec/lib/gitlab/diff/position_collection_spec.rb +++ b/spec/lib/gitlab/diff/position_collection_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::PositionCollection do +RSpec.describe Gitlab::Diff::PositionCollection do let(:merge_request) { build(:merge_request) } let(:text_position) do diff --git a/spec/lib/gitlab/diff/position_spec.rb b/spec/lib/gitlab/diff/position_spec.rb index b32a2c59bb9..a7f6ea0cbfb 100644 --- a/spec/lib/gitlab/diff/position_spec.rb +++ b/spec/lib/gitlab/diff/position_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::Position do +RSpec.describe Gitlab::Diff::Position do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/lib/gitlab/diff/position_tracer/image_strategy_spec.rb b/spec/lib/gitlab/diff/position_tracer/image_strategy_spec.rb index 900816af53a..7dceb64b776 100644 --- a/spec/lib/gitlab/diff/position_tracer/image_strategy_spec.rb +++ b/spec/lib/gitlab/diff/position_tracer/image_strategy_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::PositionTracer::ImageStrategy do +RSpec.describe Gitlab::Diff::PositionTracer::ImageStrategy do include PositionTracerHelpers let(:project) { create(:project, :repository) } @@ -234,5 +234,118 @@ describe Gitlab::Diff::PositionTracer::ImageStrategy do end end end + + describe 'symlink scenarios' do + let(:new_file) { old_file_status == :new } + let(:deleted_file) { old_file_status == :deleted } + let(:renamed_file) { old_file_status == :renamed } + + let(:file_identifier) { "#{file_name}-#{new_file}-#{deleted_file}-#{renamed_file}" } + let(:file_identifier_hash) { Digest::SHA1.hexdigest(file_identifier) } + let(:old_position) { position(old_path: file_name, new_path: file_name, position_type: 'image', file_identifier_hash: file_identifier_hash) } + + let(:update_file_commit) do + initial_commit + + update_file( + branch_name, + file_name, + Base64.encode64('morecontent') + ) + end + + let(:delete_file_commit) do + initial_commit + + delete_file(branch_name, file_name) + end + + let(:create_second_file_commit) do + initial_commit + + create_file( + branch_name, + second_file_name, + Base64.encode64('morecontent') + ) + end + + before do + stub_feature_flags(file_identifier_hash: true) + end + + describe 'from symlink to image' do + let(:initial_commit) { project.commit('a19c7f9a147e35e535c797cf148d29c24dac5544') } + let(:symlink_to_image_commit) { project.commit('8cfca8420812e5bd7479aa32cf33e0c95a3ca576') } + let(:branch_name) { 'diff-files-symlink-to-image' } + let(:file_name) { 'symlink-to-image.png' } + + context "when the old position is on the new image file" do + let(:old_file_status) { :new } + + context "when the image file's content was unchanged between the old and the new diff" do + let(:old_diff_refs) { diff_refs(initial_commit, symlink_to_image_commit) } + let(:new_diff_refs) { diff_refs(initial_commit, create_second_file_commit) } + + it "returns the new position" do + expect_new_position( + old_path: file_name, + new_path: file_name + ) + end + end + + context "when the image file's content was changed between the old and the new diff" do + let(:old_diff_refs) { diff_refs(initial_commit, symlink_to_image_commit) } + let(:new_diff_refs) { diff_refs(initial_commit, update_file_commit) } + let(:change_diff_refs) { diff_refs(symlink_to_image_commit, update_file_commit) } + + it "returns the position of the change" do + expect_change_position( + old_path: file_name, + new_path: file_name + ) + end + end + + context "when the image file was removed between the old and the new diff" do + let(:old_diff_refs) { diff_refs(initial_commit, symlink_to_image_commit) } + let(:new_diff_refs) { diff_refs(initial_commit, delete_file_commit) } + let(:change_diff_refs) { diff_refs(symlink_to_image_commit, delete_file_commit) } + + it "returns the position of the change" do + expect_change_position( + old_path: file_name, + new_path: file_name + ) + end + end + end + end + + describe 'from image to symlink' do + let(:initial_commit) { project.commit('d10dcdfbbb2b59a959a5f5d66a4adf28f0ea4008') } + let(:image_to_symlink_commit) { project.commit('3e94fdaa60da8aed38401b91bc56be70d54ca424') } + let(:branch_name) { 'diff-files-image-to-symlink' } + let(:file_name) { 'image-to-symlink.png' } + + context "when the old position is on the added image file" do + let(:old_file_status) { :new } + + context "when the image file gets changed to a symlink between the old and the new diff" do + let(:old_diff_refs) { diff_refs(initial_commit.parent, initial_commit) } + let(:new_diff_refs) { diff_refs(initial_commit.parent, image_to_symlink_commit) } + let(:change_diff_refs) { diff_refs(initial_commit, image_to_symlink_commit) } + + it "returns the position of the change" do + expect_change_position( + old_path: file_name, + new_path: file_name + ) + end + end + end + end + end end end diff --git a/spec/lib/gitlab/diff/position_tracer/line_strategy_spec.rb b/spec/lib/gitlab/diff/position_tracer/line_strategy_spec.rb index 7f4902c5b86..d9f384fb47f 100644 --- a/spec/lib/gitlab/diff/position_tracer/line_strategy_spec.rb +++ b/spec/lib/gitlab/diff/position_tracer/line_strategy_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::PositionTracer::LineStrategy do +RSpec.describe Gitlab::Diff::PositionTracer::LineStrategy do # Douwe's diary New York City, 2016-06-28 # -------------------------------------------------------------------------- # @@ -1801,5 +1801,143 @@ describe Gitlab::Diff::PositionTracer::LineStrategy do end end end + + describe 'symlink scenarios' do + let(:new_file) { old_file_status == :new } + let(:deleted_file) { old_file_status == :deleted } + let(:renamed_file) { old_file_status == :renamed } + + let(:file_identifier) { "#{file_name}-#{new_file}-#{deleted_file}-#{renamed_file}" } + let(:file_identifier_hash) { Digest::SHA1.hexdigest(file_identifier) } + + let(:update_line_commit) do + update_file( + branch_name, + file_name, + <<-CONTENT.strip_heredoc + A + BB + C + CONTENT + ) + end + + let(:delete_file_commit) do + delete_file(branch_name, file_name) + end + + let(:create_second_file_commit) do + create_file( + branch_name, + second_file_name, + <<-CONTENT.strip_heredoc + D + E + CONTENT + ) + end + + before do + stub_feature_flags(file_identifier_hash: true) + end + + describe 'from symlink to text' do + let(:initial_commit) { project.commit('0e5b363105e9176a77bac94d7ff6d8c4fb35c3eb') } + let(:symlink_to_text_commit) { project.commit('689815e617abc6889f1fded4834d2dd7d942a58e') } + let(:branch_name) { 'diff-files-symlink-to-text' } + let(:file_name) { 'symlink-to-text.txt' } + let(:old_position) { position(old_path: file_name, new_path: file_name, new_line: 3, file_identifier_hash: file_identifier_hash) } + + before do + create_branch('diff-files-symlink-to-text-test', branch_name) + end + + context "when the old position is on the new text file" do + let(:old_file_status) { :new } + + context "when the text file's content was unchanged between the old and the new diff" do + let(:old_diff_refs) { diff_refs(initial_commit, symlink_to_text_commit) } + let(:new_diff_refs) { diff_refs(initial_commit, create_second_file_commit) } + + it "returns the new position" do + expect_new_position( + new_path: old_position.new_path, + new_line: old_position.new_line + ) + end + end + + context "when the text file's content has change, but the line was unchanged between the old and the new diff" do + let(:old_diff_refs) { diff_refs(initial_commit, symlink_to_text_commit) } + let(:new_diff_refs) { diff_refs(initial_commit, update_line_commit) } + + it "returns the new position" do + expect_new_position( + new_path: old_position.new_path, + new_line: old_position.new_line + ) + end + end + + context "when the text file's line was changed between the old and the new diff" do + let(:old_position) { position(old_path: file_name, new_path: file_name, new_line: 2, file_identifier_hash: file_identifier_hash) } + + let(:old_diff_refs) { diff_refs(initial_commit, symlink_to_text_commit) } + let(:new_diff_refs) { diff_refs(initial_commit, update_line_commit) } + let(:change_diff_refs) { diff_refs(symlink_to_text_commit, update_line_commit) } + + it "returns the position of the change" do + expect_change_position( + old_path: file_name, + new_path: file_name, + old_line: 2, + new_line: nil + ) + end + end + + context "when the text file was removed between the old and the new diff" do + let(:old_diff_refs) { diff_refs(initial_commit, symlink_to_text_commit) } + let(:new_diff_refs) { diff_refs(initial_commit, delete_file_commit) } + let(:change_diff_refs) { diff_refs(symlink_to_text_commit, delete_file_commit) } + + it "returns the position of the change" do + expect_change_position( + old_path: file_name, + new_path: file_name, + old_line: 3, + new_line: nil + ) + end + end + end + + describe 'from text to symlink' do + let(:initial_commit) { project.commit('3db7bd90bab8ce8f02c9818590b84739a2e97230') } + let(:text_to_symlink_commit) { project.commit('5e2c2708c2e403dece5dd25759369150aac51644') } + let(:branch_name) { 'diff-files-text-to-symlink' } + let(:file_name) { 'text-to-symlink.txt' } + + context "when the position is on the added text file" do + let(:old_file_status) { :new } + + context "when the text file gets changed to a symlink between the old and the new diff" do + let(:old_diff_refs) { diff_refs(initial_commit.parent, initial_commit) } + let(:new_diff_refs) { diff_refs(initial_commit.parent, text_to_symlink_commit) } + let(:change_diff_refs) { diff_refs(initial_commit, text_to_symlink_commit) } + + it "returns the position of the change" do + expect_change_position( + old_path: file_name, + new_path: file_name, + old_line: 3, + new_line: nil + ) + end + end + end + end + end + end end end diff --git a/spec/lib/gitlab/diff/position_tracer_spec.rb b/spec/lib/gitlab/diff/position_tracer_spec.rb index 47d78e0b18c..fc649812b0a 100644 --- a/spec/lib/gitlab/diff/position_tracer_spec.rb +++ b/spec/lib/gitlab/diff/position_tracer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::PositionTracer do +RSpec.describe Gitlab::Diff::PositionTracer do include PositionTracerHelpers subject do diff --git a/spec/lib/gitlab/diff/stats_cache_spec.rb b/spec/lib/gitlab/diff/stats_cache_spec.rb new file mode 100644 index 00000000000..8bf510c0bdd --- /dev/null +++ b/spec/lib/gitlab/diff/stats_cache_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Diff::StatsCache, :use_clean_rails_memory_store_caching do + subject(:stats_cache) { described_class.new(cachable_key: cachable_key) } + + let(:key) { ['diff_stats', cachable_key, described_class::VERSION].join(":") } + let(:cachable_key) { 'cachecachecache' } + let(:stat) { Gitaly::DiffStats.new(path: 'temp', additions: 10, deletions: 15) } + let(:stats) { Gitlab::Git::DiffStatsCollection.new([stat]) } + let(:cache) { Rails.cache } + + describe '#read' do + before do + stats_cache.write_if_empty(stats) + end + + it 'returns the expected stats' do + expect(stats_cache.read.to_json).to eq(stats.to_json) + end + end + + describe '#write_if_empty' do + context 'when the cache already exists' do + before do + Rails.cache.write(key, true) + end + + it 'does not write the stats' do + expect(cache).not_to receive(:write) + + stats_cache.write_if_empty(stats) + end + end + + context 'when the cache does not exist' do + it 'writes the stats' do + expect(cache) + .to receive(:write) + .with(key, stats.as_json, expires_in: described_class::EXPIRATION) + .and_call_original + + stats_cache.write_if_empty(stats) + + expect(stats_cache.read.to_a).to eq(stats.to_a) + end + + context 'when given non utf-8 characters' do + let(:non_utf8_path) { '你好'.b } + let(:stat) { Gitaly::DiffStats.new(path: non_utf8_path, additions: 10, deletions: 15) } + + it 'writes the stats' do + expect(cache) + .to receive(:write) + .with(key, stats.as_json, expires_in: described_class::EXPIRATION) + .and_call_original + + stats_cache.write_if_empty(stats) + + expect(stats_cache.read.to_a).to eq(stats.to_a) + end + end + + context 'when given empty stats' do + let(:stats) { nil } + + it 'does not write the stats' do + expect(cache).not_to receive(:write) + + stats_cache.write_if_empty(stats) + end + end + end + end + + describe '#clear' do + it 'clears cache' do + expect(cache).to receive(:delete).with(key) + + stats_cache.clear + end + end +end diff --git a/spec/lib/gitlab/diff/suggestion_diff_spec.rb b/spec/lib/gitlab/diff/suggestion_diff_spec.rb index 0d4fe33bc47..9546c581112 100644 --- a/spec/lib/gitlab/diff/suggestion_diff_spec.rb +++ b/spec/lib/gitlab/diff/suggestion_diff_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::SuggestionDiff do +RSpec.describe Gitlab::Diff::SuggestionDiff do describe '#diff_lines' do let(:from_content) do <<-BLOB.strip_heredoc diff --git a/spec/lib/gitlab/diff/suggestion_spec.rb b/spec/lib/gitlab/diff/suggestion_spec.rb index d7ca0e0a522..5a5c5555818 100644 --- a/spec/lib/gitlab/diff/suggestion_spec.rb +++ b/spec/lib/gitlab/diff/suggestion_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::Suggestion do +RSpec.describe Gitlab::Diff::Suggestion do shared_examples 'correct suggestion raw content' do it 'returns correct raw data' do expect(suggestion.to_hash).to include(from_content: expected_lines.join, diff --git a/spec/lib/gitlab/diff/suggestions_parser_spec.rb b/spec/lib/gitlab/diff/suggestions_parser_spec.rb index 1f2af42f6e7..5efce414dc8 100644 --- a/spec/lib/gitlab/diff/suggestions_parser_spec.rb +++ b/spec/lib/gitlab/diff/suggestions_parser_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Diff::SuggestionsParser do +RSpec.describe Gitlab::Diff::SuggestionsParser do describe '.parse' do let(:merge_request) { create(:merge_request) } let(:project) { merge_request.project } |