diff options
author | Rémy Coutable <remy@rymai.me> | 2017-01-06 14:30:19 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-01-18 18:38:34 +0300 |
commit | b4f67cc2294f262d35fe63cc1e60eccebc4667ac (patch) | |
tree | 34b125dee583f517f4fe4d8e6e0148d06a3f68fc /spec/lib/gitlab/view | |
parent | 5e9196b3bcc31ce7fd698ed49af5d39eae1da630 (diff) |
Document presenters
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/lib/gitlab/view')
-rw-r--r-- | spec/lib/gitlab/view/presenter_factory_spec.rb | 48 | ||||
-rw-r--r-- | spec/lib/gitlab/view/presenter_spec.rb | 29 |
2 files changed, 77 insertions, 0 deletions
diff --git a/spec/lib/gitlab/view/presenter_factory_spec.rb b/spec/lib/gitlab/view/presenter_factory_spec.rb new file mode 100644 index 00000000000..c5e4d86f6c9 --- /dev/null +++ b/spec/lib/gitlab/view/presenter_factory_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Gitlab::View::PresenterFactory do + let(:appearance) { build(:appearance) } + let(:broadcast_message) { build(:broadcast_message) } + + before do + class AppearancePresenter + include Gitlab::View::Presenter + end + + class BroadcastMessagePresenter < SimpleDelegator + include Gitlab::View::Presenter + end + end + + describe '#initialize' do + subject do + described_class.new(appearance) + end + + it 'takes a subject and optional params' do + expect { subject }.not_to raise_error + end + end + + describe '#fabricate!' do + context 'without delegation' do + subject do + described_class.new(appearance).fabricate! + end + + it 'does not forward missing methods to subject' do + expect { subject.title }.to raise_error(NoMethodError) + end + end + + context 'with delegation' do + subject do + described_class.new(broadcast_message).fabricate! + end + + it 'forwards missing methods to subject' do + expect(subject.message).to eq(broadcast_message.message) + end + end + end +end diff --git a/spec/lib/gitlab/view/presenter_spec.rb b/spec/lib/gitlab/view/presenter_spec.rb new file mode 100644 index 00000000000..0880fbe5d77 --- /dev/null +++ b/spec/lib/gitlab/view/presenter_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Gitlab::View::Presenter do + let(:project) { double(:project, bar: 'baz!') } + let(:presenter) do + base_presenter = described_class + + Class.new do + include base_presenter + + presents :foo + end + end + subject do + presenter.new.with_subject(project) + end + + describe '#initialize' do + it 'takes an object accessible via a reader' do + expect(subject.foo).to eq(project) + end + end + + describe 'common helpers' do + it 'responds to #can?' do + expect(subject).to respond_to(:can?) + end + end +end |