1
1
# frozen_string_literal: true
2
2
3
- module Grape
4
- module DSL
5
- module InsideRouteSpec
6
- class Dummy
7
- include Grape :: DSL :: InsideRoute
8
-
9
- attr_reader :env , :request , :new_settings
10
-
11
- def initialize
12
- @env = { }
13
- @header = { }
14
- @new_settings = { namespace_inheritable : { } , namespace_stackable : { } }
15
- end
3
+ describe Grape :: Endpoint do
4
+ subject { dummy_class . new }
5
+
6
+ let ( :dummy_class ) do
7
+ Class . new do
8
+ include Grape :: DSL :: InsideRoute
9
+
10
+ attr_reader :env , :request , :new_settings
11
+
12
+ def initialize
13
+ @env = { }
14
+ @header = { }
15
+ @new_settings = { namespace_inheritable : { } , namespace_stackable : { } }
16
16
end
17
17
end
18
18
end
19
- end
20
-
21
- describe Grape ::Endpoint do
22
- subject { Grape ::DSL ::InsideRouteSpec ::Dummy . new }
23
19
24
20
describe '#version' do
25
21
it 'defaults to nil' do
@@ -202,38 +198,6 @@ def initialize
202
198
end
203
199
end
204
200
205
- describe '#file' do
206
- describe 'set' do
207
- context 'as file path' do
208
- let ( :file_path ) { '/some/file/path' }
209
-
210
- it 'emits a warning that this method is deprecated' do
211
- expect ( Grape . deprecator ) . to receive ( :warn ) . with ( /Use sendfile or stream/ )
212
- expect ( subject ) . to receive ( :sendfile ) . with ( file_path )
213
- subject . file file_path
214
- end
215
- end
216
-
217
- context 'as object (backward compatibility)' do
218
- let ( :file_object ) { double ( 'StreamerObject' , each : nil ) }
219
-
220
- it 'emits a warning that this method is deprecated' do
221
- expect ( Grape . deprecator ) . to receive ( :warn ) . with ( /Use stream to use a Stream object/ )
222
- expect ( subject ) . to receive ( :stream ) . with ( file_object )
223
- subject . file file_object
224
- end
225
- end
226
- end
227
-
228
- describe 'get' do
229
- it 'emits a warning that this method is deprecated' do
230
- expect ( Grape . deprecator ) . to receive ( :warn ) . with ( /Use sendfile or stream/ )
231
- expect ( subject ) . to receive ( :sendfile )
232
- subject . file
233
- end
234
- end
235
- end
236
-
237
201
describe '#sendfile' do
238
202
describe 'set' do
239
203
context 'as file path' do
@@ -248,36 +212,19 @@ def initialize
248
212
subject . header Rack ::CACHE_CONTROL , 'cache'
249
213
subject . header Rack ::CONTENT_LENGTH , 123
250
214
subject . header Grape ::Http ::Headers ::TRANSFER_ENCODING , 'base64'
251
- end
252
-
253
- it 'sends no deprecation warnings' do
254
- expect ( Grape . deprecator ) . not_to receive ( :warn )
255
-
256
215
subject . sendfile file_path
257
216
end
258
217
259
218
it 'returns value wrapped in StreamResponse' do
260
- subject . sendfile file_path
261
-
262
219
expect ( subject . sendfile ) . to eq file_response
263
220
end
264
221
265
- it 'does not change the Cache-Control header' do
266
- subject . sendfile file_path
267
-
268
- expect ( subject . header [ Rack ::CACHE_CONTROL ] ) . to eq 'cache'
269
- end
270
-
271
- it 'does not change the Content-Length header' do
272
- subject . sendfile file_path
273
-
274
- expect ( subject . header [ Rack ::CONTENT_LENGTH ] ) . to eq 123
275
- end
276
-
277
- it 'does not change the Transfer-Encoding header' do
278
- subject . sendfile file_path
279
-
280
- expect ( subject . header [ Grape ::Http ::Headers ::TRANSFER_ENCODING ] ) . to eq 'base64'
222
+ it 'set the correct headers' do
223
+ expect ( subject . header ) . to match (
224
+ Rack ::CACHE_CONTROL => 'cache' ,
225
+ Rack ::CONTENT_LENGTH => 123 ,
226
+ Grape ::Http ::Headers ::TRANSFER_ENCODING => 'base64'
227
+ )
281
228
end
282
229
end
283
230
@@ -309,42 +256,15 @@ def initialize
309
256
subject . header Rack ::CACHE_CONTROL , 'cache'
310
257
subject . header Rack ::CONTENT_LENGTH , 123
311
258
subject . header Grape ::Http ::Headers ::TRANSFER_ENCODING , 'base64'
312
- end
313
-
314
- it 'emits no deprecation warnings' do
315
- expect ( Grape . deprecator ) . not_to receive ( :warn )
316
-
317
259
subject . stream file_path
318
260
end
319
261
320
262
it 'returns file body wrapped in StreamResponse' do
321
- subject . stream file_path
322
-
323
263
expect ( subject . stream ) . to eq file_response
324
264
end
325
265
326
- it 'sets Cache-Control header to no-cache' do
327
- subject . stream file_path
328
-
329
- expect ( subject . header [ Rack ::CACHE_CONTROL ] ) . to eq 'no-cache'
330
- end
331
-
332
- it 'does not change Cache-Control header' do
333
- subject . stream
334
-
335
- expect ( subject . header [ Rack ::CACHE_CONTROL ] ) . to eq 'cache'
336
- end
337
-
338
- it 'sets Content-Length header to nil' do
339
- subject . stream file_path
340
-
341
- expect ( subject . header [ Rack ::CONTENT_LENGTH ] ) . to be_nil
342
- end
343
-
344
- it 'sets Transfer-Encoding header to nil' do
345
- subject . stream file_path
346
-
347
- expect ( subject . header [ Grape ::Http ::Headers ::TRANSFER_ENCODING ] ) . to be_nil
266
+ it 'sets only the cache-control header' do
267
+ expect ( subject . header ) . to match ( Rack ::CACHE_CONTROL => 'no-cache' )
348
268
end
349
269
end
350
270
@@ -359,36 +279,15 @@ def initialize
359
279
subject . header Rack ::CACHE_CONTROL , 'cache'
360
280
subject . header Rack ::CONTENT_LENGTH , 123
361
281
subject . header Grape ::Http ::Headers ::TRANSFER_ENCODING , 'base64'
362
- end
363
-
364
- it 'emits no deprecation warnings' do
365
- expect ( Grape . deprecator ) . not_to receive ( :warn )
366
-
367
282
subject . stream stream_object
368
283
end
369
284
370
285
it 'returns value wrapped in StreamResponse' do
371
- subject . stream stream_object
372
-
373
286
expect ( subject . stream ) . to eq stream_response
374
287
end
375
288
376
- it 'sets Cache-Control header to no-cache' do
377
- subject . stream stream_object
378
-
379
- expect ( subject . header [ Rack ::CACHE_CONTROL ] ) . to eq 'no-cache'
380
- end
381
-
382
- it 'sets Content-Length header to nil' do
383
- subject . stream stream_object
384
-
385
- expect ( subject . header [ Rack ::CONTENT_LENGTH ] ) . to be_nil
386
- end
387
-
388
- it 'sets Transfer-Encoding header to nil' do
389
- subject . stream stream_object
390
-
391
- expect ( subject . header [ Grape ::Http ::Headers ::TRANSFER_ENCODING ] ) . to be_nil
289
+ it 'set only the cache-control header' do
290
+ expect ( subject . header ) . to match ( Rack ::CACHE_CONTROL => 'no-cache' )
392
291
end
393
292
end
394
293
@@ -403,7 +302,7 @@ def initialize
403
302
404
303
it 'returns default' do
405
304
expect ( subject . stream ) . to be_nil
406
- expect ( subject . header [ Rack :: CACHE_CONTROL ] ) . to be_nil
305
+ expect ( subject . header ) . to be_empty
407
306
end
408
307
end
409
308
0 commit comments