showcase 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cc9956d43209ffcf07147c5ebd550aa6dd07407
4
- data.tar.gz: 2f0302d869f55ac73959facae8ce2595d4c5f4b2
3
+ metadata.gz: bcf0fde90d484b35c54b9cfb8ef72123de71a78d
4
+ data.tar.gz: fdcc72c89960d828ab4d496974cb45c01045dc19
5
5
  SHA512:
6
- metadata.gz: 28fdce56fdb476019ecf50d476f614bba7d8c7a01d569d78abe6c824ef213f930972d2b90ddf5010143f0d148527ba1f9f9c60e87908e1b674e75a95676ef1b7
7
- data.tar.gz: d613dce8342d633d97368a003937a068e64bd2d8ec8dc8825cf857648e9c759281c31b15413a35592b9883c4880ec68670d7e56065535bd4c0539510a58740f4
6
+ metadata.gz: 72365b989e2d2aeef8f757cbe85607097da0a602510652d03266b6d352f4c5036164dfe81376649407f47620af7296bde6bf7f8def7edc02a31b04fbfbda644b
7
+ data.tar.gz: c8774f411e41452fc643f952ed6c43413968d2246421cabce9b38d4854f23d80609d43f198328d5be234e8fb7b1f0bf96c4d1496480474044cffb3716a17cf6f
@@ -0,0 +1,5 @@
1
+ module Showcase
2
+ class PresenterClassNotFound < RuntimeError
3
+ end
4
+ end
5
+
@@ -2,6 +2,8 @@ require 'active_support/concern'
2
2
  require 'active_support/inflector'
3
3
  require 'active_support/core_ext/hash/keys'
4
4
 
5
+ require 'showcase/errors'
6
+
5
7
  module Showcase
6
8
  module Helpers
7
9
  module Present
@@ -20,6 +22,9 @@ module Showcase
20
22
 
21
23
  if obj || options.fetch(:nil_presenter, false)
22
24
  klass ||= presenter_class(obj)
25
+ if klass.nil?
26
+ raise Showcase::PresenterClassNotFound, "Unable to guess a presenter class for #{obj.inspect}!"
27
+ end
23
28
  klass.new(obj, context)
24
29
  else
25
30
  nil
@@ -37,7 +42,9 @@ module Showcase
37
42
  klass = "#{k.name}Presenter".safe_constantize
38
43
  return klass if klass
39
44
  end
45
+ nil
40
46
  end
41
47
  end
42
48
  end
43
49
  end
50
+
@@ -1,4 +1,4 @@
1
1
  module Showcase
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
4
4
 
data/spec/helpers_spec.rb CHANGED
@@ -2,23 +2,33 @@ require 'spec_helper'
2
2
 
3
3
  describe Showcase::Helpers do
4
4
  let(:object) { Person.new('Steve Ballmer') }
5
- let(:derived_object) { EnterpriseCustomer.new('Tito Traves') }
5
+ let(:subclass_object) { EnterpriseCustomer.new('Tito Traves') }
6
+ let(:object_with_no_presenter) { Shop.new }
6
7
  let(:context) { Context.new }
7
8
 
8
9
  describe '.present' do
9
- it 'instantiates a new presenter, inferring the class' do
10
+ it 'instantiates a new presenter, inferring the presenter class' do
10
11
  PersonPresenter.stub(:new).with(object, context).and_return 'Presenter'
11
12
  context.present(object).should == 'Presenter'
12
13
  end
13
- it "instantiates a new presenter, searching presenter class in object ancestors chain" do
14
- PersonPresenter.stub(:new).with(derived_object, context).and_return 'Presenter'
15
- context.present(derived_object).should == 'Presenter'
14
+ context 'with a superclass presenter' do
15
+ it "instantiates a new presenter, searching presenter class in object ancestors chain" do
16
+ PersonPresenter.stub(:new).with(subclass_object, context).and_return 'Presenter'
17
+ context.present(subclass_object).should == 'Presenter'
18
+ end
16
19
  end
17
- it 'the presenter class to use can be specified as the second parameter' do
20
+ context 'with no existing presenter class' do
21
+ it "raises a PresenterClassNotFound error" do
22
+ expect {
23
+ context.present(object_with_no_presenter)
24
+ }.to raise_error(Showcase::PresenterClassNotFound)
25
+ end
26
+ end
27
+ it 'uses the specified presenter class, when passed' do
18
28
  ProjectPresenter.stub(:new).with(object, context).and_return 'Presenter'
19
29
  context.present(object, ProjectPresenter).should == 'Presenter'
20
30
  end
21
- it 'the context to use can be specified as third parameter' do
31
+ it 'uses the specified context, when passed' do
22
32
  different_context = double
23
33
  context.present(object, ProjectPresenter, different_context).view_context.should == different_context
24
34
  end
@@ -36,3 +46,4 @@ describe Showcase::Helpers do
36
46
  end
37
47
  end
38
48
  end
49
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: showcase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-14 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -101,6 +101,7 @@ files:
101
101
  - lib/generators/showcase/presenter/presenter_generator.rb
102
102
  - lib/generators/showcase/presenter/templates/presenter.rb
103
103
  - lib/showcase.rb
104
+ - lib/showcase/errors.rb
104
105
  - lib/showcase/helpers/config_object.rb
105
106
  - lib/showcase/helpers/html_options.rb
106
107
  - lib/showcase/helpers/module_method_builder.rb
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  version: '0'
147
148
  requirements: []
148
149
  rubyforge_project:
149
- rubygems_version: 2.0.3
150
+ rubygems_version: 2.0.14
150
151
  signing_key:
151
152
  specification_version: 4
152
153
  summary: A barebone and framework agnostic presenter implementation