bourgeois 0.1.5 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 402ab7751e8f57a74932292cbed09cffb02f5811
4
- data.tar.gz: 0cfd05d7d40d74475b7c0824e6ea437219078806
3
+ metadata.gz: f2bc10e6f30ee29a0b8bb2fd612ef97f8f67cf49
4
+ data.tar.gz: c31c4dba94b71fcf88b06523325523644863f633
5
5
  SHA512:
6
- metadata.gz: 03fa180f5385cf260c584d409ef917850d11b63de6195f960108cce00abe160a7b49d2d834dbc8d4caee11369cd7e88855d6f14ae715c0f9ff87582220013c77
7
- data.tar.gz: 58fd1285454fe05f194658ebf555d730563fe6166397b8327652312ad48801a50d3109243611b7a7a693ea5cc9c7f43be968edeb2e64047f00b3e905c2140e09
6
+ metadata.gz: 8f635a2839bf1ad9d0a3a1b2825103675cd284062b080a4eb774df234fbbf9803333f2ba27d0706b1cbbaba11dc618ea2c8849c5a6c699ae7f911b75706dd8b1
7
+ data.tar.gz: 56923d9ed6669f71491150fb08bd65885e9363cb57e2d62f057ab9f48ba8c2dd0d736d012e840fcbcf7932dc23f414b6f02cfd67f084c4071eee460a0b0f4783
data/README.md CHANGED
@@ -73,7 +73,7 @@ class UserPresenter < Bourgeois::Presenter
73
73
  helper :with_profile, if: -> { profile.present? && profile.public? }
74
74
  end
75
75
 
76
- User.first.new = Profile.create(public: true, title: 'Foo', description: 'Bar')
76
+ User.first.profile = Profile.create(public: true, title: 'Foo', description: 'Bar')
77
77
  ```
78
78
 
79
79
  ```erb
@@ -1,3 +1,3 @@
1
1
  module Bourgeois
2
- VERSION = '0.1.5'
2
+ VERSION = '1.0'
3
3
  end
@@ -11,15 +11,19 @@ module Bourgeois
11
11
  return object.map { |o| present(o, klass, &blk) } if object.respond_to?(:to_a)
12
12
 
13
13
  if klass.blank?
14
- begin
15
- klass_name = "#{object.class}Presenter"
16
- klass = klass_name.constantize
17
- rescue ::NameError
18
- raise UnknownPresenter.new(klass_name)
14
+ if object.is_a?(Bourgeois::Presenter)
15
+ presenter = object
16
+ else
17
+ begin
18
+ klass_name = "#{object.class}Presenter"
19
+ klass = klass_name.constantize
20
+ rescue ::NameError
21
+ raise UnknownPresenter.new(klass_name)
22
+ end
19
23
  end
20
24
  end
21
25
 
22
- presenter = klass.new(object, self)
26
+ presenter ||= klass.new(object, self)
23
27
  yield presenter if block_given?
24
28
 
25
29
  presenter
@@ -30,6 +30,23 @@ describe Bourgeois::ViewHelper do
30
30
  end
31
31
  end
32
32
 
33
+ context 'on a single already-presented resource' do
34
+ let(:user) { User.new first_name: 'Patrick', last_name: 'Bourgeois' }
35
+ let(:presenter) { UserPresenter.new(user) }
36
+
37
+ context 'without a block' do
38
+ it { expect(view.present(presenter).formatted_name).to eql 'Patrick Bourgeois' }
39
+ end
40
+
41
+ context 'with a block' do
42
+ specify do
43
+ view.present(presenter) do |u|
44
+ expect(u.formatted_name).to eql 'Patrick Bourgeois'
45
+ end
46
+ end
47
+ end
48
+ end
49
+
33
50
  context 'on a collection of resources' do
34
51
  let(:user1) { User.new first_name: 'Patrick', last_name: 'Bourgeois' }
35
52
  let(:user2) { User.new first_name: 'Francois', last_name: 'Jean' }
@@ -44,6 +61,20 @@ describe Bourgeois::ViewHelper do
44
61
  end
45
62
  end
46
63
 
64
+ context 'on a collection of already-presented resources' do
65
+ let(:user1) { User.new first_name: 'Patrick', last_name: 'Bourgeois' }
66
+ let(:user2) { User.new first_name: 'Francois', last_name: 'Jean' }
67
+ let(:user3) { User.new first_name: 'Alain', last_name: 'Lapointe' }
68
+ let(:users) { [UserPresenter.new(user1), UserPresenter.new(user2), UserPresenter.new(user3)] }
69
+
70
+ specify do
71
+ output = []
72
+ view.present(users) { |u| output << u.formatted_name }
73
+
74
+ expect(output).to eql ['Patrick Bourgeois', 'Francois Jean', 'Alain Lapointe']
75
+ end
76
+ end
77
+
47
78
  context 'on a resource without a defined presenter class' do
48
79
  before do
49
80
  class Project < OpenStruct; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bourgeois
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-24 00:00:00.000000000 Z
11
+ date: 2013-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel