debian-mirror-gitlab/spec/serializers/diff_file_entity_spec.rb

73 lines
2.6 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe DiffFileEntity do
2018-03-27 19:54:05 +05:30
include RepoHelpers
2020-04-22 19:07:51 +05:30
let_it_be(:project) { create(:project, :repository) }
2018-03-27 19:54:05 +05:30
let(:repository) { project.repository }
let(:commit) { project.commit(sample_commit.id) }
let(:diff_refs) { commit.diff_refs }
let(:diff) { commit.raw_diffs.first }
let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: diff_refs, repository: repository) }
2019-12-26 22:10:19 +05:30
let(:options) { {} }
let(:entity) { described_class.new(diff_file, options.reverse_merge(request: {})) }
2018-03-27 19:54:05 +05:30
subject { entity.as_json }
2018-11-08 19:23:39 +05:30
context 'when there is no merge request' do
it_behaves_like 'diff file entity'
end
context 'when there is a merge request' do
2020-04-22 19:07:51 +05:30
let_it_be(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
2018-11-08 19:23:39 +05:30
let(:user) { create(:user) }
2020-04-22 19:07:51 +05:30
let(:code_navigation_path) { Gitlab::CodeNavigationPath.new(project, project.commit.sha) }
2018-11-08 19:23:39 +05:30
let(:request) { EntityRequest.new(project: project, current_user: user) }
2020-04-22 19:07:51 +05:30
let(:entity) { described_class.new(diff_file, options.merge(request: request, merge_request: merge_request, code_navigation_path: code_navigation_path)) }
2019-07-07 11:18:12 +05:30
let(:exposed_urls) { %i(edit_path view_path context_lines_path) }
2018-11-08 19:23:39 +05:30
it_behaves_like 'diff file entity'
it 'exposes additional attributes' do
expect(subject).to include(*exposed_urls)
expect(subject).to include(:replaced_view_path)
2020-04-22 19:07:51 +05:30
expect(subject).to include(:code_navigation_path)
2018-11-08 19:23:39 +05:30
end
it 'points all urls to merge request target project' do
response = subject
exposed_urls.each do |attribute|
expect(response[attribute]).to include(merge_request.target_project.to_param)
end
end
2019-07-07 11:18:12 +05:30
it 'exposes load_collapsed_diff_url if the file viewer is collapsed' do
allow(diff_file.viewer).to receive(:collapsed?) { true }
expect(subject).to include(:load_collapsed_diff_url)
end
2018-03-27 19:54:05 +05:30
end
2018-11-20 20:47:30 +05:30
2020-03-13 15:44:24 +05:30
describe '#parallel_diff_lines' do
2019-12-26 22:10:19 +05:30
let(:options) { { diff_view: :parallel } }
2018-11-20 20:47:30 +05:30
it 'exposes parallel diff lines correctly' do
response = subject
lines = response[:parallel_diff_lines]
# make sure at least one line is present for each side
expect(lines.map { |line| line[:right] }.compact).to be_present
expect(lines.map { |line| line[:left] }.compact).to be_present
# make sure all lines are in correct format
lines.each do |parallel_line|
expect(parallel_line[:left].as_json).to match_schema('entities/diff_line') if parallel_line[:left]
expect(parallel_line[:right].as_json).to match_schema('entities/diff_line') if parallel_line[:right]
end
end
end
2018-03-27 19:54:05 +05:30
end