grape 1.8.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +19 -22
- data/UPGRADING.md +35 -0
- data/grape.gemspec +1 -4
- data/lib/grape/dsl/desc.rb +1 -1
- data/lib/grape/dsl/inside_route.rb +9 -9
- data/lib/grape/endpoint.rb +9 -1
- data/lib/grape/exceptions/missing_group_type.rb +1 -1
- data/lib/grape/exceptions/unsupported_group_type.rb +1 -1
- data/lib/grape/http/headers.rb +12 -2
- data/lib/grape/middleware/auth/strategies.rb +1 -2
- data/lib/grape/middleware/error.rb +4 -4
- data/lib/grape/middleware/formatter.rb +5 -5
- data/lib/grape/railtie.rb +9 -0
- data/lib/grape/request.rb +8 -2
- data/lib/grape/router/route.rb +1 -1
- data/lib/grape/validations/validators/base.rb +1 -1
- data/lib/grape/validations/validators/values_validator.rb +2 -2
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +15 -2
- metadata +8 -243
- data/spec/grape/api/custom_validations_spec.rb +0 -213
- data/spec/grape/api/deeply_included_options_spec.rb +0 -56
- data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -38
- data/spec/grape/api/documentation_spec.rb +0 -59
- data/spec/grape/api/inherited_helpers_spec.rb +0 -114
- data/spec/grape/api/instance_spec.rb +0 -103
- data/spec/grape/api/invalid_format_spec.rb +0 -45
- data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -38
- data/spec/grape/api/nested_helpers_spec.rb +0 -50
- data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -43
- data/spec/grape/api/parameters_modification_spec.rb +0 -41
- data/spec/grape/api/patch_method_helpers_spec.rb +0 -79
- data/spec/grape/api/recognize_path_spec.rb +0 -21
- data/spec/grape/api/required_parameters_in_route_spec.rb +0 -37
- data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -26
- data/spec/grape/api/routes_with_requirements_spec.rb +0 -59
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -41
- data/spec/grape/api/shared_helpers_spec.rb +0 -36
- data/spec/grape/api_remount_spec.rb +0 -509
- data/spec/grape/api_spec.rb +0 -4356
- data/spec/grape/dsl/callbacks_spec.rb +0 -45
- data/spec/grape/dsl/desc_spec.rb +0 -98
- data/spec/grape/dsl/headers_spec.rb +0 -62
- data/spec/grape/dsl/helpers_spec.rb +0 -100
- data/spec/grape/dsl/inside_route_spec.rb +0 -531
- data/spec/grape/dsl/logger_spec.rb +0 -24
- data/spec/grape/dsl/middleware_spec.rb +0 -60
- data/spec/grape/dsl/parameters_spec.rb +0 -180
- data/spec/grape/dsl/request_response_spec.rb +0 -225
- data/spec/grape/dsl/routing_spec.rb +0 -275
- data/spec/grape/dsl/settings_spec.rb +0 -261
- data/spec/grape/dsl/validations_spec.rb +0 -55
- data/spec/grape/endpoint/declared_spec.rb +0 -846
- data/spec/grape/endpoint_spec.rb +0 -1085
- data/spec/grape/entity_spec.rb +0 -336
- data/spec/grape/exceptions/base_spec.rb +0 -81
- data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -185
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +0 -358
- data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -15
- data/spec/grape/exceptions/invalid_response_spec.rb +0 -11
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -15
- data/spec/grape/exceptions/missing_group_type_spec.rb +0 -17
- data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -17
- data/spec/grape/exceptions/missing_option_spec.rb +0 -15
- data/spec/grape/exceptions/unknown_options_spec.rb +0 -15
- data/spec/grape/exceptions/unknown_validator_spec.rb +0 -15
- data/spec/grape/exceptions/unsupported_group_type_spec.rb +0 -19
- data/spec/grape/exceptions/validation_errors_spec.rb +0 -92
- data/spec/grape/exceptions/validation_spec.rb +0 -19
- data/spec/grape/extensions/param_builders/hash_spec.rb +0 -83
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -105
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -79
- data/spec/grape/grape_spec.rb +0 -9
- data/spec/grape/integration/global_namespace_function_spec.rb +0 -29
- data/spec/grape/integration/rack_sendfile_spec.rb +0 -48
- data/spec/grape/integration/rack_spec.rb +0 -51
- data/spec/grape/loading_spec.rb +0 -44
- data/spec/grape/middleware/auth/base_spec.rb +0 -31
- data/spec/grape/middleware/auth/dsl_spec.rb +0 -60
- data/spec/grape/middleware/auth/strategies_spec.rb +0 -120
- data/spec/grape/middleware/base_spec.rb +0 -221
- data/spec/grape/middleware/error_spec.rb +0 -85
- data/spec/grape/middleware/exception_spec.rb +0 -294
- data/spec/grape/middleware/formatter_spec.rb +0 -461
- data/spec/grape/middleware/globals_spec.rb +0 -30
- data/spec/grape/middleware/stack_spec.rb +0 -155
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -122
- data/spec/grape/middleware/versioner/header_spec.rb +0 -345
- data/spec/grape/middleware/versioner/param_spec.rb +0 -171
- data/spec/grape/middleware/versioner/path_spec.rb +0 -62
- data/spec/grape/middleware/versioner_spec.rb +0 -21
- data/spec/grape/named_api_spec.rb +0 -19
- data/spec/grape/parser_spec.rb +0 -86
- data/spec/grape/path_spec.rb +0 -252
- data/spec/grape/presenters/presenter_spec.rb +0 -71
- data/spec/grape/request_spec.rb +0 -126
- data/spec/grape/util/inheritable_setting_spec.rb +0 -242
- data/spec/grape/util/inheritable_values_spec.rb +0 -79
- data/spec/grape/util/reverse_stackable_values_spec.rb +0 -134
- data/spec/grape/util/stackable_values_spec.rb +0 -128
- data/spec/grape/util/strict_hash_configuration_spec.rb +0 -38
- data/spec/grape/validations/attributes_doc_spec.rb +0 -153
- data/spec/grape/validations/instance_behaivour_spec.rb +0 -43
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -38
- data/spec/grape/validations/params_scope_spec.rb +0 -1420
- data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -56
- data/spec/grape/validations/types/array_coercer_spec.rb +0 -33
- data/spec/grape/validations/types/primitive_coercer_spec.rb +0 -150
- data/spec/grape/validations/types/set_coercer_spec.rb +0 -32
- data/spec/grape/validations/types_spec.rb +0 -111
- data/spec/grape/validations/validators/all_or_none_spec.rb +0 -162
- data/spec/grape/validations/validators/allow_blank_spec.rb +0 -575
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -205
- data/spec/grape/validations/validators/base_spec.rb +0 -38
- data/spec/grape/validations/validators/coerce_spec.rb +0 -1261
- data/spec/grape/validations/validators/default_spec.rb +0 -463
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -233
- data/spec/grape/validations/validators/except_values_spec.rb +0 -192
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -214
- data/spec/grape/validations/validators/presence_spec.rb +0 -315
- data/spec/grape/validations/validators/regexp_spec.rb +0 -161
- data/spec/grape/validations/validators/same_as_spec.rb +0 -57
- data/spec/grape/validations/validators/values_spec.rb +0 -733
- data/spec/grape/validations/validators/zh-CN.yml +0 -10
- data/spec/grape/validations_spec.rb +0 -2030
- data/spec/integration/eager_load/eager_load_spec.rb +0 -15
- data/spec/integration/multi_json/json_spec.rb +0 -7
- data/spec/integration/multi_xml/xml_spec.rb +0 -7
- data/spec/shared/deprecated_class_examples.rb +0 -16
- data/spec/shared/versioning_examples.rb +0 -215
- data/spec/spec_helper.rb +0 -52
- data/spec/support/basic_auth_encode_helpers.rb +0 -11
- data/spec/support/chunks.rb +0 -14
- data/spec/support/content_type_helpers.rb +0 -15
- data/spec/support/endpoint_faker.rb +0 -25
- data/spec/support/file_streamer.rb +0 -13
- data/spec/support/integer_helpers.rb +0 -13
- data/spec/support/versioned_helpers.rb +0 -55
@@ -1,531 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
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
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe Grape::Endpoint do
|
22
|
-
subject { Grape::DSL::InsideRouteSpec::Dummy.new }
|
23
|
-
|
24
|
-
describe '#version' do
|
25
|
-
it 'defaults to nil' do
|
26
|
-
expect(subject.version).to be_nil
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns env[api.version]' do
|
30
|
-
subject.env['api.version'] = 'dummy'
|
31
|
-
expect(subject.version).to eq 'dummy'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#error!' do
|
36
|
-
it 'throws :error' do
|
37
|
-
expect { subject.error! 'Not Found', 404 }.to throw_symbol(:error)
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'thrown' do
|
41
|
-
before do
|
42
|
-
catch(:error) { subject.error! 'Not Found', 404 }
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'sets status' do
|
46
|
-
expect(subject.status).to eq 404
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe 'default_error_status' do
|
51
|
-
before do
|
52
|
-
subject.namespace_inheritable(:default_error_status, 500)
|
53
|
-
catch(:error) { subject.error! 'Unknown' }
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'sets status to default_error_status' do
|
57
|
-
expect(subject.status).to eq 500
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# self.status(status || settings[:default_error_status])
|
62
|
-
# throw :error, message: message, status: self.status, headers: headers
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#redirect' do
|
66
|
-
describe 'default' do
|
67
|
-
before do
|
68
|
-
subject.redirect '/'
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'sets status to 302' do
|
72
|
-
expect(subject.status).to eq 302
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'sets location header' do
|
76
|
-
expect(subject.header['Location']).to eq '/'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'permanent' do
|
81
|
-
before do
|
82
|
-
subject.redirect '/', permanent: true
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'sets status to 301' do
|
86
|
-
expect(subject.status).to eq 301
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'sets location header' do
|
90
|
-
expect(subject.header['Location']).to eq '/'
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe '#status' do
|
96
|
-
%w[GET PUT OPTIONS].each do |method|
|
97
|
-
it 'defaults to 200 on GET' do
|
98
|
-
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: method))
|
99
|
-
expect(subject).to receive(:request).and_return(request)
|
100
|
-
expect(subject.status).to eq 200
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'defaults to 201 on POST' do
|
105
|
-
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'POST'))
|
106
|
-
expect(subject).to receive(:request).and_return(request)
|
107
|
-
expect(subject.status).to eq 201
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'defaults to 204 on DELETE' do
|
111
|
-
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE'))
|
112
|
-
expect(subject).to receive(:request).and_return(request)
|
113
|
-
expect(subject.status).to eq 204
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'defaults to 200 on DELETE with a body present' do
|
117
|
-
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE'))
|
118
|
-
subject.body 'content here'
|
119
|
-
expect(subject).to receive(:request).and_return(request)
|
120
|
-
expect(subject.status).to eq 200
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'returns status set' do
|
124
|
-
subject.status 501
|
125
|
-
expect(subject.status).to eq 501
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'accepts symbol for status' do
|
129
|
-
subject.status :see_other
|
130
|
-
expect(subject.status).to eq 303
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'raises error if unknow symbol is passed' do
|
134
|
-
expect { subject.status :foo_bar }
|
135
|
-
.to raise_error(ArgumentError, 'Status code :foo_bar is invalid.')
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'accepts unknown Integer status codes' do
|
139
|
-
expect { subject.status 210 }.not_to raise_error
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'raises error if status is not a integer or symbol' do
|
143
|
-
expect { subject.status Object.new }
|
144
|
-
.to raise_error(ArgumentError, 'Status code must be Integer or Symbol.')
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe '#return_no_content' do
|
149
|
-
it 'sets the status code and body' do
|
150
|
-
subject.return_no_content
|
151
|
-
expect(subject.status).to eq 204
|
152
|
-
expect(subject.body).to eq ''
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe '#content_type' do
|
157
|
-
describe 'set' do
|
158
|
-
before do
|
159
|
-
subject.content_type 'text/plain'
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'returns value' do
|
163
|
-
expect(subject.content_type).to eq 'text/plain'
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'returns default' do
|
168
|
-
expect(subject.content_type).to be_nil
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe '#cookies' do
|
173
|
-
it 'returns an instance of Cookies' do
|
174
|
-
expect(subject.cookies).to be_a Grape::Cookies
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
describe '#body' do
|
179
|
-
describe 'set' do
|
180
|
-
before do
|
181
|
-
subject.body 'body'
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'returns value' do
|
185
|
-
expect(subject.body).to eq 'body'
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
describe 'false' do
|
190
|
-
before do
|
191
|
-
subject.body false
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'sets status to 204' do
|
195
|
-
expect(subject.body).to eq ''
|
196
|
-
expect(subject.status).to eq 204
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'returns default' do
|
201
|
-
expect(subject.body).to be_nil
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
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(ActiveSupport::Deprecation).to receive(:warn).with(/Use sendfile or stream/)
|
212
|
-
|
213
|
-
subject.file file_path
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'forwards the call to sendfile' do
|
217
|
-
expect(subject).to receive(:sendfile).with(file_path)
|
218
|
-
|
219
|
-
subject.file file_path
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context 'as object (backward compatibility)' do
|
224
|
-
let(:file_object) { double('StreamerObject', each: nil) }
|
225
|
-
|
226
|
-
it 'emits a warning that this method is deprecated' do
|
227
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).with(/Use stream to use a Stream object/)
|
228
|
-
|
229
|
-
subject.file file_object
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'forwards the call to stream' do
|
233
|
-
expect(subject).to receive(:stream).with(file_object)
|
234
|
-
|
235
|
-
subject.file file_object
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe 'get' do
|
241
|
-
it 'emits a warning that this method is deprecated' do
|
242
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).with(/Use sendfile or stream/)
|
243
|
-
|
244
|
-
subject.file
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'fowards call to sendfile' do
|
248
|
-
expect(subject).to receive(:sendfile)
|
249
|
-
|
250
|
-
subject.file
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
describe '#sendfile' do
|
256
|
-
describe 'set' do
|
257
|
-
context 'as file path' do
|
258
|
-
let(:file_path) { '/some/file/path' }
|
259
|
-
|
260
|
-
let(:file_response) do
|
261
|
-
file_body = Grape::ServeStream::FileBody.new(file_path)
|
262
|
-
Grape::ServeStream::StreamResponse.new(file_body)
|
263
|
-
end
|
264
|
-
|
265
|
-
before do
|
266
|
-
subject.header 'Cache-Control', 'cache'
|
267
|
-
subject.header 'Content-Length', 123
|
268
|
-
subject.header 'Transfer-Encoding', 'base64'
|
269
|
-
end
|
270
|
-
|
271
|
-
it 'sends no deprecation warnings' do
|
272
|
-
expect(ActiveSupport::Deprecation).not_to receive(:warn)
|
273
|
-
|
274
|
-
subject.sendfile file_path
|
275
|
-
end
|
276
|
-
|
277
|
-
it 'returns value wrapped in StreamResponse' do
|
278
|
-
subject.sendfile file_path
|
279
|
-
|
280
|
-
expect(subject.sendfile).to eq file_response
|
281
|
-
end
|
282
|
-
|
283
|
-
it 'does not change the Cache-Control header' do
|
284
|
-
subject.sendfile file_path
|
285
|
-
|
286
|
-
expect(subject.header['Cache-Control']).to eq 'cache'
|
287
|
-
end
|
288
|
-
|
289
|
-
it 'does not change the Content-Length header' do
|
290
|
-
subject.sendfile file_path
|
291
|
-
|
292
|
-
expect(subject.header['Content-Length']).to eq 123
|
293
|
-
end
|
294
|
-
|
295
|
-
it 'does not change the Transfer-Encoding header' do
|
296
|
-
subject.sendfile file_path
|
297
|
-
|
298
|
-
expect(subject.header['Transfer-Encoding']).to eq 'base64'
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
context 'as object' do
|
303
|
-
let(:file_object) { double('StreamerObject', each: nil) }
|
304
|
-
|
305
|
-
it 'raises an error that only a file path is supported' do
|
306
|
-
expect { subject.sendfile file_object }.to raise_error(ArgumentError, /Argument must be a file path/)
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
it 'returns default' do
|
312
|
-
expect(subject.sendfile).to be_nil
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
describe '#stream' do
|
317
|
-
describe 'set' do
|
318
|
-
context 'as a file path' do
|
319
|
-
let(:file_path) { '/some/file/path' }
|
320
|
-
|
321
|
-
let(:file_response) do
|
322
|
-
file_body = Grape::ServeStream::FileBody.new(file_path)
|
323
|
-
Grape::ServeStream::StreamResponse.new(file_body)
|
324
|
-
end
|
325
|
-
|
326
|
-
before do
|
327
|
-
subject.header 'Cache-Control', 'cache'
|
328
|
-
subject.header 'Content-Length', 123
|
329
|
-
subject.header 'Transfer-Encoding', 'base64'
|
330
|
-
end
|
331
|
-
|
332
|
-
it 'emits no deprecation warnings' do
|
333
|
-
expect(ActiveSupport::Deprecation).not_to receive(:warn)
|
334
|
-
|
335
|
-
subject.stream file_path
|
336
|
-
end
|
337
|
-
|
338
|
-
it 'returns file body wrapped in StreamResponse' do
|
339
|
-
subject.stream file_path
|
340
|
-
|
341
|
-
expect(subject.stream).to eq file_response
|
342
|
-
end
|
343
|
-
|
344
|
-
it 'sets Cache-Control header to no-cache' do
|
345
|
-
subject.stream file_path
|
346
|
-
|
347
|
-
expect(subject.header['Cache-Control']).to eq 'no-cache'
|
348
|
-
end
|
349
|
-
|
350
|
-
it 'does not change Cache-Control header' do
|
351
|
-
subject.stream
|
352
|
-
|
353
|
-
expect(subject.header['Cache-Control']).to eq 'cache'
|
354
|
-
end
|
355
|
-
|
356
|
-
it 'sets Content-Length header to nil' do
|
357
|
-
subject.stream file_path
|
358
|
-
|
359
|
-
expect(subject.header['Content-Length']).to be_nil
|
360
|
-
end
|
361
|
-
|
362
|
-
it 'sets Transfer-Encoding header to nil' do
|
363
|
-
subject.stream file_path
|
364
|
-
|
365
|
-
expect(subject.header['Transfer-Encoding']).to be_nil
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
context 'as a stream object' do
|
370
|
-
let(:stream_object) { double('StreamerObject', each: nil) }
|
371
|
-
|
372
|
-
let(:stream_response) do
|
373
|
-
Grape::ServeStream::StreamResponse.new(stream_object)
|
374
|
-
end
|
375
|
-
|
376
|
-
before do
|
377
|
-
subject.header 'Cache-Control', 'cache'
|
378
|
-
subject.header 'Content-Length', 123
|
379
|
-
subject.header 'Transfer-Encoding', 'base64'
|
380
|
-
end
|
381
|
-
|
382
|
-
it 'emits no deprecation warnings' do
|
383
|
-
expect(ActiveSupport::Deprecation).not_to receive(:warn)
|
384
|
-
|
385
|
-
subject.stream stream_object
|
386
|
-
end
|
387
|
-
|
388
|
-
it 'returns value wrapped in StreamResponse' do
|
389
|
-
subject.stream stream_object
|
390
|
-
|
391
|
-
expect(subject.stream).to eq stream_response
|
392
|
-
end
|
393
|
-
|
394
|
-
it 'sets Cache-Control header to no-cache' do
|
395
|
-
subject.stream stream_object
|
396
|
-
|
397
|
-
expect(subject.header['Cache-Control']).to eq 'no-cache'
|
398
|
-
end
|
399
|
-
|
400
|
-
it 'sets Content-Length header to nil' do
|
401
|
-
subject.stream stream_object
|
402
|
-
|
403
|
-
expect(subject.header['Content-Length']).to be_nil
|
404
|
-
end
|
405
|
-
|
406
|
-
it 'sets Transfer-Encoding header to nil' do
|
407
|
-
subject.stream stream_object
|
408
|
-
|
409
|
-
expect(subject.header['Transfer-Encoding']).to be_nil
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
context 'as a non-stream object' do
|
414
|
-
let(:non_stream_object) { double('NonStreamerObject') }
|
415
|
-
|
416
|
-
it 'raises an error that the object must implement :each' do
|
417
|
-
expect { subject.stream non_stream_object }.to raise_error(ArgumentError, /:each/)
|
418
|
-
end
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
it 'returns default' do
|
423
|
-
expect(subject.stream).to be_nil
|
424
|
-
expect(subject.header['Cache-Control']).to be_nil
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
describe '#route' do
|
429
|
-
before do
|
430
|
-
subject.env['grape.routing_args'] = {}
|
431
|
-
subject.env['grape.routing_args'][:route_info] = 'dummy'
|
432
|
-
end
|
433
|
-
|
434
|
-
it 'returns route_info' do
|
435
|
-
expect(subject.route).to eq 'dummy'
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
describe '#present' do
|
440
|
-
# see entity_spec.rb for entity representation spec coverage
|
441
|
-
|
442
|
-
describe 'dummy' do
|
443
|
-
before do
|
444
|
-
subject.present 'dummy'
|
445
|
-
end
|
446
|
-
|
447
|
-
it 'presents dummy object' do
|
448
|
-
expect(subject.body).to eq 'dummy'
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
describe 'with' do
|
453
|
-
describe 'entity' do
|
454
|
-
let(:entity_mock) do
|
455
|
-
entity_mock = Object.new
|
456
|
-
allow(entity_mock).to receive(:represent).and_return('dummy')
|
457
|
-
entity_mock
|
458
|
-
end
|
459
|
-
|
460
|
-
describe 'instance' do
|
461
|
-
before do
|
462
|
-
subject.present 'dummy', with: entity_mock
|
463
|
-
end
|
464
|
-
|
465
|
-
it 'presents dummy object' do
|
466
|
-
expect(subject.body).to eq 'dummy'
|
467
|
-
end
|
468
|
-
end
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
472
|
-
describe 'multiple entities' do
|
473
|
-
let(:entity_mock_one) do
|
474
|
-
entity_mock_one = Object.new
|
475
|
-
allow(entity_mock_one).to receive(:represent).and_return(dummy1: 'dummy1')
|
476
|
-
entity_mock_one
|
477
|
-
end
|
478
|
-
|
479
|
-
let(:entity_mock_two) do
|
480
|
-
entity_mock_two = Object.new
|
481
|
-
allow(entity_mock_two).to receive(:represent).and_return(dummy2: 'dummy2')
|
482
|
-
entity_mock_two
|
483
|
-
end
|
484
|
-
|
485
|
-
describe 'instance' do
|
486
|
-
before do
|
487
|
-
subject.present 'dummy1', with: entity_mock_one
|
488
|
-
subject.present 'dummy2', with: entity_mock_two
|
489
|
-
end
|
490
|
-
|
491
|
-
it 'presents both dummy objects' do
|
492
|
-
expect(subject.body[:dummy1]).to eq 'dummy1'
|
493
|
-
expect(subject.body[:dummy2]).to eq 'dummy2'
|
494
|
-
end
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
describe 'non mergeable entity' do
|
499
|
-
let(:entity_mock_one) do
|
500
|
-
entity_mock_one = Object.new
|
501
|
-
allow(entity_mock_one).to receive(:represent).and_return(dummy1: 'dummy1')
|
502
|
-
entity_mock_one
|
503
|
-
end
|
504
|
-
|
505
|
-
let(:entity_mock_two) do
|
506
|
-
entity_mock_two = Object.new
|
507
|
-
allow(entity_mock_two).to receive(:represent).and_return('not a hash')
|
508
|
-
entity_mock_two
|
509
|
-
end
|
510
|
-
|
511
|
-
describe 'instance' do
|
512
|
-
it 'fails' do
|
513
|
-
subject.present 'dummy1', with: entity_mock_one
|
514
|
-
expect do
|
515
|
-
subject.present 'dummy2', with: entity_mock_two
|
516
|
-
end.to raise_error ArgumentError, 'Representation of type String cannot be merged.'
|
517
|
-
end
|
518
|
-
end
|
519
|
-
end
|
520
|
-
end
|
521
|
-
|
522
|
-
describe '#declared' do
|
523
|
-
# see endpoint_spec.rb#declared for spec coverage
|
524
|
-
|
525
|
-
it 'is not available by default' do
|
526
|
-
expect { subject.declared({}) }.to raise_error(
|
527
|
-
Grape::DSL::InsideRoute::MethodNotYetAvailable
|
528
|
-
)
|
529
|
-
end
|
530
|
-
end
|
531
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe Grape::DSL::Logger do
|
4
|
-
subject { Class.new(dummy_logger) }
|
5
|
-
|
6
|
-
let(:dummy_logger) do
|
7
|
-
Class.new do
|
8
|
-
extend Grape::DSL::Logger
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:logger) { instance_double(::Logger) }
|
13
|
-
|
14
|
-
describe '.logger' do
|
15
|
-
it 'sets a logger' do
|
16
|
-
subject.logger logger
|
17
|
-
expect(subject.logger).to eq logger
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns a logger' do
|
21
|
-
expect(subject.logger(logger)).to eq logger
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module DSL
|
5
|
-
module MiddlewareSpec
|
6
|
-
class Dummy
|
7
|
-
include Grape::DSL::Middleware
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Middleware do
|
12
|
-
subject { Class.new(MiddlewareSpec::Dummy) }
|
13
|
-
|
14
|
-
let(:proc) { -> {} }
|
15
|
-
let(:foo_middleware) { Class.new }
|
16
|
-
let(:bar_middleware) { Class.new }
|
17
|
-
|
18
|
-
describe '.use' do
|
19
|
-
it 'adds a middleware with the right operation' do
|
20
|
-
expect(subject).to receive(:namespace_stackable).with(:middleware, [:use, foo_middleware, :arg1, proc])
|
21
|
-
|
22
|
-
subject.use foo_middleware, :arg1, &proc
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '.insert' do
|
27
|
-
it 'adds a middleware with the right operation' do
|
28
|
-
expect(subject).to receive(:namespace_stackable).with(:middleware, [:insert, 0, :arg1, proc])
|
29
|
-
|
30
|
-
subject.insert 0, :arg1, &proc
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '.insert_before' do
|
35
|
-
it 'adds a middleware with the right operation' do
|
36
|
-
expect(subject).to receive(:namespace_stackable).with(:middleware, [:insert_before, foo_middleware, :arg1, proc])
|
37
|
-
|
38
|
-
subject.insert_before foo_middleware, :arg1, &proc
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '.insert_after' do
|
43
|
-
it 'adds a middleware with the right operation' do
|
44
|
-
expect(subject).to receive(:namespace_stackable).with(:middleware, [:insert_after, foo_middleware, :arg1, proc])
|
45
|
-
|
46
|
-
subject.insert_after foo_middleware, :arg1, &proc
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '.middleware' do
|
51
|
-
it 'returns the middleware stack' do
|
52
|
-
subject.use foo_middleware, :arg1, &proc
|
53
|
-
subject.insert_before bar_middleware, :arg1, :arg2
|
54
|
-
|
55
|
-
expect(subject.middleware).to eq [[:use, foo_middleware, :arg1, proc], [:insert_before, bar_middleware, :arg1, :arg2]]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|