diff options
author | Rémy Coutable <remy@rymai.me> | 2017-01-09 21:45:49 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-01-18 16:38:34 +0100 |
commit | bf789ff567c71ff68c216bfa8f3d43e09b6f49fb (patch) | |
tree | 28d4ac2aa74824eb5d85dc8271474980a3237bbe /spec/presenters/ci | |
parent | fd72c0f4c748658f539d24a286366e9ac7a22b57 (diff) | |
download | gitlab-ce-bf789ff567c71ff68c216bfa8f3d43e09b6f49fb.tar.gz |
Improve presenter architecture
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/presenters/ci')
-rw-r--r-- | spec/presenters/ci/build/presenter_spec.rb | 75 | ||||
-rw-r--r-- | spec/presenters/ci/variable/presenter_spec.rb | 23 |
2 files changed, 98 insertions, 0 deletions
diff --git a/spec/presenters/ci/build/presenter_spec.rb b/spec/presenters/ci/build/presenter_spec.rb new file mode 100644 index 00000000000..ecab84dcbc9 --- /dev/null +++ b/spec/presenters/ci/build/presenter_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper' + +describe Ci::Build::Presenter do + let(:project) { create(:empty_project) } + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:build) { create(:ci_build, pipeline: pipeline) } + + subject 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 { subject }.not_to raise_error + end + + it 'exposes build' do + expect(subject.build).to eq(build) + end + + it 'forwards missing methods to build' do + expect(subject.ref).to eq('master') + end + end + + describe '#erased_by_user?' do + it 'takes a build and optional params' do + expect(subject).not_to be_erased_by_user + end + end + + describe '#erased_by_name' do + context 'when build is not erased' do + before do + expect(build).to receive(:erased_by).and_return(nil) + end + + it 'returns nil' do + expect(subject.erased_by_name).to be_nil + end + end + context 'when build is erased' do + before do + expect(build).to receive(:erased_by).twice. + and_return(double(:user, name: 'John Doe')) + end + + it 'returns the name of the eraser' do + expect(subject.erased_by_name).to eq('John Doe') + end + end + end + + describe 'quack like a Ci::Build permission-wise' do + context 'user is not allowed' do + let(:project) { create(:empty_project, public_builds: false) } + + it 'returns false' do + expect(subject.can?(nil, :read_build)).to be_falsy + end + end + + context 'user is allowed' do + let(:project) { create(:empty_project, :public) } + + it 'returns true' do + expect(subject.can?(nil, :read_build)).to be_truthy + end + end + end +end diff --git a/spec/presenters/ci/variable/presenter_spec.rb b/spec/presenters/ci/variable/presenter_spec.rb new file mode 100644 index 00000000000..b3afb2e2e33 --- /dev/null +++ b/spec/presenters/ci/variable/presenter_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Ci::Variable::Presenter do + let(:variable) { double(:variable) } + + subject do + described_class.new(variable) + end + + it 'inherits from Gitlab::View::Presenter::Simple' do + expect(described_class.superclass).to eq(Gitlab::View::Presenter::Simple) + end + + describe '#initialize' do + it 'takes a variable and optional params' do + expect { subject }.not_to raise_error + end + + it 'exposes variable' do + expect(subject.variable).to eq(variable) + end + end +end |