2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MergeRequestDiffEntity do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:request) { EntityRequest.new(project: project) }
|
|
|
|
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
|
|
|
|
let(:merge_request_diffs) { merge_request.merge_request_diffs }
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:merge_request_diff) { merge_request_diffs.first }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
let(:entity) do
|
2019-12-26 22:10:19 +05:30
|
|
|
described_class.new(merge_request_diff, request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
subject { entity.as_json }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'as json' do
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'exposes needed attributes' do
|
|
|
|
expect(subject).to include(
|
|
|
|
:version_index, :created_at, :commits_count,
|
|
|
|
:latest, :short_commit_sha, :version_path,
|
|
|
|
:compare_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe '#short_commit_sha' do
|
|
|
|
it 'returns short sha' do
|
|
|
|
expect(subject[:short_commit_sha]).to eq('b83d6e39')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil if head_commit_sha does not exist' do
|
|
|
|
allow(merge_request_diff).to receive(:head_commit_sha).and_return(nil)
|
|
|
|
|
|
|
|
expect(subject[:short_commit_sha]).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|