2019-10-10 12:06:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DiffsMetadataEntity do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:request) { EntityRequest.new(project: project, current_user: user) }
|
|
|
|
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
|
|
|
|
let(:merge_request_diffs) { merge_request.merge_request_diffs }
|
|
|
|
let(:merge_request_diff) { merge_request_diffs.last }
|
|
|
|
|
|
|
|
let(:entity) do
|
|
|
|
described_class.new(merge_request_diff.diffs,
|
|
|
|
request: request,
|
|
|
|
merge_request: merge_request,
|
|
|
|
merge_request_diffs: merge_request_diffs)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as json' do
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
it 'contain only required attributes' do
|
|
|
|
expect(subject.keys).to contain_exactly(
|
|
|
|
# Inherited attributes
|
|
|
|
:real_size, :size, :branch_name,
|
|
|
|
:target_branch_name, :commit, :merge_request_diff,
|
|
|
|
:start_version, :latest_diff, :latest_version_path,
|
|
|
|
:added_lines, :removed_lines, :render_overflow_warning,
|
|
|
|
:email_patch_path, :plain_diff_path,
|
2020-04-02 09:08:14 +00:00
|
|
|
:merge_request_diffs, :context_commits,
|
|
|
|
:definition_path_prefix,
|
2019-10-10 12:06:19 +00:00
|
|
|
# Attributes
|
|
|
|
:diff_files
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'diff_files' do
|
|
|
|
it 'returns diff files metadata' do
|
2019-12-16 21:08:00 +00:00
|
|
|
raw_diff_files = merge_request_diff.diffs.raw_diff_files
|
|
|
|
|
|
|
|
expect_next_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff) do |instance|
|
|
|
|
# Use lightweight version instead. Several methods delegate to it, so putting a 5
|
|
|
|
# calls limit.
|
|
|
|
expect(instance).to receive(:raw_diff_files).at_most(5).times.and_call_original
|
|
|
|
expect(instance).not_to receive(:diff_files)
|
|
|
|
end
|
|
|
|
|
|
|
|
payload = DiffFileMetadataEntity.represent(raw_diff_files).as_json
|
2019-10-10 12:06:19 +00:00
|
|
|
|
|
|
|
expect(subject[:diff_files]).to eq(payload)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|