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) }
|
|
|
|
let!(:build) { create(:ci_build, :failed, project: project) }
|
|
|
|
let(:request) { double('request') }
|
|
|
|
let(:entity) { described_class.new(build, request: request, current_user: user, project: project) }
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user has access to issues and merge requests' do
|
2017-05-26 04:31:42 -04:00
|
|
|
let!(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project, source_branch: build.ref)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(build).to receive(:merge_request).and_return(merge_request)
|
|
|
|
end
|
2017-05-23 11:10:07 -04:00
|
|
|
|
|
|
|
it 'contains the needed key value pairs' do
|
|
|
|
expect(subject).to include(:coverage, :erased_at, :duration)
|
2017-06-13 05:05:48 -04:00
|
|
|
expect(subject).to include(:runner, :pipeline)
|
2017-06-01 15:34:44 -04:00
|
|
|
expect(subject).to include(:raw_path, :merge_request)
|
2017-06-02 14:32:37 -04:00
|
|
|
expect(subject).to include(:new_issue_path)
|
2017-05-29 03:58:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes details of the merge request' do
|
|
|
|
expect(subject[:merge_request]).to include(:iid, :path)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the build has been erased' do
|
|
|
|
let!(:build) { create(:ci_build, :erasable, project: project) }
|
|
|
|
|
|
|
|
it 'exposes the user whom erased the build' do
|
|
|
|
expect(subject).to include(:erase_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the build has been erased' do
|
|
|
|
let!(:build) { create(:ci_build, erased_at: Time.now, project: project, erased_by: user) }
|
|
|
|
|
|
|
|
it 'exposes the user whom erased the build' do
|
|
|
|
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
|