diff options
author | Rémy Coutable <remy@rymai.me> | 2017-01-11 01:41:04 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-01-18 18:38:35 +0300 |
commit | 061bb6eb6ed0ca6be3c571b3fcfd14a6f9729205 (patch) | |
tree | 2b87e3ea5d1e67b19c515891d19b466c80040a04 /spec/presenters | |
parent | e950830ba6a0efa3b0992e6e55cb5b5842f8573a (diff) |
More improvements to presenters
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/presenters')
-rw-r--r-- | spec/presenters/ci/build_presenter_spec.rb (renamed from spec/presenters/ci/build/presenter_spec.rb) | 30 | ||||
-rw-r--r-- | spec/presenters/ci/variable/presenter_spec.rb | 23 |
2 files changed, 16 insertions, 37 deletions
diff --git a/spec/presenters/ci/build/presenter_spec.rb b/spec/presenters/ci/build_presenter_spec.rb index ecab84dcbc9..7a35da38b2b 100644 --- a/spec/presenters/ci/build/presenter_spec.rb +++ b/spec/presenters/ci/build_presenter_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -describe Ci::Build::Presenter do +describe Ci::BuildPresenter do let(:project) { create(:empty_project) } let(:pipeline) { create(:ci_pipeline, project: project) } let(:build) { create(:ci_build, pipeline: pipeline) } - subject do + subject(:presenter) do described_class.new(build) end @@ -15,60 +15,62 @@ describe Ci::Build::Presenter do describe '#initialize' do it 'takes a build and optional params' do - expect { subject }.not_to raise_error + expect { presenter }.not_to raise_error end it 'exposes build' do - expect(subject.build).to eq(build) + expect(presenter.build).to eq(build) end it 'forwards missing methods to build' do - expect(subject.ref).to eq('master') + expect(presenter.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 + 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(build).to receive(:erased_by).and_return(nil) + expect(presenter).to receive(:erased_by_user?).and_return(false) end it 'returns nil' do - expect(subject.erased_by_name).to be_nil + expect(presenter.erased_by_name).to be_nil end end + context 'when build is erased' do before do - expect(build).to receive(:erased_by).twice. + expect(presenter).to receive(:erased_by_user?).and_return(true) + expect(build).to receive(:erased_by). 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') + expect(presenter.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) } + let(:project) { build_stubbed(:empty_project, public_builds: false) } it 'returns false' do - expect(subject.can?(nil, :read_build)).to be_falsy + expect(presenter.can?(nil, :read_build)).to be_falsy end end context 'user is allowed' do - let(:project) { create(:empty_project, :public) } + let(:project) { build_stubbed(:empty_project, :public) } it 'returns true' do - expect(subject.can?(nil, :read_build)).to be_truthy + expect(presenter.can?(nil, :read_build)).to be_truthy end end end diff --git a/spec/presenters/ci/variable/presenter_spec.rb b/spec/presenters/ci/variable/presenter_spec.rb deleted file mode 100644 index b3afb2e2e33..00000000000 --- a/spec/presenters/ci/variable/presenter_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -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 |