bourgeois 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bourgeois/presenter.rb +1 -1
- data/lib/bourgeois/version.rb +1 -1
- data/spec/bourgeois/presenter_spec.rb +16 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5869471a07dcb6bc5f57f478de63ff06b4d4bf5a
|
4
|
+
data.tar.gz: 750e2123766395e20d65c1c53ec6ae6b5ae464df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0658e2b88a38375914022c651a9ec4c2edebf46cef6409f104ace0e62896774482fb8e0c17ff592bd7a87d9c9b74a1ee3a22a68546f8adc3524a22a06935a231
|
7
|
+
data.tar.gz: 90abbc8eb9b200279f7839cdb2dffbbcd29d848c40799379cb6fe22bb22e1a333770cdc1b8483fe7d601354cfa8390c7ad2c3e8aa07592bdcdef2d3a7b0c777c
|
data/lib/bourgeois/presenter.rb
CHANGED
@@ -54,7 +54,7 @@ module Bourgeois
|
|
54
54
|
# puts user.inspect # => #<UserPresenter object=#<User name="Remi>>
|
55
55
|
# puts user.name # => Remi
|
56
56
|
# end
|
57
|
-
def self.present(object, klass =
|
57
|
+
def self.present(object, klass = nil, &blk)
|
58
58
|
return if object.nil?
|
59
59
|
return object.map { |o| present(o, klass, &blk) } if object.respond_to?(:to_a) && !object.is_a?(Struct)
|
60
60
|
|
data/lib/bourgeois/version.rb
CHANGED
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Bourgeois::Presenter do
|
4
4
|
let(:user) { User.new first_name: 'Patrick', last_name: 'Bourgeois', birthdate: '1962-06-16' }
|
5
|
-
let(:
|
6
|
-
let(:presenter) { UserPresenter.new(user, view) }
|
5
|
+
let(:presenter) { UserPresenter.new(user) }
|
7
6
|
|
8
7
|
describe :DelegatedMethods do
|
9
8
|
before do
|
@@ -38,6 +37,9 @@ describe Bourgeois::Presenter do
|
|
38
37
|
end
|
39
38
|
|
40
39
|
describe :view do
|
40
|
+
let(:view) { ActionView::Base.new }
|
41
|
+
let(:presenter) { UserPresenter.new(user, view) }
|
42
|
+
|
41
43
|
context 'with present view' do
|
42
44
|
before do
|
43
45
|
class UserPresenter < Bourgeois::Presenter
|
@@ -259,8 +261,6 @@ describe Bourgeois::Presenter do
|
|
259
261
|
end
|
260
262
|
|
261
263
|
describe :present do
|
262
|
-
let(:view) { ActionView::Base.new }
|
263
|
-
|
264
264
|
before do
|
265
265
|
class UserPresenter < Bourgeois::Presenter
|
266
266
|
def formatted_name
|
@@ -273,7 +273,7 @@ describe Bourgeois::Presenter do
|
|
273
273
|
|
274
274
|
context 'on a Nil object' do
|
275
275
|
context 'without a block' do
|
276
|
-
it { expect {
|
276
|
+
it { expect { Bourgeois::Presenter.present(nil) }.not_to raise_error }
|
277
277
|
end
|
278
278
|
|
279
279
|
context 'with a block' do
|
@@ -281,7 +281,7 @@ describe Bourgeois::Presenter do
|
|
281
281
|
|
282
282
|
specify do
|
283
283
|
expect do
|
284
|
-
|
284
|
+
Bourgeois::Presenter.present(nil) { |obj| obj.formatted_name }
|
285
285
|
end.not_to raise_error
|
286
286
|
end
|
287
287
|
end
|
@@ -291,12 +291,12 @@ describe Bourgeois::Presenter do
|
|
291
291
|
let(:user) { User.new first_name: 'Patrick', last_name: 'Bourgeois' }
|
292
292
|
|
293
293
|
context 'without a block' do
|
294
|
-
it { expect(
|
294
|
+
it { expect(Bourgeois::Presenter.present(user).formatted_name).to eql 'Patrick Bourgeois' }
|
295
295
|
end
|
296
296
|
|
297
297
|
context 'with a block' do
|
298
298
|
specify do
|
299
|
-
|
299
|
+
Bourgeois::Presenter.present(user) do |u|
|
300
300
|
expect(u.formatted_name).to eql 'Patrick Bourgeois'
|
301
301
|
end
|
302
302
|
end
|
@@ -308,12 +308,12 @@ describe Bourgeois::Presenter do
|
|
308
308
|
let(:presenter) { UserPresenter.new(user) }
|
309
309
|
|
310
310
|
context 'without a block' do
|
311
|
-
it { expect(
|
311
|
+
it { expect(Bourgeois::Presenter.present(presenter).formatted_name).to eql 'Patrick Bourgeois' }
|
312
312
|
end
|
313
313
|
|
314
314
|
context 'with a block' do
|
315
315
|
specify do
|
316
|
-
|
316
|
+
Bourgeois::Presenter.present(presenter) do |u|
|
317
317
|
expect(u.formatted_name).to eql 'Patrick Bourgeois'
|
318
318
|
end
|
319
319
|
end
|
@@ -328,7 +328,7 @@ describe Bourgeois::Presenter do
|
|
328
328
|
|
329
329
|
specify do
|
330
330
|
output = []
|
331
|
-
|
331
|
+
Bourgeois::Presenter.present(users) { |u| output << u.formatted_name }
|
332
332
|
|
333
333
|
expect(output).to eql ['Patrick Bourgeois', 'Francois Jean', 'Alain Lapointe']
|
334
334
|
end
|
@@ -342,7 +342,7 @@ describe Bourgeois::Presenter do
|
|
342
342
|
|
343
343
|
specify do
|
344
344
|
output = []
|
345
|
-
|
345
|
+
Bourgeois::Presenter.present(users) { |u| output << u.formatted_name }
|
346
346
|
|
347
347
|
expect(output).to eql ['Patrick Bourgeois', 'Francois Jean', 'Alain Lapointe']
|
348
348
|
end
|
@@ -354,7 +354,7 @@ describe Bourgeois::Presenter do
|
|
354
354
|
end
|
355
355
|
|
356
356
|
let(:project) { Project.new name: 'Les B.B.' }
|
357
|
-
it { expect {
|
357
|
+
it { expect { Bourgeois::Presenter.present(project) }.to raise_error(Bourgeois::UnknownPresenter, 'unknown presenter class ProjectPresenter') }
|
358
358
|
end
|
359
359
|
|
360
360
|
context 'on a resource with a custom presenter class' do
|
@@ -368,7 +368,7 @@ describe Bourgeois::Presenter do
|
|
368
368
|
end
|
369
369
|
|
370
370
|
let(:article) { Article.new name: 'Les B.B.' }
|
371
|
-
let(:presented_article) {
|
371
|
+
let(:presented_article) { Bourgeois::Presenter.present(article, CustomArticlePresenter) }
|
372
372
|
|
373
373
|
it { expect { presented_article }.not_to raise_error }
|
374
374
|
it { expect(presented_article.name).to eql 'LES B.B.' }
|
@@ -387,7 +387,7 @@ describe Bourgeois::Presenter do
|
|
387
387
|
end
|
388
388
|
|
389
389
|
let(:band) { Band.new('Les B.B.') }
|
390
|
-
let(:presented_band) {
|
390
|
+
let(:presented_band) { Bourgeois::Presenter.present(band) }
|
391
391
|
|
392
392
|
it { expect(presented_band.name).to eql 'LES B.B.' }
|
393
393
|
end
|
@@ -406,7 +406,7 @@ describe Bourgeois::Presenter do
|
|
406
406
|
|
407
407
|
specify do
|
408
408
|
output = []
|
409
|
-
|
409
|
+
Bourgeois::Presenter.present(articles, CustomArticlePresenter) { |u| output << u.name }
|
410
410
|
|
411
411
|
expect(output).to eql ['LES B.B.', 'ROCK ET BELLES OREILLES']
|
412
412
|
end
|