debian-mirror-gitlab/spec/lib/gitlab/discussions_diff/file_collection_spec.rb

87 lines
3.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::DiscussionsDiff::FileCollection do
2019-02-15 15:39:39 +05:30
let(:merge_request) { create(:merge_request) }
let!(:diff_note_a) { create(:diff_note_on_merge_request, project: merge_request.project, noteable: merge_request) }
let!(:diff_note_b) { create(:diff_note_on_merge_request, project: merge_request.project, noteable: merge_request) }
let(:note_diff_file_a) { diff_note_a.note_diff_file }
let(:note_diff_file_b) { diff_note_b.note_diff_file }
subject { described_class.new([note_diff_file_a, note_diff_file_b]) }
describe '#load_highlight', :clean_gitlab_redis_shared_state do
it 'writes uncached diffs highlight' do
file_a_caching_content = diff_note_a.diff_file.highlighted_diff_lines.map(&:to_hash)
file_b_caching_content = diff_note_b.diff_file.highlighted_diff_lines.map(&:to_hash)
expect(Gitlab::DiscussionsDiff::HighlightCache)
.to receive(:write_multiple)
.with({ note_diff_file_a.id => file_a_caching_content,
note_diff_file_b.id => file_b_caching_content })
.and_call_original
2019-12-04 20:38:33 +05:30
subject.load_highlight
2019-02-15 15:39:39 +05:30
end
it 'does not write cache for already cached file' do
2019-12-04 20:38:33 +05:30
file_a_caching_content = diff_note_a.diff_file.highlighted_diff_lines.map(&:to_hash)
Gitlab::DiscussionsDiff::HighlightCache
.write_multiple({ note_diff_file_a.id => file_a_caching_content })
2019-02-15 15:39:39 +05:30
file_b_caching_content = diff_note_b.diff_file.highlighted_diff_lines.map(&:to_hash)
expect(Gitlab::DiscussionsDiff::HighlightCache)
.to receive(:write_multiple)
.with({ note_diff_file_b.id => file_b_caching_content })
.and_call_original
2019-12-04 20:38:33 +05:30
subject.load_highlight
2019-02-15 15:39:39 +05:30
end
2019-12-21 20:55:43 +05:30
it 'does not write cache for empty mapping' do
allow(subject).to receive(:highlighted_lines_by_ids).and_return([])
expect(Gitlab::DiscussionsDiff::HighlightCache).not_to receive(:write_multiple)
subject.load_highlight
end
2019-12-04 20:38:33 +05:30
it 'does not write cache for resolved notes' do
diff_note_a.update_column(:resolved_at, Time.now)
file_b_caching_content = diff_note_b.diff_file.highlighted_diff_lines.map(&:to_hash)
expect(Gitlab::DiscussionsDiff::HighlightCache)
.to receive(:write_multiple)
.with({ note_diff_file_b.id => file_b_caching_content })
.and_call_original
subject.load_highlight
2019-02-15 15:39:39 +05:30
end
it 'loaded diff files have highlighted lines loaded' do
2019-12-04 20:38:33 +05:30
subject.load_highlight
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
diff_file_a = subject.find_by_id(note_diff_file_a.id)
diff_file_b = subject.find_by_id(note_diff_file_b.id)
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
expect(diff_file_a).to be_highlight_loaded
expect(diff_file_b).to be_highlight_loaded
2019-02-15 15:39:39 +05:30
end
it 'not loaded diff files does not have highlighted lines loaded' do
2019-12-04 20:38:33 +05:30
diff_note_a.update_column(:resolved_at, Time.now)
subject.load_highlight
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
diff_file_a = subject.find_by_id(note_diff_file_a.id)
diff_file_b = subject.find_by_id(note_diff_file_b.id)
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
expect(diff_file_a).not_to be_highlight_loaded
expect(diff_file_b).to be_highlight_loaded
2019-02-15 15:39:39 +05:30
end
end
end