2017-01-09 20:45:49 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-01-10 22:41:04 +00:00
|
|
|
describe Ci::BuildPresenter do
|
2017-01-09 20:45:49 +00:00
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
|
2017-01-10 22:41:04 +00:00
|
|
|
subject(:presenter) do
|
2017-01-09 20:45:49 +00:00
|
|
|
described_class.new(build)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'inherits from Gitlab::View::Presenter::Delegated' do
|
|
|
|
expect(described_class.superclass).to eq(Gitlab::View::Presenter::Delegated)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
it 'takes a build and optional params' do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect { presenter }.not_to raise_error
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes build' do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter.build).to eq(build)
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'forwards missing methods to build' do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter.ref).to eq('master')
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#erased_by_user?' do
|
|
|
|
it 'takes a build and optional params' do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter).not_to be_erased_by_user
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#erased_by_name' do
|
|
|
|
context 'when build is not erased' do
|
|
|
|
before do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter).to receive(:erased_by_user?).and_return(false)
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil' do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter.erased_by_name).to be_nil
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
end
|
2017-01-10 22:41:04 +00:00
|
|
|
|
2017-01-09 20:45:49 +00:00
|
|
|
context 'when build is erased' do
|
|
|
|
before do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter).to receive(:erased_by_user?).and_return(true)
|
|
|
|
expect(build).to receive(:erased_by).
|
2017-01-09 20:45:49 +00:00
|
|
|
and_return(double(:user, name: 'John Doe'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the name of the eraser' do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter.erased_by_name).to eq('John Doe')
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'quack like a Ci::Build permission-wise' do
|
|
|
|
context 'user is not allowed' do
|
2017-01-10 22:41:04 +00:00
|
|
|
let(:project) { build_stubbed(:empty_project, public_builds: false) }
|
2017-01-09 20:45:49 +00:00
|
|
|
|
|
|
|
it 'returns false' do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter.can?(nil, :read_build)).to be_falsy
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is allowed' do
|
2017-01-10 22:41:04 +00:00
|
|
|
let(:project) { build_stubbed(:empty_project, :public) }
|
2017-01-09 20:45:49 +00:00
|
|
|
|
|
|
|
it 'returns true' do
|
2017-01-10 22:41:04 +00:00
|
|
|
expect(presenter.can?(nil, :read_build)).to be_truthy
|
2017-01-09 20:45:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|