2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-09 15:45:49 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::View::Presenter::Delegated do
|
2017-01-20 12:13:14 -05:00
|
|
|
let(:project) { double(:project, user: 'John Doe') }
|
2017-01-09 15:45:49 -05:00
|
|
|
let(:presenter_class) do
|
|
|
|
Class.new(described_class)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes Gitlab::View::Presenter::Base' do
|
|
|
|
expect(described_class).to include(Gitlab::View::Presenter::Base)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
it 'takes arbitrary key/values and exposes them' do
|
2017-01-20 12:13:14 -05:00
|
|
|
presenter = presenter_class.new(project, current_user: 'Jane Doe')
|
2017-01-10 17:41:04 -05:00
|
|
|
|
2017-01-20 12:13:14 -05:00
|
|
|
expect(presenter.current_user).to eq('Jane Doe')
|
|
|
|
end
|
|
|
|
|
2017-01-24 11:07:56 -05:00
|
|
|
it 'raise an error if the presentee already respond to method' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect { presenter_class.new(project, user: 'Jane Doe') }
|
|
|
|
.to raise_error Gitlab::View::Presenter::CannotOverrideMethodError
|
2017-01-09 15:45:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'delegation' do
|
2017-01-10 17:41:04 -05:00
|
|
|
it 'forwards missing methods to subject' do
|
|
|
|
presenter = presenter_class.new(project)
|
|
|
|
|
2017-01-20 12:13:14 -05:00
|
|
|
expect(presenter.user).to eq('John Doe')
|
2017-01-09 15:45:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|