summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/view/presenter/base_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/view/presenter/base_spec.rb')
-rw-r--r--spec/lib/gitlab/view/presenter/base_spec.rb34
1 files changed, 25 insertions, 9 deletions
diff --git a/spec/lib/gitlab/view/presenter/base_spec.rb b/spec/lib/gitlab/view/presenter/base_spec.rb
index a7083bd2722..afb44c0d298 100644
--- a/spec/lib/gitlab/view/presenter/base_spec.rb
+++ b/spec/lib/gitlab/view/presenter/base_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::View::Presenter::Base do
let(:project) { double(:project) }
let(:presenter_class) do
- Struct.new(:subject).include(described_class)
+ Struct.new(:__subject__).include(described_class)
end
describe '.presenter?' do
@@ -17,17 +17,24 @@ RSpec.describe Gitlab::View::Presenter::Base do
end
describe '.presents' do
- it 'exposes #subject with the given keyword' do
- presenter_class.presents(Object, as: :foo)
- presenter = presenter_class.new(project)
-
- expect(presenter.foo).to eq(project)
- end
-
it 'raises an error when symbol is passed' do
expect { presenter_class.presents(:foo) }.to raise_error(ArgumentError)
end
+ context 'when the presenter class specifies a custom keyword' do
+ subject(:presenter) { presenter_class.new(project) }
+
+ before do
+ presenter_class.class_eval do
+ presents Object, as: :foo
+ end
+ end
+
+ it 'exposes the subject with the given keyword' do
+ expect(presenter.foo).to be(project)
+ end
+ end
+
context 'when the presenter class inherits Presenter::Delegated' do
let(:presenter_class) do
Class.new(::Gitlab::View::Presenter::Delegated) do
@@ -50,13 +57,22 @@ RSpec.describe Gitlab::View::Presenter::Base do
end
it 'does not set the delegator target' do
- expect(presenter_class).not_to receive(:delegator_target).with(Object)
+ expect(presenter_class).not_to receive(:delegator_target)
presenter_class.presents(Object, as: :foo)
end
end
end
+ describe '#__subject__' do
+ it 'returns the subject' do
+ subject = double
+ presenter = presenter_class.new(subject)
+
+ expect(presenter.__subject__).to be(subject)
+ end
+ end
+
describe '#can?' do
context 'user is not allowed' do
it 'returns false' do