gitlab-org--gitlab-foss/spec/presenters/ci/build_presenter_spec.rb

104 lines
2.6 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Ci::BuildPresenter do
let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, pipeline: pipeline) }
subject(:presenter) do
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
expect { presenter }.not_to raise_error
end
it 'exposes build' do
expect(presenter.build).to eq(build)
end
it 'forwards missing methods to build' do
expect(presenter.ref).to eq('master')
end
end
describe '#erased_by_user?' do
it 'takes a build and optional params' do
expect(presenter).not_to be_erased_by_user
end
end
describe '#erased_by_name' do
context 'when build is not erased' do
before do
expect(presenter).to receive(:erased_by_user?).and_return(false)
end
it 'returns nil' do
expect(presenter.erased_by_name).to be_nil
end
end
context 'when build is erased' do
before do
expect(presenter).to receive(:erased_by_user?).and_return(true)
2017-06-21 09:48:12 -04:00
expect(build).to receive(:erased_by)
.and_return(double(:user, name: 'John Doe'))
end
it 'returns the name of the eraser' do
expect(presenter.erased_by_name).to eq('John Doe')
end
end
end
2017-04-05 15:10:52 -04:00
describe '#status_title' do
context 'when build is auto-canceled' do
2017-04-05 15:10:52 -04:00
before do
expect(build).to receive(:auto_canceled?).and_return(true)
expect(build).to receive(:auto_canceled_by_id).and_return(1)
2017-04-05 15:10:52 -04:00
end
it 'shows that the build is auto-canceled' do
status_title = presenter.status_title
2017-04-05 15:10:52 -04:00
expect(status_title).to include('auto-canceled')
expect(status_title).to include('Pipeline #1')
2017-04-05 15:10:52 -04:00
end
end
2017-04-05 15:10:52 -04:00
context 'when build is not auto-canceled' do
before do
expect(build).to receive(:auto_canceled?).and_return(false)
end
2017-04-05 15:10:52 -04:00
it 'does not have a status title' do
expect(presenter.status_title).to be_nil
2017-04-05 15:10:52 -04:00
end
end
end
describe 'quack like a Ci::Build permission-wise' do
context 'user is not allowed' do
let(:project) { create(:project, public_builds: false) }
it 'returns false' do
expect(presenter.can?(nil, :read_build)).to be_falsy
end
end
context 'user is allowed' do
let(:project) { create(:project, :public) }
it 'returns true' do
expect(presenter.can?(nil, :read_build)).to be_truthy
end
end
end
end