debian-mirror-gitlab/spec/lib/gitlab/view/presenter/base_spec.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::View::Presenter::Base do
2017-08-17 22:00:37 +05:30
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
2017-09-10 17:25:29 +05:30
presenter = presenter_class.new(build_stubbed(:project))
2017-08-17 22:00:37 +05:30
expect(presenter.can?(nil, :read_project)).to be_falsy
end
end
context 'user is allowed' do
it 'returns true' do
2017-09-10 17:25:29 +05:30
presenter = presenter_class.new(build_stubbed(:project, :public))
2017-08-17 22:00:37 +05:30
expect(presenter.can?(nil, :read_project)).to be_truthy
end
end
2018-12-13 13:39:08 +05:30
context 'subject is overridden' do
2017-08-17 22:00:37 +05:30
it 'returns true' do
2017-09-10 17:25:29 +05:30
presenter = presenter_class.new(build_stubbed(:project, :public))
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(presenter.can?(nil, :read_project, build_stubbed(:project))).to be_falsy
2017-08-17 22:00:37 +05:30
end
end
end
2018-10-15 14:42:47 +05:30
describe '#present' do
it 'returns self' do
presenter = presenter_class.new(build_stubbed(:project))
expect(presenter.present).to eq(presenter)
end
end
2017-08-17 22:00:37 +05:30
end