draper 3.0.0.pre1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +16 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +24 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +20 -0
- data/Guardfile +5 -5
- data/README.md +27 -5
- data/Rakefile +1 -2
- data/draper.gemspec +1 -0
- data/lib/draper.rb +7 -2
- data/lib/draper/automatic_delegation.rb +5 -3
- data/lib/draper/collection_decorator.rb +1 -11
- data/lib/draper/compatibility/api_only.rb +23 -0
- data/lib/draper/configuration.rb +15 -0
- data/lib/draper/decoratable.rb +2 -2
- data/lib/draper/decorator.rb +4 -12
- data/lib/draper/finders.rb +0 -0
- data/lib/draper/helper_proxy.rb +1 -8
- data/lib/draper/railtie.rb +12 -13
- data/lib/draper/tasks/test.rake +1 -1
- data/lib/draper/test/devise_helper.rb +1 -8
- data/lib/draper/test/minitest_integration.rb +0 -0
- data/lib/draper/test/rspec_integration.rb +0 -0
- data/lib/draper/undecorate.rb +8 -0
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context.rb +3 -19
- data/lib/draper/view_context/build_strategy.rb +11 -2
- data/lib/generators/controller_override.rb +2 -2
- data/lib/generators/draper/install_generator.rb +14 -0
- data/lib/generators/draper/templates/application_decorator.rb +8 -0
- data/lib/generators/mini_test/decorator_generator.rb +1 -1
- data/lib/generators/rails/decorator_generator.rb +1 -8
- data/lib/generators/rspec/templates/decorator_spec.rb +1 -1
- data/spec/draper/collection_decorator_spec.rb +11 -26
- data/spec/draper/configuration_spec.rb +25 -0
- data/spec/draper/decoratable_spec.rb +28 -13
- data/spec/draper/decorated_association_spec.rb +9 -9
- data/spec/draper/decorates_assigned_spec.rb +6 -6
- data/spec/draper/decorator_spec.rb +104 -89
- data/spec/draper/draper_spec.rb +24 -0
- data/spec/draper/factory_spec.rb +24 -24
- data/spec/draper/finders_spec.rb +21 -21
- data/spec/draper/helper_proxy_spec.rb +2 -2
- data/spec/draper/lazy_helpers_spec.rb +2 -2
- data/spec/draper/undecorate_chain_spec.rb +20 -0
- data/spec/draper/view_context/build_strategy_spec.rb +26 -10
- data/spec/draper/view_context_spec.rb +49 -21
- data/spec/dummy/app/controllers/base_controller.rb +4 -0
- data/spec/dummy/app/controllers/posts_controller.rb +2 -2
- data/spec/dummy/app/decorators/post_decorator.rb +0 -0
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/initializers/draper.rb +3 -0
- data/spec/dummy/db/schema.rb +4 -4
- data/spec/dummy/fast_spec/post_decorator_spec.rb +1 -1
- data/spec/dummy/lib/tasks/test.rake +1 -1
- data/spec/dummy/spec/decorators/devise_spec.rb +0 -9
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +2 -2
- data/spec/dummy/test/decorators/minitest/devise_test.rb +0 -9
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +3 -3
- data/spec/dummy/test/decorators/test_unit/devise_test.rb +0 -9
- data/spec/generators/controller/controller_generator_spec.rb +3 -3
- data/spec/generators/decorator/decorator_generator_spec.rb +11 -10
- data/spec/generators/install/install_generator_spec.rb +19 -0
- data/spec/spec_helper.rb +4 -3
- data/spec/support/shared_examples/view_helpers.rb +8 -8
- metadata +38 -7
- data/spec/dummy/app/controllers/application_controller.rb +0 -4
@@ -28,14 +28,14 @@ module Draper
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "creates a factory" do
|
31
|
-
Factory.
|
31
|
+
allow(Factory).to receive(:new).once
|
32
32
|
controller_class.decorates_assigned :article, :author
|
33
33
|
end
|
34
34
|
|
35
35
|
it "passes options to the factory" do
|
36
36
|
options = {foo: "bar"}
|
37
37
|
|
38
|
-
Factory.
|
38
|
+
allow(Factory).to receive(:new).with(options)
|
39
39
|
controller_class.decorates_assigned :article, :author, options
|
40
40
|
end
|
41
41
|
|
@@ -43,24 +43,24 @@ module Draper
|
|
43
43
|
it "decorates the instance variable" do
|
44
44
|
object = double
|
45
45
|
factory = double
|
46
|
-
Factory.
|
46
|
+
allow(Factory).to receive_messages(new: factory)
|
47
47
|
|
48
48
|
controller_class.decorates_assigned :article
|
49
49
|
controller = controller_class.new
|
50
50
|
controller.instance_variable_set "@article", object
|
51
51
|
|
52
|
-
factory.
|
52
|
+
expect(factory).to receive(:decorate).with(object, context_args: controller).and_return(:decorated)
|
53
53
|
expect(controller.article).to be :decorated
|
54
54
|
end
|
55
55
|
|
56
56
|
it "memoizes" do
|
57
57
|
factory = double
|
58
|
-
Factory.
|
58
|
+
allow(Factory).to receive_messages(new: factory)
|
59
59
|
|
60
60
|
controller_class.decorates_assigned :article
|
61
61
|
controller = controller_class.new
|
62
62
|
|
63
|
-
factory.
|
63
|
+
expect(factory).to receive(:decorate).once
|
64
64
|
controller.article
|
65
65
|
controller.article
|
66
66
|
end
|
@@ -73,7 +73,7 @@ module Draper
|
|
73
73
|
decorated = OtherDecorator.new(Decorator.new(Model.new))
|
74
74
|
|
75
75
|
warning_message = nil
|
76
|
-
Object.
|
76
|
+
allow_any_instance_of(Object).to receive(:warn) { |instance, message| warning_message = message }
|
77
77
|
|
78
78
|
expect{Decorator.new(decorated)}.to change{warning_message}
|
79
79
|
expect(warning_message).to start_with "Reapplying Draper::Decorator"
|
@@ -82,7 +82,7 @@ module Draper
|
|
82
82
|
|
83
83
|
it "decorates anyway" do
|
84
84
|
decorated = OtherDecorator.new(Decorator.new(Model.new))
|
85
|
-
Object.
|
85
|
+
allow_any_instance_of(Object).to receive(:warn)
|
86
86
|
redecorated = Decorator.decorate(decorated)
|
87
87
|
|
88
88
|
expect(redecorated.object).to be decorated
|
@@ -102,7 +102,7 @@ module Draper
|
|
102
102
|
|
103
103
|
describe ".decorate_collection" do
|
104
104
|
describe "options validation" do
|
105
|
-
before { CollectionDecorator.
|
105
|
+
before { allow(CollectionDecorator).to receive(:new) }
|
106
106
|
|
107
107
|
it "does not raise error on valid options" do
|
108
108
|
valid_options = {with: OtherDecorator, context: {}}
|
@@ -118,14 +118,14 @@ module Draper
|
|
118
118
|
it "creates a CollectionDecorator using itself for each item" do
|
119
119
|
object = [Model.new]
|
120
120
|
|
121
|
-
CollectionDecorator.
|
121
|
+
expect(CollectionDecorator).to receive(:new).with(object, with: Decorator)
|
122
122
|
Decorator.decorate_collection(object)
|
123
123
|
end
|
124
124
|
|
125
125
|
it "passes options to the collection decorator" do
|
126
126
|
options = {with: OtherDecorator, context: {some: "context"}}
|
127
127
|
|
128
|
-
CollectionDecorator.
|
128
|
+
expect(CollectionDecorator).to receive(:new).with([], options)
|
129
129
|
Decorator.decorate_collection([], options)
|
130
130
|
end
|
131
131
|
end
|
@@ -134,24 +134,17 @@ module Draper
|
|
134
134
|
it "creates a custom collection decorator using itself for each item" do
|
135
135
|
object = [Model.new]
|
136
136
|
|
137
|
-
ProductsDecorator.
|
137
|
+
expect(ProductsDecorator).to receive(:new).with(object, with: ProductDecorator)
|
138
138
|
ProductDecorator.decorate_collection(object)
|
139
139
|
end
|
140
140
|
|
141
141
|
it "passes options to the collection decorator" do
|
142
142
|
options = {with: OtherDecorator, context: {some: "context"}}
|
143
143
|
|
144
|
-
ProductsDecorator.
|
144
|
+
expect(ProductsDecorator).to receive(:new).with([], options)
|
145
145
|
ProductDecorator.decorate_collection([], options)
|
146
146
|
end
|
147
147
|
end
|
148
|
-
|
149
|
-
context "when a NameError is thrown" do
|
150
|
-
it "re-raises that error" do
|
151
|
-
String.any_instance.stub(:constantize) { Draper::DecoratedEnumerableProxy }
|
152
|
-
expect{ProductDecorator.decorate_collection([])}.to raise_error NameError, /Draper::DecoratedEnumerableProxy/
|
153
|
-
end
|
154
|
-
end
|
155
148
|
end
|
156
149
|
|
157
150
|
describe ".decorates" do
|
@@ -181,61 +174,67 @@ module Draper
|
|
181
174
|
protect_class Namespaced::ProductDecorator
|
182
175
|
|
183
176
|
context "when not set by .decorates" do
|
184
|
-
it "raises an
|
185
|
-
expect{Decorator.object_class}.to raise_error
|
177
|
+
it "raises an UninferrableObjectError for a so-named 'Decorator'" do
|
178
|
+
expect{Decorator.object_class}.to raise_error UninferrableObjectError
|
186
179
|
end
|
187
180
|
|
188
|
-
it "raises an
|
189
|
-
expect{Class.new(Decorator).object_class}.to raise_error
|
181
|
+
it "raises an UninferrableObjectError for anonymous decorators" do
|
182
|
+
expect{Class.new(Decorator).object_class}.to raise_error UninferrableObjectError
|
190
183
|
end
|
191
184
|
|
192
|
-
it "raises an
|
193
|
-
|
194
|
-
expect{
|
185
|
+
it "raises an UninferrableObjectError for a decorator without a model" do
|
186
|
+
SomeDecorator = Class.new(Draper::Decorator)
|
187
|
+
expect{SomeDecorator.object_class}.to raise_error UninferrableObjectError
|
195
188
|
end
|
196
189
|
|
197
|
-
it "raises an
|
198
|
-
|
190
|
+
it "raises an UninferrableObjectError for other naming conventions" do
|
191
|
+
ProductPresenter = Class.new(Draper::Decorator)
|
192
|
+
expect{ProductPresenter.object_class}.to raise_error UninferrableObjectError
|
199
193
|
end
|
200
194
|
|
201
|
-
it "infers the
|
195
|
+
it "infers the object class for '<Model>Decorator'" do
|
202
196
|
expect(ProductDecorator.object_class).to be Product
|
203
197
|
end
|
204
198
|
|
205
|
-
it "infers namespaced
|
199
|
+
it "infers the object class for namespaced decorators" do
|
206
200
|
expect(Namespaced::ProductDecorator.object_class).to be Namespaced::Product
|
207
201
|
end
|
208
202
|
|
209
203
|
context "when an unrelated NameError is thrown" do
|
210
204
|
it "re-raises that error" do
|
211
|
-
String.
|
205
|
+
allow_any_instance_of(String).to receive(:constantize) { SomethingThatDoesntExist }
|
212
206
|
expect{ProductDecorator.object_class}.to raise_error NameError, /SomethingThatDoesntExist/
|
213
207
|
end
|
214
208
|
end
|
215
209
|
end
|
216
|
-
|
217
|
-
it "is aliased to .source_class" do
|
218
|
-
expect(ProductDecorator.source_class).to be Product
|
219
|
-
end
|
220
210
|
end
|
221
211
|
|
222
212
|
describe ".object_class?" do
|
223
213
|
it "returns truthy when .object_class is set" do
|
224
|
-
Decorator.
|
214
|
+
allow(Decorator).to receive(:object_class).and_return(Model)
|
225
215
|
|
226
216
|
expect(Decorator.object_class?).to be_truthy
|
227
217
|
end
|
228
218
|
|
229
219
|
it "returns false when .object_class is not inferrable" do
|
230
|
-
Decorator.
|
220
|
+
allow(Decorator).to receive(:object_class).and_raise(UninferrableObjectError.new(Decorator))
|
231
221
|
|
232
222
|
expect(Decorator.object_class?).to be_falsey
|
233
223
|
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe '.collection_decorator_class' do
|
227
|
+
it 'defaults to CollectionDecorator' do
|
228
|
+
allow_any_instance_of(String).to receive(:constantize) { SomethingThatDoesntExist }
|
229
|
+
expect(ProductDecorator.collection_decorator_class).to be Draper::CollectionDecorator
|
230
|
+
end
|
234
231
|
|
235
|
-
it
|
236
|
-
|
232
|
+
it 'infers collection decorator based on name' do
|
233
|
+
expect(ProductDecorator.collection_decorator_class).to be ProductsDecorator
|
234
|
+
end
|
237
235
|
|
238
|
-
|
236
|
+
it 'infers collection decorator base on name for namespeced model' do
|
237
|
+
expect(Namespaced::ProductDecorator.collection_decorator_class).to be Namespaced::ProductsDecorator
|
239
238
|
end
|
240
239
|
end
|
241
240
|
|
@@ -243,7 +242,7 @@ module Draper
|
|
243
242
|
protect_class Decorator
|
244
243
|
|
245
244
|
describe "options validation" do
|
246
|
-
before { DecoratedAssociation.
|
245
|
+
before { allow(DecoratedAssociation).to receive(:new).and_return(->{}) }
|
247
246
|
|
248
247
|
it "does not raise error on valid options" do
|
249
248
|
valid_options = {with: Class, scope: :sorted, context: {}}
|
@@ -261,7 +260,7 @@ module Draper
|
|
261
260
|
Decorator.decorates_association :children, options
|
262
261
|
decorator = Decorator.new(Model.new)
|
263
262
|
|
264
|
-
DecoratedAssociation.
|
263
|
+
expect(DecoratedAssociation).to receive(:new).with(decorator, :children, options).and_return(->{})
|
265
264
|
decorator.children
|
266
265
|
end
|
267
266
|
|
@@ -269,7 +268,7 @@ module Draper
|
|
269
268
|
Decorator.decorates_association :children
|
270
269
|
decorator = Decorator.new(Model.new)
|
271
270
|
|
272
|
-
DecoratedAssociation.
|
271
|
+
expect(DecoratedAssociation).to receive(:new).once.and_return(->{})
|
273
272
|
decorator.children
|
274
273
|
decorator.children
|
275
274
|
end
|
@@ -278,9 +277,9 @@ module Draper
|
|
278
277
|
Decorator.decorates_association :children
|
279
278
|
decorator = Decorator.new(Model.new)
|
280
279
|
decorated_association = ->{}
|
281
|
-
DecoratedAssociation.
|
280
|
+
allow(DecoratedAssociation).to receive(:new).and_return(decorated_association)
|
282
281
|
|
283
|
-
decorated_association.
|
282
|
+
expect(decorated_association).to receive(:call).and_return(:decorated)
|
284
283
|
expect(decorator.children).to be :decorated
|
285
284
|
end
|
286
285
|
end
|
@@ -290,16 +289,16 @@ module Draper
|
|
290
289
|
protect_class Decorator
|
291
290
|
|
292
291
|
it "decorates each of the associations" do
|
293
|
-
Decorator.
|
294
|
-
Decorator.
|
292
|
+
expect(Decorator).to receive(:decorates_association).with(:friends, {})
|
293
|
+
expect(Decorator).to receive(:decorates_association).with(:enemies, {})
|
295
294
|
Decorator.decorates_associations :friends, :enemies
|
296
295
|
end
|
297
296
|
|
298
297
|
it "dispatches options" do
|
299
298
|
options = {with: Class.new, scope: :foo, context: {}}
|
300
299
|
|
301
|
-
Decorator.
|
302
|
-
Decorator.
|
300
|
+
expect(Decorator).to receive(:decorates_association).with(:friends, options)
|
301
|
+
expect(Decorator).to receive(:decorates_association).with(:enemies, options)
|
303
302
|
Decorator.decorates_associations :friends, :enemies, options
|
304
303
|
end
|
305
304
|
end
|
@@ -337,7 +336,6 @@ module Draper
|
|
337
336
|
|
338
337
|
expect(decorator.object).to be object
|
339
338
|
expect(decorator.model).to be object
|
340
|
-
expect(decorator.to_source).to be object
|
341
339
|
end
|
342
340
|
|
343
341
|
it "is aliased to #model" do
|
@@ -346,20 +344,6 @@ module Draper
|
|
346
344
|
|
347
345
|
expect(decorator.model).to be object
|
348
346
|
end
|
349
|
-
|
350
|
-
it "is aliased to #source" do
|
351
|
-
object = Model.new
|
352
|
-
decorator = Decorator.new(object)
|
353
|
-
|
354
|
-
expect(decorator.source).to be object
|
355
|
-
end
|
356
|
-
|
357
|
-
it "is aliased to #to_source" do
|
358
|
-
object = Model.new
|
359
|
-
decorator = Decorator.new(object)
|
360
|
-
|
361
|
-
expect(decorator.to_source).to be object
|
362
|
-
end
|
363
347
|
end
|
364
348
|
|
365
349
|
describe "aliasing object to object class name" do
|
@@ -480,15 +464,15 @@ module Draper
|
|
480
464
|
describe "#attributes" do
|
481
465
|
it "returns only the object's attributes that are implemented by the decorator" do
|
482
466
|
decorator = Decorator.new(double(attributes: {foo: "bar", baz: "qux"}))
|
483
|
-
decorator.
|
467
|
+
allow(decorator).to receive(:foo)
|
484
468
|
|
485
469
|
expect(decorator.attributes).to eq({foo: "bar"})
|
486
470
|
end
|
487
471
|
end
|
488
472
|
|
489
473
|
describe ".model_name" do
|
490
|
-
it "delegates to the
|
491
|
-
Decorator.
|
474
|
+
it "delegates to the object class" do
|
475
|
+
allow(Decorator).to receive(:object_class).and_return(double(model_name: :delegated))
|
492
476
|
|
493
477
|
expect(Decorator.model_name).to be :delegated
|
494
478
|
end
|
@@ -514,7 +498,7 @@ module Draper
|
|
514
498
|
decorator = Decorator.new(object)
|
515
499
|
other = double(object: Model.new)
|
516
500
|
|
517
|
-
object.
|
501
|
+
expect(object).to receive(:==).with(other).and_return(true)
|
518
502
|
expect(decorator == other).to be_truthy
|
519
503
|
end
|
520
504
|
|
@@ -523,7 +507,7 @@ module Draper
|
|
523
507
|
decorator = Decorator.new(object)
|
524
508
|
other = double(object: Model.new)
|
525
509
|
|
526
|
-
object.
|
510
|
+
expect(object).to receive(:==).with(other).and_return(false)
|
527
511
|
expect(decorator == other).to be_falsey
|
528
512
|
end
|
529
513
|
end
|
@@ -538,7 +522,7 @@ module Draper
|
|
538
522
|
|
539
523
|
it "is false when #== is false" do
|
540
524
|
decorator = Decorator.new(Model.new)
|
541
|
-
decorator.
|
525
|
+
allow(decorator).to receive(:==).with(:anything).and_return(false)
|
542
526
|
|
543
527
|
expect(decorator === :anything).to be_falsey
|
544
528
|
end
|
@@ -574,12 +558,12 @@ module Draper
|
|
574
558
|
protect_class Decorator
|
575
559
|
|
576
560
|
it "defaults the :to option to :object" do
|
577
|
-
Object.
|
561
|
+
expect(Object).to receive(:delegate).with(:foo, :bar, to: :object)
|
578
562
|
Decorator.delegate :foo, :bar
|
579
563
|
end
|
580
564
|
|
581
565
|
it "does not overwrite the :to option if supplied" do
|
582
|
-
Object.
|
566
|
+
expect(Object).to receive(:delegate).with(:foo, :bar, to: :baz)
|
583
567
|
Decorator.delegate :foo, :bar, to: :baz
|
584
568
|
end
|
585
569
|
end
|
@@ -596,12 +580,43 @@ module Draper
|
|
596
580
|
expect(decorator.hello_world).to be :delegated
|
597
581
|
end
|
598
582
|
|
599
|
-
it
|
600
|
-
|
583
|
+
it 'delegates `super` to parent class first' do
|
584
|
+
parent_decorator_class = Class.new(Decorator) do
|
585
|
+
def hello_world
|
586
|
+
"parent#hello_world"
|
587
|
+
end
|
588
|
+
end
|
601
589
|
|
602
|
-
|
603
|
-
|
604
|
-
|
590
|
+
child_decorator_class = Class.new(parent_decorator_class) do
|
591
|
+
def hello_world
|
592
|
+
super
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
decorator = child_decorator_class.new(double(hello_world: 'object#hello_world'))
|
597
|
+
expect(decorator.hello_world).to eq 'parent#hello_world'
|
598
|
+
end
|
599
|
+
|
600
|
+
it 'delegates `super` to object if method does not exist on parent class' do
|
601
|
+
decorator_class = Class.new(Decorator) do
|
602
|
+
def hello_world
|
603
|
+
super
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
decorator = decorator_class.new(double(hello_world: 'object#hello_world'))
|
608
|
+
expect(decorator.hello_world).to eq 'object#hello_world'
|
609
|
+
end
|
610
|
+
|
611
|
+
it 'raises `NoMethodError` when `super` is called on for method that does not exist' do
|
612
|
+
decorator_class = Class.new(Decorator) do
|
613
|
+
def hello_world
|
614
|
+
super
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
decorator = decorator_class.new(double)
|
619
|
+
expect{decorator.hello_world}.to raise_error NoMethodError
|
605
620
|
end
|
606
621
|
|
607
622
|
it "allows decorator to decorate different classes of objects" do
|
@@ -614,7 +629,7 @@ module Draper
|
|
614
629
|
|
615
630
|
it "passes blocks to delegated methods" do
|
616
631
|
object = Model.new
|
617
|
-
object.
|
632
|
+
allow(object).to receive(:hello_world) { |*args, &block| block.call }
|
618
633
|
decorator = Decorator.new(object)
|
619
634
|
|
620
635
|
expect(decorator.hello_world{:yielded}).to be :yielded
|
@@ -628,7 +643,7 @@ module Draper
|
|
628
643
|
|
629
644
|
it "delegates already-delegated methods" do
|
630
645
|
object = Class.new{ delegate :bar, to: :foo }.new
|
631
|
-
object.
|
646
|
+
allow(object).to receive_messages foo: double(bar: :delegated)
|
632
647
|
decorator = Decorator.new(object)
|
633
648
|
|
634
649
|
expect(decorator.bar).to be :delegated
|
@@ -651,23 +666,23 @@ module Draper
|
|
651
666
|
end
|
652
667
|
|
653
668
|
context ".method_missing" do
|
654
|
-
context "without
|
669
|
+
context "without an object class" do
|
655
670
|
it "raises a NoMethodError on missing methods" do
|
656
671
|
expect{Decorator.hello_world}.to raise_error NoMethodError
|
657
672
|
end
|
658
673
|
end
|
659
674
|
|
660
|
-
context "with
|
661
|
-
it "delegates methods that exist on the
|
675
|
+
context "with an object class" do
|
676
|
+
it "delegates methods that exist on the object class" do
|
662
677
|
object_class = Class.new
|
663
|
-
object_class.
|
664
|
-
Decorator.
|
678
|
+
allow(object_class).to receive_messages hello_world: :delegated
|
679
|
+
allow(Decorator).to receive_messages object_class: object_class
|
665
680
|
|
666
681
|
expect(Decorator.hello_world).to be :delegated
|
667
682
|
end
|
668
683
|
|
669
|
-
it "does not delegate methods that do not exist on the
|
670
|
-
Decorator.
|
684
|
+
it "does not delegate methods that do not exist on the object class" do
|
685
|
+
allow(Decorator).to receive_messages object_class: Class.new
|
671
686
|
|
672
687
|
expect{Decorator.hello_world}.to raise_error NoMethodError
|
673
688
|
end
|
@@ -706,7 +721,7 @@ module Draper
|
|
706
721
|
end
|
707
722
|
|
708
723
|
describe ".respond_to?" do
|
709
|
-
context "without a
|
724
|
+
context "without a object class" do
|
710
725
|
it "returns true for its own class methods" do
|
711
726
|
Decorator.class_eval{def self.hello_world; end}
|
712
727
|
|
@@ -718,16 +733,16 @@ module Draper
|
|
718
733
|
end
|
719
734
|
end
|
720
735
|
|
721
|
-
context "with a
|
736
|
+
context "with a object class" do
|
722
737
|
it "returns true for its own class methods" do
|
723
738
|
Decorator.class_eval{def self.hello_world; end}
|
724
|
-
Decorator.
|
739
|
+
allow(Decorator).to receive_messages object_class: Class.new
|
725
740
|
|
726
741
|
expect(Decorator).to respond_to :hello_world
|
727
742
|
end
|
728
743
|
|
729
|
-
it "returns true for the
|
730
|
-
Decorator.
|
744
|
+
it "returns true for the object's class methods" do
|
745
|
+
allow(Decorator).to receive_messages object_class: double(hello_world: :delegated)
|
731
746
|
|
732
747
|
expect(Decorator).to respond_to :hello_world
|
733
748
|
end
|
@@ -745,7 +760,7 @@ module Draper
|
|
745
760
|
|
746
761
|
describe ".respond_to_missing?" do
|
747
762
|
it "allows .method to be called on delegated class methods" do
|
748
|
-
Decorator.
|
763
|
+
allow(Decorator).to receive_messages object_class: double(hello_world: :delegated)
|
749
764
|
|
750
765
|
expect(Decorator.method(:hello_world)).not_to be_nil
|
751
766
|
end
|
@@ -753,7 +768,7 @@ module Draper
|
|
753
768
|
end
|
754
769
|
|
755
770
|
describe "class spoofing" do
|
756
|
-
it "pretends to be a kind of the
|
771
|
+
it "pretends to be a kind of the object class" do
|
757
772
|
decorator = Decorator.new(Model.new)
|
758
773
|
|
759
774
|
expect(decorator.kind_of?(Model)).to be_truthy
|
@@ -767,7 +782,7 @@ module Draper
|
|
767
782
|
expect(decorator.is_a?(Decorator)).to be_truthy
|
768
783
|
end
|
769
784
|
|
770
|
-
it "pretends to be an instance of the
|
785
|
+
it "pretends to be an instance of the object class" do
|
771
786
|
decorator = Decorator.new(Model.new)
|
772
787
|
|
773
788
|
expect(decorator.instance_of?(Model)).to be_truthy
|