2017-05-23 11:10:07 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BuildDetailsEntity do
|
2017-05-29 03:58:20 -04:00
|
|
|
set(:user) { create(:admin) }
|
|
|
|
|
2017-06-07 05:36:41 -04:00
|
|
|
it 'inherits from JobEntity' do
|
|
|
|
expect(described_class).to be < JobEntity
|
2017-05-23 11:10:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#as_json' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
2017-07-19 07:11:39 -04:00
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
let(:build) { create(:ci_build, :failed, pipeline: pipeline) }
|
2017-05-23 11:10:07 -04:00
|
|
|
let(:request) { double('request') }
|
2017-07-19 07:11:39 -04:00
|
|
|
|
|
|
|
let(:entity) do
|
|
|
|
described_class.new(build, request: request,
|
|
|
|
current_user: user,
|
|
|
|
project: project)
|
|
|
|
end
|
|
|
|
|
2017-05-23 11:10:07 -04:00
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
2017-07-19 07:11:39 -04:00
|
|
|
it 'contains the needed key value pairs' do
|
|
|
|
expect(subject).to include(:coverage, :erased_at, :duration)
|
|
|
|
expect(subject).to include(:runner, :pipeline)
|
|
|
|
expect(subject).to include(:raw_path, :new_issue_path)
|
|
|
|
end
|
|
|
|
|
2017-05-23 11:10:07 -04:00
|
|
|
context 'when the user has access to issues and merge requests' do
|
2017-07-19 07:11:39 -04:00
|
|
|
context 'when merge request orginates from the same project' do
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project, source_branch: build.ref)
|
|
|
|
end
|
2017-05-26 04:31:42 -04:00
|
|
|
|
2017-07-19 07:11:39 -04:00
|
|
|
before do
|
|
|
|
allow(build).to receive(:merge_request).and_return(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the needed key value pairs' do
|
|
|
|
expect(subject).to include(:merge_request)
|
|
|
|
expect(subject).to include(:new_issue_path)
|
|
|
|
end
|
|
|
|
|
2017-07-20 03:18:45 -04:00
|
|
|
it 'exposes correct details of the merge request' do
|
|
|
|
expect(subject[:merge_request][:iid]).to eq merge_request.iid
|
2017-07-19 07:11:39 -04:00
|
|
|
end
|
2017-05-23 11:10:07 -04:00
|
|
|
|
2017-07-19 07:11:39 -04:00
|
|
|
it 'has a correct merge request path' do
|
|
|
|
expect(subject[:merge_request][:path]).to include project.full_path
|
|
|
|
end
|
2017-05-29 03:58:20 -04:00
|
|
|
end
|
|
|
|
|
2017-07-19 07:11:39 -04:00
|
|
|
context 'when merge request is from a fork' do
|
|
|
|
let(:fork_project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, forked_from_project: project)
|
2017-07-19 07:11:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: fork_project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(build).to receive(:merge_request).and_return(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, source_project: fork_project,
|
|
|
|
target_project: project,
|
|
|
|
source_branch: build.ref)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the needed key value pairs' do
|
|
|
|
expect(subject).to include(:merge_request)
|
|
|
|
expect(subject).to include(:new_issue_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes details of the merge request' do
|
2017-07-20 03:18:45 -04:00
|
|
|
expect(subject[:merge_request][:iid]).to eq merge_request.iid
|
2017-07-19 07:11:39 -04:00
|
|
|
end
|
|
|
|
|
2017-07-21 07:09:13 -04:00
|
|
|
it 'has a merge request path to a target project' do
|
2017-07-19 07:11:39 -04:00
|
|
|
expect(subject[:merge_request][:path])
|
2017-07-21 07:09:13 -04:00
|
|
|
.to include project.full_path
|
2017-07-19 07:11:39 -04:00
|
|
|
end
|
2017-05-29 03:58:20 -04:00
|
|
|
end
|
|
|
|
|
2017-07-20 05:42:13 -04:00
|
|
|
context 'when the build has not been erased' do
|
|
|
|
let(:build) { create(:ci_build, :erasable, project: project) }
|
2017-05-29 03:58:20 -04:00
|
|
|
|
2017-07-20 05:42:13 -04:00
|
|
|
it 'exposes a build erase path' do
|
2017-05-29 03:58:20 -04:00
|
|
|
expect(subject).to include(:erase_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the build has been erased' do
|
2017-07-20 05:42:13 -04:00
|
|
|
let(:build) { create(:ci_build, :erased, project: project) }
|
2017-05-29 03:58:20 -04:00
|
|
|
|
2017-07-20 05:42:13 -04:00
|
|
|
it 'exposes the user who erased the build' do
|
2017-05-29 03:58:20 -04:00
|
|
|
expect(subject).to include(:erased_by)
|
|
|
|
end
|
2017-05-23 11:10:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user can only read the build' do
|
2017-05-26 04:31:42 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2017-05-23 11:10:07 -04:00
|
|
|
it "won't display the paths to issues and merge requests" do
|
|
|
|
expect(subject['new_issue_path']).to be_nil
|
|
|
|
expect(subject['merge_request_path']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|