gitlab-org--gitlab-foss/spec/lib/gitlab/view/presenter/base_spec.rb
Rémy Coutable 061bb6eb6e More improvements to presenters
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-01-18 16:38:35 +01:00

51 lines
1.3 KiB
Ruby

require 'spec_helper'
describe Gitlab::View::Presenter::Base do
let(:project) { double(:project) }
let(:presenter_class) do
Struct.new(:subject).include(described_class)
end
describe '.presenter?' do
it 'returns true' do
presenter = presenter_class.new(project)
expect(presenter.class).to be_presenter
end
end
describe '.presents' do
it 'exposes #subject with the given keyword' do
presenter_class.presents(:foo)
presenter = presenter_class.new(project)
expect(presenter.foo).to eq(project)
end
end
describe '#can?' do
context 'user is not allowed' do
it 'returns false' do
presenter = presenter_class.new(build_stubbed(:empty_project))
expect(presenter.can?(nil, :read_project)).to be_falsy
end
end
context 'user is allowed' do
it 'returns true' do
presenter = presenter_class.new(build_stubbed(:empty_project, :public))
expect(presenter.can?(nil, :read_project)).to be_truthy
end
end
context 'subject is overriden' do
it 'returns true' do
presenter = presenter_class.new(build_stubbed(:empty_project, :public))
expect(presenter.can?(nil, :read_project, build_stubbed(:empty_project))).to be_falsy
end
end
end
end