grape 1.3.3 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +111 -2
- data/CONTRIBUTING.md +2 -1
- data/README.md +135 -23
- data/UPGRADING.md +237 -46
- data/grape.gemspec +5 -5
- data/lib/grape/api/instance.rb +34 -42
- data/lib/grape/api.rb +21 -16
- data/lib/grape/cookies.rb +2 -0
- data/lib/grape/dsl/callbacks.rb +1 -1
- data/lib/grape/dsl/desc.rb +3 -5
- data/lib/grape/dsl/headers.rb +5 -2
- data/lib/grape/dsl/helpers.rb +8 -5
- data/lib/grape/dsl/inside_route.rb +72 -53
- data/lib/grape/dsl/middleware.rb +4 -4
- data/lib/grape/dsl/parameters.rb +11 -7
- data/lib/grape/dsl/request_response.rb +9 -6
- data/lib/grape/dsl/routing.rb +8 -9
- data/lib/grape/dsl/settings.rb +5 -5
- data/lib/grape/dsl/validations.rb +18 -1
- data/lib/grape/eager_load.rb +1 -1
- data/lib/grape/endpoint.rb +29 -42
- data/lib/grape/error_formatter/json.rb +2 -6
- data/lib/grape/error_formatter/xml.rb +2 -6
- data/lib/grape/exceptions/empty_message_body.rb +11 -0
- data/lib/grape/exceptions/validation.rb +2 -3
- data/lib/grape/exceptions/validation_errors.rb +1 -1
- data/lib/grape/formatter/json.rb +1 -0
- data/lib/grape/formatter/serializable_hash.rb +2 -1
- data/lib/grape/formatter/xml.rb +1 -0
- data/lib/grape/locale/en.yml +1 -1
- data/lib/grape/middleware/auth/base.rb +3 -3
- data/lib/grape/middleware/auth/dsl.rb +7 -1
- data/lib/grape/middleware/base.rb +6 -3
- data/lib/grape/middleware/error.rb +11 -13
- data/lib/grape/middleware/formatter.rb +7 -7
- data/lib/grape/middleware/stack.rb +10 -3
- data/lib/grape/middleware/versioner/accept_version_header.rb +3 -5
- data/lib/grape/middleware/versioner/header.rb +6 -4
- data/lib/grape/middleware/versioner/param.rb +1 -0
- data/lib/grape/middleware/versioner/parse_media_type_patch.rb +2 -1
- data/lib/grape/middleware/versioner/path.rb +2 -0
- data/lib/grape/parser/json.rb +1 -1
- data/lib/grape/parser/xml.rb +1 -1
- data/lib/grape/path.rb +1 -0
- data/lib/grape/request.rb +4 -1
- data/lib/grape/router/attribute_translator.rb +3 -3
- data/lib/grape/router/pattern.rb +1 -1
- data/lib/grape/router/route.rb +2 -2
- data/lib/grape/router.rb +31 -30
- data/lib/grape/{serve_file → serve_stream}/file_body.rb +1 -1
- data/lib/grape/{serve_file → serve_stream}/sendfile_response.rb +1 -1
- data/lib/grape/{serve_file/file_response.rb → serve_stream/stream_response.rb} +8 -8
- data/lib/grape/util/base_inheritable.rb +2 -2
- data/lib/grape/util/inheritable_setting.rb +1 -3
- data/lib/grape/util/lazy_value.rb +4 -2
- data/lib/grape/util/strict_hash_configuration.rb +1 -1
- data/lib/grape/validations/attributes_iterator.rb +8 -0
- data/lib/grape/validations/multiple_attributes_iterator.rb +1 -1
- data/lib/grape/validations/params_scope.rb +97 -62
- data/lib/grape/validations/single_attribute_iterator.rb +1 -1
- data/lib/grape/validations/types/custom_type_coercer.rb +16 -3
- data/lib/grape/validations/types/dry_type_coercer.rb +1 -1
- data/lib/grape/validations/types/invalid_value.rb +24 -0
- data/lib/grape/validations/types/json.rb +2 -1
- data/lib/grape/validations/types/primitive_coercer.rb +4 -5
- data/lib/grape/validations/types.rb +1 -4
- data/lib/grape/validations/validator_factory.rb +1 -1
- data/lib/grape/validations/validators/all_or_none.rb +8 -5
- data/lib/grape/validations/validators/allow_blank.rb +9 -7
- data/lib/grape/validations/validators/as.rb +6 -8
- data/lib/grape/validations/validators/at_least_one_of.rb +7 -4
- data/lib/grape/validations/validators/base.rb +74 -69
- data/lib/grape/validations/validators/coerce.rb +63 -76
- data/lib/grape/validations/validators/default.rb +36 -34
- data/lib/grape/validations/validators/exactly_one_of.rb +9 -6
- data/lib/grape/validations/validators/except_values.rb +13 -11
- data/lib/grape/validations/validators/multiple_params_base.rb +24 -19
- data/lib/grape/validations/validators/mutual_exclusion.rb +8 -5
- data/lib/grape/validations/validators/presence.rb +7 -4
- data/lib/grape/validations/validators/regexp.rb +8 -5
- data/lib/grape/validations/validators/same_as.rb +18 -15
- data/lib/grape/validations/validators/values.rb +61 -56
- data/lib/grape/validations.rb +6 -0
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +7 -3
- data/spec/grape/api/custom_validations_spec.rb +77 -45
- data/spec/grape/api/deeply_included_options_spec.rb +3 -3
- data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -1
- data/spec/grape/api/invalid_format_spec.rb +2 -0
- data/spec/grape/api/recognize_path_spec.rb +1 -1
- data/spec/grape/api/routes_with_requirements_spec.rb +8 -8
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -15
- data/spec/grape/api_remount_spec.rb +25 -19
- data/spec/grape/api_spec.rb +576 -211
- data/spec/grape/dsl/callbacks_spec.rb +2 -1
- data/spec/grape/dsl/headers_spec.rb +39 -9
- data/spec/grape/dsl/helpers_spec.rb +3 -2
- data/spec/grape/dsl/inside_route_spec.rb +185 -34
- data/spec/grape/dsl/logger_spec.rb +16 -18
- data/spec/grape/dsl/middleware_spec.rb +2 -1
- data/spec/grape/dsl/parameters_spec.rb +2 -0
- data/spec/grape/dsl/request_response_spec.rb +1 -0
- data/spec/grape/dsl/routing_spec.rb +10 -7
- data/spec/grape/endpoint/declared_spec.rb +848 -0
- data/spec/grape/endpoint_spec.rb +77 -589
- data/spec/grape/entity_spec.rb +29 -23
- data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -0
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +61 -22
- data/spec/grape/exceptions/validation_errors_spec.rb +13 -10
- data/spec/grape/exceptions/validation_spec.rb +5 -3
- data/spec/grape/extensions/param_builders/hash_spec.rb +7 -7
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -8
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -8
- data/spec/grape/integration/rack_sendfile_spec.rb +13 -9
- data/spec/grape/loading_spec.rb +8 -8
- data/spec/grape/middleware/auth/dsl_spec.rb +15 -6
- data/spec/grape/middleware/auth/strategies_spec.rb +61 -21
- data/spec/grape/middleware/base_spec.rb +24 -15
- data/spec/grape/middleware/error_spec.rb +3 -3
- data/spec/grape/middleware/exception_spec.rb +111 -161
- data/spec/grape/middleware/formatter_spec.rb +28 -7
- data/spec/grape/middleware/globals_spec.rb +7 -4
- data/spec/grape/middleware/stack_spec.rb +15 -12
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -1
- data/spec/grape/middleware/versioner/header_spec.rb +14 -13
- data/spec/grape/middleware/versioner/param_spec.rb +7 -1
- data/spec/grape/middleware/versioner/path_spec.rb +5 -1
- data/spec/grape/middleware/versioner_spec.rb +1 -1
- data/spec/grape/parser_spec.rb +4 -0
- data/spec/grape/path_spec.rb +52 -52
- data/spec/grape/presenters/presenter_spec.rb +7 -6
- data/spec/grape/request_spec.rb +6 -4
- data/spec/grape/util/inheritable_setting_spec.rb +7 -7
- data/spec/grape/util/inheritable_values_spec.rb +3 -2
- data/spec/grape/util/reverse_stackable_values_spec.rb +3 -1
- data/spec/grape/util/stackable_values_spec.rb +7 -5
- data/spec/grape/validations/instance_behaivour_spec.rb +9 -10
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +14 -3
- data/spec/grape/validations/params_scope_spec.rb +72 -10
- data/spec/grape/validations/single_attribute_iterator_spec.rb +18 -6
- data/spec/grape/validations/types/primitive_coercer_spec.rb +63 -7
- data/spec/grape/validations/types_spec.rb +8 -8
- data/spec/grape/validations/validators/all_or_none_spec.rb +50 -56
- data/spec/grape/validations/validators/allow_blank_spec.rb +136 -140
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -56
- data/spec/grape/validations/validators/coerce_spec.rb +248 -33
- data/spec/grape/validations/validators/default_spec.rb +121 -78
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -77
- data/spec/grape/validations/validators/except_values_spec.rb +4 -3
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -77
- data/spec/grape/validations/validators/presence_spec.rb +16 -1
- data/spec/grape/validations/validators/regexp_spec.rb +25 -31
- data/spec/grape/validations/validators/same_as_spec.rb +14 -20
- data/spec/grape/validations/validators/values_spec.rb +183 -178
- data/spec/grape/validations_spec.rb +342 -29
- data/spec/integration/eager_load/eager_load_spec.rb +15 -0
- data/spec/integration/multi_json/json_spec.rb +1 -1
- data/spec/integration/multi_xml/xml_spec.rb +1 -1
- data/spec/shared/versioning_examples.rb +32 -29
- data/spec/spec_helper.rb +12 -12
- data/spec/support/basic_auth_encode_helpers.rb +1 -1
- data/spec/support/chunks.rb +14 -0
- data/spec/support/versioned_helpers.rb +4 -6
- metadata +110 -102
@@ -12,21 +12,51 @@ module Grape
|
|
12
12
|
describe Headers do
|
13
13
|
subject { HeadersSpec::Dummy.new }
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
let(:header_data) do
|
16
|
+
{ 'First Key' => 'First Value',
|
17
|
+
'Second Key' => 'Second Value' }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when headers are set' do
|
21
|
+
describe '#header' do
|
17
22
|
before do
|
18
|
-
subject.header
|
23
|
+
header_data.each { |k, v| subject.header(k, v) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'get' do
|
27
|
+
it 'returns a specifc value' do
|
28
|
+
expect(subject.header['First Key']).to eq 'First Value'
|
29
|
+
expect(subject.header['Second Key']).to eq 'Second Value'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns all set headers' do
|
33
|
+
expect(subject.header).to eq header_data
|
34
|
+
expect(subject.headers).to eq header_data
|
35
|
+
end
|
19
36
|
end
|
20
37
|
|
21
|
-
|
22
|
-
|
23
|
-
|
38
|
+
describe 'set' do
|
39
|
+
it 'returns value' do
|
40
|
+
expect(subject.header('Third Key', 'Third Value'))
|
41
|
+
expect(subject.header['Third Key']).to eq 'Third Value'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'delete' do
|
46
|
+
it 'deletes a header key-value pair' do
|
47
|
+
expect(subject.header('First Key')).to eq header_data['First Key']
|
48
|
+
expect(subject.header).not_to have_key('First Key')
|
49
|
+
end
|
24
50
|
end
|
25
51
|
end
|
52
|
+
end
|
26
53
|
|
27
|
-
|
28
|
-
|
29
|
-
|
54
|
+
context 'when no headers are set' do
|
55
|
+
describe '#header' do
|
56
|
+
it 'returns nil' do
|
57
|
+
expect(subject.header['First Key']).to be nil
|
58
|
+
expect(subject.header('First Key')).to be nil
|
59
|
+
end
|
30
60
|
end
|
31
61
|
end
|
32
62
|
end
|
@@ -34,6 +34,7 @@ module Grape
|
|
34
34
|
|
35
35
|
describe Helpers do
|
36
36
|
subject { Class.new(HelpersSpec::Dummy) }
|
37
|
+
|
37
38
|
let(:proc) do
|
38
39
|
lambda do |*|
|
39
40
|
def test
|
@@ -54,7 +55,7 @@ module Grape
|
|
54
55
|
it 'uses provided modules' do
|
55
56
|
mod = Module.new
|
56
57
|
|
57
|
-
expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original.
|
58
|
+
expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original.twice
|
58
59
|
expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original
|
59
60
|
subject.helpers(mod, &proc)
|
60
61
|
|
@@ -92,7 +93,7 @@ module Grape
|
|
92
93
|
use :requires_toggle_prm
|
93
94
|
end
|
94
95
|
end
|
95
|
-
end.
|
96
|
+
end.not_to raise_exception
|
96
97
|
end
|
97
98
|
end
|
98
99
|
end
|
@@ -43,6 +43,7 @@ describe Grape::Endpoint do
|
|
43
43
|
before do
|
44
44
|
catch(:error) { subject.error! 'Not Found', 404 }
|
45
45
|
end
|
46
|
+
|
46
47
|
it 'sets status' do
|
47
48
|
expect(subject.status).to eq 404
|
48
49
|
end
|
@@ -53,6 +54,7 @@ describe Grape::Endpoint do
|
|
53
54
|
subject.namespace_inheritable(:default_error_status, 500)
|
54
55
|
catch(:error) { subject.error! 'Unknown' }
|
55
56
|
end
|
57
|
+
|
56
58
|
it 'sets status to default_error_status' do
|
57
59
|
expect(subject.status).to eq 500
|
58
60
|
end
|
@@ -136,7 +138,7 @@ describe Grape::Endpoint do
|
|
136
138
|
end
|
137
139
|
|
138
140
|
it 'accepts unknown Integer status codes' do
|
139
|
-
expect { subject.status 210 }.
|
141
|
+
expect { subject.status 210 }.not_to raise_error
|
140
142
|
end
|
141
143
|
|
142
144
|
it 'raises error if status is not a integer or symbol' do
|
@@ -203,80 +205,229 @@ describe Grape::Endpoint do
|
|
203
205
|
end
|
204
206
|
|
205
207
|
describe '#file' do
|
208
|
+
before do
|
209
|
+
allow(subject).to receive(:warn)
|
210
|
+
end
|
211
|
+
|
206
212
|
describe 'set' do
|
207
213
|
context 'as file path' do
|
208
214
|
let(:file_path) { '/some/file/path' }
|
209
215
|
|
210
|
-
|
211
|
-
|
212
|
-
Grape::ServeFile::FileResponse.new(file_body)
|
213
|
-
end
|
216
|
+
it 'emits a warning that this method is deprecated' do
|
217
|
+
expect(subject).to receive(:warn).with(/Use sendfile or stream/)
|
214
218
|
|
215
|
-
before do
|
216
219
|
subject.file file_path
|
217
220
|
end
|
218
221
|
|
219
|
-
it '
|
220
|
-
expect(subject
|
222
|
+
it 'forwards the call to sendfile' do
|
223
|
+
expect(subject).to receive(:sendfile).with(file_path)
|
224
|
+
|
225
|
+
subject.file file_path
|
221
226
|
end
|
222
227
|
end
|
223
228
|
|
224
229
|
context 'as object (backward compatibility)' do
|
225
|
-
let(:file_object) {
|
230
|
+
let(:file_object) { double('StreamerObject', each: nil) }
|
231
|
+
|
232
|
+
it 'emits a warning that this method is deprecated' do
|
233
|
+
expect(subject).to receive(:warn).with(/Use stream to use a Stream object/)
|
234
|
+
|
235
|
+
subject.file file_object
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'forwards the call to stream' do
|
239
|
+
expect(subject).to receive(:stream).with(file_object)
|
240
|
+
|
241
|
+
subject.file file_object
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe 'get' do
|
247
|
+
it 'emits a warning that this method is deprecated' do
|
248
|
+
expect(subject).to receive(:warn).with(/Use sendfile or stream/)
|
249
|
+
|
250
|
+
subject.file
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'fowards call to sendfile' do
|
254
|
+
expect(subject).to receive(:sendfile)
|
255
|
+
|
256
|
+
subject.file
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe '#sendfile' do
|
262
|
+
describe 'set' do
|
263
|
+
context 'as file path' do
|
264
|
+
let(:file_path) { '/some/file/path' }
|
226
265
|
|
227
266
|
let(:file_response) do
|
228
|
-
Grape::
|
267
|
+
file_body = Grape::ServeStream::FileBody.new(file_path)
|
268
|
+
Grape::ServeStream::StreamResponse.new(file_body)
|
229
269
|
end
|
230
270
|
|
231
271
|
before do
|
232
|
-
subject.
|
272
|
+
subject.header 'Cache-Control', 'cache'
|
273
|
+
subject.header 'Content-Length', 123
|
274
|
+
subject.header 'Transfer-Encoding', 'base64'
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'sends no deprecation warnings' do
|
278
|
+
expect(subject).not_to receive(:warn)
|
279
|
+
|
280
|
+
subject.sendfile file_path
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'returns value wrapped in StreamResponse' do
|
284
|
+
subject.sendfile file_path
|
285
|
+
|
286
|
+
expect(subject.sendfile).to eq file_response
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'does not change the Cache-Control header' do
|
290
|
+
subject.sendfile file_path
|
291
|
+
|
292
|
+
expect(subject.header['Cache-Control']).to eq 'cache'
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'does not change the Content-Length header' do
|
296
|
+
subject.sendfile file_path
|
297
|
+
|
298
|
+
expect(subject.header['Content-Length']).to eq 123
|
233
299
|
end
|
234
300
|
|
235
|
-
it '
|
236
|
-
|
301
|
+
it 'does not change the Transfer-Encoding header' do
|
302
|
+
subject.sendfile file_path
|
303
|
+
|
304
|
+
expect(subject.header['Transfer-Encoding']).to eq 'base64'
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context 'as object' do
|
309
|
+
let(:file_object) { double('StreamerObject', each: nil) }
|
310
|
+
|
311
|
+
it 'raises an error that only a file path is supported' do
|
312
|
+
expect { subject.sendfile file_object }.to raise_error(ArgumentError, /Argument must be a file path/)
|
237
313
|
end
|
238
314
|
end
|
239
315
|
end
|
240
316
|
|
241
317
|
it 'returns default' do
|
242
|
-
expect(subject.
|
318
|
+
expect(subject.sendfile).to be nil
|
243
319
|
end
|
244
320
|
end
|
245
321
|
|
246
322
|
describe '#stream' do
|
247
323
|
describe 'set' do
|
248
|
-
|
324
|
+
context 'as a file path' do
|
325
|
+
let(:file_path) { '/some/file/path' }
|
249
326
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
subject.stream file_object
|
255
|
-
end
|
327
|
+
let(:file_response) do
|
328
|
+
file_body = Grape::ServeStream::FileBody.new(file_path)
|
329
|
+
Grape::ServeStream::StreamResponse.new(file_body)
|
330
|
+
end
|
256
331
|
|
257
|
-
|
258
|
-
|
259
|
-
|
332
|
+
before do
|
333
|
+
subject.header 'Cache-Control', 'cache'
|
334
|
+
subject.header 'Content-Length', 123
|
335
|
+
subject.header 'Transfer-Encoding', 'base64'
|
336
|
+
end
|
260
337
|
|
261
|
-
|
262
|
-
|
263
|
-
|
338
|
+
it 'emits no deprecation warnings' do
|
339
|
+
expect(subject).not_to receive(:warn)
|
340
|
+
|
341
|
+
subject.stream file_path
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'returns file body wrapped in StreamResponse' do
|
345
|
+
subject.stream file_path
|
346
|
+
|
347
|
+
expect(subject.stream).to eq file_response
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'sets Cache-Control header to no-cache' do
|
351
|
+
subject.stream file_path
|
352
|
+
|
353
|
+
expect(subject.header['Cache-Control']).to eq 'no-cache'
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'does not change Cache-Control header' do
|
357
|
+
subject.stream
|
358
|
+
|
359
|
+
expect(subject.header['Cache-Control']).to eq 'cache'
|
360
|
+
end
|
361
|
+
|
362
|
+
it 'sets Content-Length header to nil' do
|
363
|
+
subject.stream file_path
|
364
|
+
|
365
|
+
expect(subject.header['Content-Length']).to eq nil
|
366
|
+
end
|
264
367
|
|
265
|
-
|
266
|
-
|
368
|
+
it 'sets Transfer-Encoding header to nil' do
|
369
|
+
subject.stream file_path
|
370
|
+
|
371
|
+
expect(subject.header['Transfer-Encoding']).to eq nil
|
372
|
+
end
|
267
373
|
end
|
268
374
|
|
269
|
-
|
270
|
-
|
375
|
+
context 'as a stream object' do
|
376
|
+
let(:stream_object) { double('StreamerObject', each: nil) }
|
377
|
+
|
378
|
+
let(:stream_response) do
|
379
|
+
Grape::ServeStream::StreamResponse.new(stream_object)
|
380
|
+
end
|
381
|
+
|
382
|
+
before do
|
383
|
+
subject.header 'Cache-Control', 'cache'
|
384
|
+
subject.header 'Content-Length', 123
|
385
|
+
subject.header 'Transfer-Encoding', 'base64'
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'emits no deprecation warnings' do
|
389
|
+
expect(subject).not_to receive(:warn)
|
390
|
+
|
391
|
+
subject.stream stream_object
|
392
|
+
end
|
393
|
+
|
394
|
+
it 'returns value wrapped in StreamResponse' do
|
395
|
+
subject.stream stream_object
|
396
|
+
|
397
|
+
expect(subject.stream).to eq stream_response
|
398
|
+
end
|
399
|
+
|
400
|
+
it 'sets Cache-Control header to no-cache' do
|
401
|
+
subject.stream stream_object
|
402
|
+
|
403
|
+
expect(subject.header['Cache-Control']).to eq 'no-cache'
|
404
|
+
end
|
405
|
+
|
406
|
+
it 'sets Content-Length header to nil' do
|
407
|
+
subject.stream stream_object
|
408
|
+
|
409
|
+
expect(subject.header['Content-Length']).to eq nil
|
410
|
+
end
|
411
|
+
|
412
|
+
it 'sets Transfer-Encoding header to nil' do
|
413
|
+
subject.stream stream_object
|
414
|
+
|
415
|
+
expect(subject.header['Transfer-Encoding']).to eq nil
|
416
|
+
end
|
271
417
|
end
|
272
418
|
|
273
|
-
|
274
|
-
|
419
|
+
context 'as a non-stream object' do
|
420
|
+
let(:non_stream_object) { double('NonStreamerObject') }
|
421
|
+
|
422
|
+
it 'raises an error that the object must implement :each' do
|
423
|
+
expect { subject.stream non_stream_object }.to raise_error(ArgumentError, /:each/)
|
424
|
+
end
|
275
425
|
end
|
276
426
|
end
|
277
427
|
|
278
428
|
it 'returns default' do
|
279
|
-
expect(subject.
|
429
|
+
expect(subject.stream).to be nil
|
430
|
+
expect(subject.header['Cache-Control']).to eq nil
|
280
431
|
end
|
281
432
|
end
|
282
433
|
|
@@ -2,27 +2,25 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe Grape::DSL::Logger do
|
6
|
+
subject { Class.new(dummy_logger) }
|
7
|
+
|
8
|
+
let(:dummy_logger) do
|
9
|
+
Class.new do
|
10
|
+
extend Grape::DSL::Logger
|
11
11
|
end
|
12
|
-
|
13
|
-
subject { Class.new(LoggerSpec::Dummy) }
|
14
|
-
let(:logger) { double(:logger) }
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
let(:logger) { instance_double(::Logger) }
|
15
|
+
|
16
|
+
describe '.logger' do
|
17
|
+
it 'sets a logger' do
|
18
|
+
subject.logger logger
|
19
|
+
expect(subject.logger).to eq logger
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
22
|
+
it 'returns a logger' do
|
23
|
+
expect(subject.logger(logger)).to eq logger
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -40,6 +40,7 @@ module Grape
|
|
40
40
|
|
41
41
|
def extract_message_option(attrs)
|
42
42
|
return nil unless attrs.is_a?(Array)
|
43
|
+
|
43
44
|
opts = attrs.last.is_a?(Hash) ? attrs.pop : {}
|
44
45
|
opts.key?(:message) && !opts[:message].nil? ? opts.delete(:message) : nil
|
45
46
|
end
|
@@ -54,6 +55,7 @@ module Grape
|
|
54
55
|
allow_message_expectations_on_nil
|
55
56
|
allow(subject.api).to receive(:namespace_stackable).with(:named_params)
|
56
57
|
end
|
58
|
+
|
57
59
|
let(:options) { { option: 'value' } }
|
58
60
|
let(:named_params) { { params_group: proc {} } }
|
59
61
|
|
@@ -12,7 +12,8 @@ module Grape
|
|
12
12
|
|
13
13
|
describe Routing do
|
14
14
|
subject { Class.new(RoutingSpec::Dummy) }
|
15
|
-
|
15
|
+
|
16
|
+
let(:proc) { -> {} }
|
16
17
|
let(:options) { { a: :b } }
|
17
18
|
let(:path) { '/dummy' }
|
18
19
|
|
@@ -109,7 +110,7 @@ module Grape
|
|
109
110
|
it 'does not duplicate identical endpoints' do
|
110
111
|
subject.route(:any)
|
111
112
|
expect { subject.route(:any) }
|
112
|
-
.
|
113
|
+
.not_to change(subject.endpoints, :count)
|
113
114
|
end
|
114
115
|
|
115
116
|
it 'generates correct endpoint options' do
|
@@ -233,21 +234,23 @@ module Grape
|
|
233
234
|
allow(subject).to receive(:prepare_routes).and_return(routes)
|
234
235
|
subject.routes
|
235
236
|
end
|
236
|
-
|
237
|
-
|
237
|
+
|
238
|
+
it 'does not call prepare_routes again' do
|
239
|
+
expect(subject).not_to receive(:prepare_routes)
|
238
240
|
expect(subject.routes).to eq routes
|
239
241
|
end
|
240
242
|
end
|
241
243
|
end
|
242
244
|
|
243
245
|
describe '.route_param' do
|
246
|
+
let!(:options) { { requirements: regex } }
|
247
|
+
let(:regex) { /(.*)/ }
|
248
|
+
|
244
249
|
it 'calls #namespace with given params' do
|
245
250
|
expect(subject).to receive(:namespace).with(':foo', {}).and_yield
|
246
251
|
subject.route_param('foo', {}, &proc {})
|
247
252
|
end
|
248
253
|
|
249
|
-
let(:regex) { /(.*)/ }
|
250
|
-
let!(:options) { { requirements: regex } }
|
251
254
|
it 'nests requirements option under param name' do
|
252
255
|
expect(subject).to receive(:namespace) do |_param, options|
|
253
256
|
expect(options[:requirements][:foo]).to eq regex
|
@@ -258,7 +261,7 @@ module Grape
|
|
258
261
|
it 'does not modify options parameter' do
|
259
262
|
allow(subject).to receive(:namespace)
|
260
263
|
expect { subject.route_param('foo', options, &proc {}) }
|
261
|
-
.
|
264
|
+
.not_to change { options }
|
262
265
|
end
|
263
266
|
end
|
264
267
|
|