@@ -34,7 +34,7 @@ module Draper
34
34
factory = Factory . new
35
35
object = double
36
36
37
- expect ( Factory ::Worker ) . to receive ( :new ) . with ( anything ( ) , object ) . and_return ( -> ( *) { } )
37
+ expect ( Factory ::Worker ) . to receive ( :new ) . with ( anything ( ) , object , anything ( ) ) . and_return ( -> ( *) { } )
38
38
factory . decorate ( object )
39
39
end
40
40
@@ -43,7 +43,7 @@ module Draper
43
43
decorator_class = double
44
44
factory = Factory . new ( with : decorator_class )
45
45
46
- expect ( Factory ::Worker ) . to receive ( :new ) . with ( decorator_class , anything ( ) ) . and_return ( -> ( *) { } )
46
+ expect ( Factory ::Worker ) . to receive ( :new ) . with ( decorator_class , anything ( ) , anything ( ) ) . and_return ( -> ( *) { } )
47
47
factory . decorate ( double )
48
48
end
49
49
end
@@ -52,7 +52,7 @@ module Draper
52
52
it "passes nil to the worker" do
53
53
factory = Factory . new
54
54
55
- expect ( Factory ::Worker ) . to receive ( :new ) . with ( nil , anything ( ) ) . and_return ( -> ( *) { } )
55
+ expect ( Factory ::Worker ) . to receive ( :new ) . with ( nil , anything ( ) , anything ( ) ) . and_return ( -> ( *) { } )
56
56
factory . decorate ( double )
57
57
end
58
58
end
@@ -94,7 +94,7 @@ module Draper
94
94
it "calls the decorator method" do
95
95
object = double
96
96
options = { foo : "bar" }
97
- worker = Factory ::Worker . new ( double , object )
97
+ worker = Factory ::Worker . new ( double , object , nil )
98
98
decorator = -> ( *) { }
99
99
allow ( worker ) . to receive ( :decorator ) { decorator }
100
100
@@ -104,7 +104,7 @@ module Draper
104
104
105
105
context "when the :context option is callable" do
106
106
it "calls it" do
107
- worker = Factory ::Worker . new ( double , double )
107
+ worker = Factory ::Worker . new ( double , double , nil )
108
108
decorator = -> ( *) { }
109
109
allow ( worker ) . to receive_messages decorator : decorator
110
110
context = { foo : "bar" }
@@ -114,7 +114,7 @@ module Draper
114
114
end
115
115
116
116
it "receives arguments from the :context_args option" do
117
- worker = Factory ::Worker . new ( double , double )
117
+ worker = Factory ::Worker . new ( double , double , nil )
118
118
allow ( worker ) . to receive_messages decorator : -> ( *) { }
119
119
context = -> { }
120
120
@@ -123,7 +123,7 @@ module Draper
123
123
end
124
124
125
125
it "wraps non-arrays passed to :context_args" do
126
- worker = Factory ::Worker . new ( double , double )
126
+ worker = Factory ::Worker . new ( double , double , nil )
127
127
allow ( worker ) . to receive_messages decorator : -> ( *) { }
128
128
context = -> { }
129
129
hash = { foo : "bar" }
@@ -135,7 +135,7 @@ module Draper
135
135
136
136
context "when the :context option is not callable" do
137
137
it "doesn't call it" do
138
- worker = Factory ::Worker . new ( double , double )
138
+ worker = Factory ::Worker . new ( double , double , nil )
139
139
decorator = -> ( *) { }
140
140
allow ( worker ) . to receive_messages decorator : decorator
141
141
context = { foo : "bar" }
@@ -146,7 +146,7 @@ module Draper
146
146
end
147
147
148
148
it "does not pass the :context_args option to the decorator" do
149
- worker = Factory ::Worker . new ( double , double )
149
+ worker = Factory ::Worker . new ( double , double , nil )
150
150
decorator = -> ( *) { }
151
151
allow ( worker ) . to receive_messages decorator : decorator
152
152
@@ -160,7 +160,7 @@ module Draper
160
160
context "when decorator_class is specified" do
161
161
it "returns the .decorate method from the decorator" do
162
162
decorator_class = Class . new ( Decorator )
163
- worker = Factory ::Worker . new ( decorator_class , double )
163
+ worker = Factory ::Worker . new ( decorator_class , double , nil )
164
164
165
165
expect ( worker . decorator ) . to eq decorator_class . method ( :decorate )
166
166
end
@@ -171,17 +171,17 @@ module Draper
171
171
it "returns the object's #decorate method" do
172
172
object = double
173
173
options = { foo : "bar" }
174
- worker = Factory ::Worker . new ( nil , object )
174
+ worker = Factory ::Worker . new ( nil , object , nil )
175
175
176
- expect ( object ) . to receive ( :decorate ) . with ( options ) . and_return ( :decorated )
176
+ expect ( object ) . to receive ( :decorate ) . with ( options . merge ( namespace : nil ) ) . and_return ( :decorated )
177
177
expect ( worker . decorator . call ( object , options ) ) . to be :decorated
178
178
end
179
179
end
180
180
181
181
context "and the object is not decoratable" do
182
182
it "raises an error" do
183
183
object = double
184
- worker = Factory ::Worker . new ( nil , object )
184
+ worker = Factory ::Worker . new ( nil , object , nil )
185
185
186
186
expect { worker . decorator } . to raise_error UninferrableDecoratorError
187
187
end
@@ -193,7 +193,7 @@ module Draper
193
193
object = Struct . new ( :stuff ) . new ( "things" )
194
194
195
195
decorator_class = Class . new ( Decorator )
196
- worker = Factory ::Worker . new ( decorator_class , object )
196
+ worker = Factory ::Worker . new ( decorator_class , object , nil )
197
197
198
198
expect ( worker . decorator ) . to eq decorator_class . method ( :decorate )
199
199
end
@@ -204,7 +204,7 @@ module Draper
204
204
context "when decorator_class is a CollectionDecorator" do
205
205
it "returns the .decorate method from the collection decorator" do
206
206
decorator_class = Class . new ( CollectionDecorator )
207
- worker = Factory ::Worker . new ( decorator_class , [ ] )
207
+ worker = Factory ::Worker . new ( decorator_class , [ ] , nil )
208
208
209
209
expect ( worker . decorator ) . to eq decorator_class . method ( :decorate )
210
210
end
@@ -213,7 +213,7 @@ module Draper
213
213
context "when decorator_class is a Decorator" do
214
214
it "returns the .decorate_collection method from the decorator" do
215
215
decorator_class = Class . new ( Decorator )
216
- worker = Factory ::Worker . new ( decorator_class , [ ] )
216
+ worker = Factory ::Worker . new ( decorator_class , [ ] , nil )
217
217
218
218
expect ( worker . decorator ) . to eq decorator_class . method ( :decorate_collection )
219
219
end
@@ -226,7 +226,7 @@ module Draper
226
226
decorator_class = Class . new ( Decorator )
227
227
allow ( object ) . to receive ( :decorator_class ) { decorator_class }
228
228
allow ( object ) . to receive ( :decorate ) { nil }
229
- worker = Factory ::Worker . new ( nil , object )
229
+ worker = Factory ::Worker . new ( nil , object , nil )
230
230
231
231
expect ( decorator_class ) . to receive ( :decorate_collection ) . with ( object , { foo : "bar" , with : nil } ) . and_return ( :decorated )
232
232
expect ( worker . decorator . call ( object , foo : "bar" ) ) . to be :decorated
@@ -235,7 +235,7 @@ module Draper
235
235
236
236
context "and the object is not decoratable" do
237
237
it "returns the .decorate method from CollectionDecorator" do
238
- worker = Factory ::Worker . new ( nil , [ ] )
238
+ worker = Factory ::Worker . new ( nil , [ ] , nil )
239
239
240
240
expect ( worker . decorator ) . to eq CollectionDecorator . method ( :decorate )
241
241
end
0 commit comments