grape 1.8.0 → 2.0.0

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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +19 -22
  4. data/UPGRADING.md +35 -0
  5. data/grape.gemspec +1 -4
  6. data/lib/grape/dsl/desc.rb +1 -1
  7. data/lib/grape/dsl/inside_route.rb +9 -9
  8. data/lib/grape/endpoint.rb +9 -1
  9. data/lib/grape/exceptions/missing_group_type.rb +1 -1
  10. data/lib/grape/exceptions/unsupported_group_type.rb +1 -1
  11. data/lib/grape/http/headers.rb +12 -2
  12. data/lib/grape/middleware/auth/strategies.rb +1 -2
  13. data/lib/grape/middleware/error.rb +4 -4
  14. data/lib/grape/middleware/formatter.rb +5 -5
  15. data/lib/grape/railtie.rb +9 -0
  16. data/lib/grape/request.rb +8 -2
  17. data/lib/grape/router/route.rb +1 -1
  18. data/lib/grape/validations/validators/base.rb +1 -1
  19. data/lib/grape/validations/validators/values_validator.rb +2 -2
  20. data/lib/grape/version.rb +1 -1
  21. data/lib/grape.rb +15 -2
  22. metadata +8 -243
  23. data/spec/grape/api/custom_validations_spec.rb +0 -213
  24. data/spec/grape/api/deeply_included_options_spec.rb +0 -56
  25. data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -38
  26. data/spec/grape/api/documentation_spec.rb +0 -59
  27. data/spec/grape/api/inherited_helpers_spec.rb +0 -114
  28. data/spec/grape/api/instance_spec.rb +0 -103
  29. data/spec/grape/api/invalid_format_spec.rb +0 -45
  30. data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -38
  31. data/spec/grape/api/nested_helpers_spec.rb +0 -50
  32. data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -43
  33. data/spec/grape/api/parameters_modification_spec.rb +0 -41
  34. data/spec/grape/api/patch_method_helpers_spec.rb +0 -79
  35. data/spec/grape/api/recognize_path_spec.rb +0 -21
  36. data/spec/grape/api/required_parameters_in_route_spec.rb +0 -37
  37. data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -26
  38. data/spec/grape/api/routes_with_requirements_spec.rb +0 -59
  39. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -41
  40. data/spec/grape/api/shared_helpers_spec.rb +0 -36
  41. data/spec/grape/api_remount_spec.rb +0 -509
  42. data/spec/grape/api_spec.rb +0 -4356
  43. data/spec/grape/dsl/callbacks_spec.rb +0 -45
  44. data/spec/grape/dsl/desc_spec.rb +0 -98
  45. data/spec/grape/dsl/headers_spec.rb +0 -62
  46. data/spec/grape/dsl/helpers_spec.rb +0 -100
  47. data/spec/grape/dsl/inside_route_spec.rb +0 -531
  48. data/spec/grape/dsl/logger_spec.rb +0 -24
  49. data/spec/grape/dsl/middleware_spec.rb +0 -60
  50. data/spec/grape/dsl/parameters_spec.rb +0 -180
  51. data/spec/grape/dsl/request_response_spec.rb +0 -225
  52. data/spec/grape/dsl/routing_spec.rb +0 -275
  53. data/spec/grape/dsl/settings_spec.rb +0 -261
  54. data/spec/grape/dsl/validations_spec.rb +0 -55
  55. data/spec/grape/endpoint/declared_spec.rb +0 -846
  56. data/spec/grape/endpoint_spec.rb +0 -1085
  57. data/spec/grape/entity_spec.rb +0 -336
  58. data/spec/grape/exceptions/base_spec.rb +0 -81
  59. data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -185
  60. data/spec/grape/exceptions/invalid_accept_header_spec.rb +0 -358
  61. data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -15
  62. data/spec/grape/exceptions/invalid_response_spec.rb +0 -11
  63. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -15
  64. data/spec/grape/exceptions/missing_group_type_spec.rb +0 -17
  65. data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -17
  66. data/spec/grape/exceptions/missing_option_spec.rb +0 -15
  67. data/spec/grape/exceptions/unknown_options_spec.rb +0 -15
  68. data/spec/grape/exceptions/unknown_validator_spec.rb +0 -15
  69. data/spec/grape/exceptions/unsupported_group_type_spec.rb +0 -19
  70. data/spec/grape/exceptions/validation_errors_spec.rb +0 -92
  71. data/spec/grape/exceptions/validation_spec.rb +0 -19
  72. data/spec/grape/extensions/param_builders/hash_spec.rb +0 -83
  73. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -105
  74. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -79
  75. data/spec/grape/grape_spec.rb +0 -9
  76. data/spec/grape/integration/global_namespace_function_spec.rb +0 -29
  77. data/spec/grape/integration/rack_sendfile_spec.rb +0 -48
  78. data/spec/grape/integration/rack_spec.rb +0 -51
  79. data/spec/grape/loading_spec.rb +0 -44
  80. data/spec/grape/middleware/auth/base_spec.rb +0 -31
  81. data/spec/grape/middleware/auth/dsl_spec.rb +0 -60
  82. data/spec/grape/middleware/auth/strategies_spec.rb +0 -120
  83. data/spec/grape/middleware/base_spec.rb +0 -221
  84. data/spec/grape/middleware/error_spec.rb +0 -85
  85. data/spec/grape/middleware/exception_spec.rb +0 -294
  86. data/spec/grape/middleware/formatter_spec.rb +0 -461
  87. data/spec/grape/middleware/globals_spec.rb +0 -30
  88. data/spec/grape/middleware/stack_spec.rb +0 -155
  89. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -122
  90. data/spec/grape/middleware/versioner/header_spec.rb +0 -345
  91. data/spec/grape/middleware/versioner/param_spec.rb +0 -171
  92. data/spec/grape/middleware/versioner/path_spec.rb +0 -62
  93. data/spec/grape/middleware/versioner_spec.rb +0 -21
  94. data/spec/grape/named_api_spec.rb +0 -19
  95. data/spec/grape/parser_spec.rb +0 -86
  96. data/spec/grape/path_spec.rb +0 -252
  97. data/spec/grape/presenters/presenter_spec.rb +0 -71
  98. data/spec/grape/request_spec.rb +0 -126
  99. data/spec/grape/util/inheritable_setting_spec.rb +0 -242
  100. data/spec/grape/util/inheritable_values_spec.rb +0 -79
  101. data/spec/grape/util/reverse_stackable_values_spec.rb +0 -134
  102. data/spec/grape/util/stackable_values_spec.rb +0 -128
  103. data/spec/grape/util/strict_hash_configuration_spec.rb +0 -38
  104. data/spec/grape/validations/attributes_doc_spec.rb +0 -153
  105. data/spec/grape/validations/instance_behaivour_spec.rb +0 -43
  106. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -38
  107. data/spec/grape/validations/params_scope_spec.rb +0 -1420
  108. data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -56
  109. data/spec/grape/validations/types/array_coercer_spec.rb +0 -33
  110. data/spec/grape/validations/types/primitive_coercer_spec.rb +0 -150
  111. data/spec/grape/validations/types/set_coercer_spec.rb +0 -32
  112. data/spec/grape/validations/types_spec.rb +0 -111
  113. data/spec/grape/validations/validators/all_or_none_spec.rb +0 -162
  114. data/spec/grape/validations/validators/allow_blank_spec.rb +0 -575
  115. data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -205
  116. data/spec/grape/validations/validators/base_spec.rb +0 -38
  117. data/spec/grape/validations/validators/coerce_spec.rb +0 -1261
  118. data/spec/grape/validations/validators/default_spec.rb +0 -463
  119. data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -233
  120. data/spec/grape/validations/validators/except_values_spec.rb +0 -192
  121. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -214
  122. data/spec/grape/validations/validators/presence_spec.rb +0 -315
  123. data/spec/grape/validations/validators/regexp_spec.rb +0 -161
  124. data/spec/grape/validations/validators/same_as_spec.rb +0 -57
  125. data/spec/grape/validations/validators/values_spec.rb +0 -733
  126. data/spec/grape/validations/validators/zh-CN.yml +0 -10
  127. data/spec/grape/validations_spec.rb +0 -2030
  128. data/spec/integration/eager_load/eager_load_spec.rb +0 -15
  129. data/spec/integration/multi_json/json_spec.rb +0 -7
  130. data/spec/integration/multi_xml/xml_spec.rb +0 -7
  131. data/spec/shared/deprecated_class_examples.rb +0 -16
  132. data/spec/shared/versioning_examples.rb +0 -215
  133. data/spec/spec_helper.rb +0 -52
  134. data/spec/support/basic_auth_encode_helpers.rb +0 -11
  135. data/spec/support/chunks.rb +0 -14
  136. data/spec/support/content_type_helpers.rb +0 -15
  137. data/spec/support/endpoint_faker.rb +0 -25
  138. data/spec/support/file_streamer.rb +0 -13
  139. data/spec/support/integer_helpers.rb +0 -13
  140. data/spec/support/versioned_helpers.rb +0 -55
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::API::Helpers do
4
- subject do
5
- shared_params = Module.new do
6
- extend Grape::API::Helpers
7
-
8
- params :pagination do
9
- optional :page, type: Integer
10
- optional :size, type: Integer
11
- end
12
- end
13
-
14
- Class.new(Grape::API) do
15
- helpers shared_params
16
- format :json
17
-
18
- params do
19
- use :pagination
20
- end
21
- get do
22
- declared(params, include_missing: true)
23
- end
24
- end
25
- end
26
-
27
- def app
28
- subject
29
- end
30
-
31
- it 'defines parameters' do
32
- get '/'
33
- expect(last_response.status).to eq 200
34
- expect(last_response.body).to eq({ page: nil, size: nil }.to_json)
35
- end
36
- end
@@ -1,509 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared/versioning_examples'
4
-
5
- describe Grape::API do
6
- subject(:a_remounted_api) { Class.new(described_class) }
7
-
8
- let(:root_api) { Class.new(described_class) }
9
-
10
- def app
11
- root_api
12
- end
13
-
14
- describe 'remounting an API' do
15
- context 'with a defined route' do
16
- before do
17
- a_remounted_api.get '/votes' do
18
- '10 votes'
19
- end
20
- end
21
-
22
- context 'when mounting one instance' do
23
- before do
24
- root_api.mount a_remounted_api
25
- end
26
-
27
- it 'can access the endpoint' do
28
- get '/votes'
29
- expect(last_response.body).to eql '10 votes'
30
- end
31
- end
32
-
33
- context 'when mounting twice' do
34
- before do
35
- root_api.mount a_remounted_api => '/posts'
36
- root_api.mount a_remounted_api => '/comments'
37
- end
38
-
39
- it 'can access the votes in both places' do
40
- get '/posts/votes'
41
- expect(last_response.body).to eql '10 votes'
42
- get '/comments/votes'
43
- expect(last_response.body).to eql '10 votes'
44
- end
45
- end
46
-
47
- context 'when mounting on namespace' do
48
- before do
49
- stub_const('StaticRefToAPI', a_remounted_api)
50
- root_api.namespace 'posts' do
51
- mount StaticRefToAPI
52
- end
53
-
54
- root_api.namespace 'comments' do
55
- mount StaticRefToAPI
56
- end
57
- end
58
-
59
- it 'can access the votes in both places' do
60
- get '/posts/votes'
61
- expect(last_response.body).to eql '10 votes'
62
- get '/comments/votes'
63
- expect(last_response.body).to eql '10 votes'
64
- end
65
- end
66
- end
67
-
68
- describe 'with dynamic configuration' do
69
- context 'when mounting an endpoint conditional on a configuration' do
70
- subject(:a_remounted_api) do
71
- Class.new(described_class) do
72
- get 'always' do
73
- 'success'
74
- end
75
-
76
- given configuration[:mount_sometimes] do
77
- get 'sometimes' do
78
- 'sometimes'
79
- end
80
- end
81
- end
82
- end
83
-
84
- it 'mounts the endpoints only when configured to do so' do
85
- root_api.mount({ a_remounted_api => 'with_conditional' }, with: { mount_sometimes: true })
86
- root_api.mount({ a_remounted_api => 'without_conditional' }, with: { mount_sometimes: false })
87
-
88
- get '/with_conditional/always'
89
- expect(last_response.body).to eq 'success'
90
-
91
- get '/with_conditional/sometimes'
92
- expect(last_response.body).to eq 'sometimes'
93
-
94
- get '/without_conditional/always'
95
- expect(last_response.body).to eq 'success'
96
-
97
- get '/without_conditional/sometimes'
98
- expect(last_response.status).to eq 404
99
- end
100
- end
101
-
102
- context 'when using an expression derived from a configuration' do
103
- subject(:a_remounted_api) do
104
- Class.new(described_class) do
105
- get(mounted { "api_name_#{configuration[:api_name]}" }) do
106
- 'success'
107
- end
108
- end
109
- end
110
-
111
- before do
112
- root_api.mount a_remounted_api, with: {
113
- api_name: 'a_name'
114
- }
115
- end
116
-
117
- it 'mounts the endpoint with the name' do
118
- get 'api_name_a_name'
119
- expect(last_response.body).to eq 'success'
120
- end
121
-
122
- it 'does not mount the endpoint with a null name' do
123
- get 'api_name_'
124
- expect(last_response.body).not_to eq 'success'
125
- end
126
-
127
- context 'when the expression lives in a namespace' do
128
- subject(:a_remounted_api) do
129
- Class.new(described_class) do
130
- namespace :base do
131
- get(mounted { "api_name_#{configuration[:api_name]}" }) do
132
- 'success'
133
- end
134
- end
135
- end
136
- end
137
-
138
- it 'mounts the endpoint with the name' do
139
- get 'base/api_name_a_name'
140
- expect(last_response.body).to eq 'success'
141
- end
142
-
143
- it 'does not mount the endpoint with a null name' do
144
- get 'base/api_name_'
145
- expect(last_response.body).not_to eq 'success'
146
- end
147
- end
148
- end
149
-
150
- context 'when the params are configured via a configuration' do
151
- subject(:a_remounted_api) do
152
- Class.new(described_class) do
153
- params do
154
- requires configuration[:required_attr_name], type: String
155
- end
156
-
157
- get(mounted { configuration[:endpoint] }) do
158
- status 200
159
- end
160
- end
161
- end
162
-
163
- context 'when the configured param is my_attr' do
164
- it 'requires the configured params' do
165
- root_api.mount a_remounted_api, with: {
166
- required_attr_name: 'my_attr',
167
- endpoint: 'test'
168
- }
169
- get 'test?another_attr=1'
170
- expect(last_response.status).to eq 400
171
- get 'test?my_attr=1'
172
- expect(last_response.status).to eq 200
173
-
174
- root_api.mount a_remounted_api, with: {
175
- required_attr_name: 'another_attr',
176
- endpoint: 'test_b'
177
- }
178
- get 'test_b?another_attr=1'
179
- expect(last_response.status).to eq 200
180
- get 'test_b?my_attr=1'
181
- expect(last_response.status).to eq 400
182
- end
183
- end
184
- end
185
-
186
- context 'when executing a standard block within a `mounted` block with all dynamic params' do
187
- subject(:a_remounted_api) do
188
- Class.new(described_class) do
189
- mounted do
190
- desc configuration[:description] do
191
- headers configuration[:headers]
192
- end
193
- get configuration[:endpoint] do
194
- configuration[:response]
195
- end
196
- end
197
- end
198
- end
199
-
200
- let(:api_endpoint) { 'custom_endpoint' }
201
- let(:api_response) { 'custom response' }
202
- let(:endpoint_description) { 'this is a custom API' }
203
- let(:headers) do
204
- {
205
- 'XAuthToken' => {
206
- 'description' => 'Validates your identity',
207
- 'required' => true
208
- }
209
- }
210
- end
211
-
212
- it 'mounts the API and obtains the description and headers definition' do
213
- root_api.mount a_remounted_api, with: {
214
- description: endpoint_description,
215
- headers: headers,
216
- endpoint: api_endpoint,
217
- response: api_response
218
- }
219
- get api_endpoint
220
- expect(last_response.body).to eq api_response
221
- expect(a_remounted_api.instances.last.endpoints.first.options[:route_options][:description])
222
- .to eq endpoint_description
223
- expect(a_remounted_api.instances.last.endpoints.first.options[:route_options][:headers])
224
- .to eq headers
225
- end
226
- end
227
-
228
- context 'when executing a custom block on mount' do
229
- subject(:a_remounted_api) do
230
- Class.new(described_class) do
231
- get 'always' do
232
- 'success'
233
- end
234
-
235
- mounted do
236
- configuration[:endpoints].each do |endpoint_name, endpoint_response|
237
- get endpoint_name do
238
- endpoint_response
239
- end
240
- end
241
- end
242
- end
243
- end
244
-
245
- it 'mounts the endpoints only when configured to do so' do
246
- root_api.mount a_remounted_api, with: { endpoints: { 'api_name' => 'api_response' } }
247
- get 'api_name'
248
- expect(last_response.body).to eq 'api_response'
249
- end
250
- end
251
-
252
- context 'when the configuration is part of the arguments of a method' do
253
- subject(:a_remounted_api) do
254
- Class.new(described_class) do
255
- get configuration[:endpoint_name] do
256
- 'success'
257
- end
258
- end
259
- end
260
-
261
- it 'mounts the endpoint in the location it is configured' do
262
- root_api.mount a_remounted_api, with: { endpoint_name: 'some_location' }
263
- get '/some_location'
264
- expect(last_response.body).to eq 'success'
265
-
266
- get '/different_location'
267
- expect(last_response.status).to eq 404
268
-
269
- root_api.mount a_remounted_api, with: { endpoint_name: 'new_location' }
270
- get '/new_location'
271
- expect(last_response.body).to eq 'success'
272
- end
273
-
274
- context 'when the configuration is the value in a key-arg pair' do
275
- subject(:a_remounted_api) do
276
- Class.new(described_class) do
277
- version 'v1', using: :param, parameter: configuration[:version_param]
278
- get 'endpoint' do
279
- 'version 1'
280
- end
281
-
282
- version 'v2', using: :param, parameter: configuration[:version_param]
283
- get 'endpoint' do
284
- 'version 2'
285
- end
286
- end
287
- end
288
-
289
- it 'takes the param from the configuration' do
290
- root_api.mount a_remounted_api, with: { version_param: 'param_name' }
291
-
292
- get '/endpoint?param_name=v1'
293
- expect(last_response.body).to eq 'version 1'
294
-
295
- get '/endpoint?param_name=v2'
296
- expect(last_response.body).to eq 'version 2'
297
-
298
- get '/endpoint?wrong_param_name=v2'
299
- expect(last_response.body).to eq 'version 1'
300
- end
301
- end
302
- end
303
-
304
- context 'on the DescSCope' do
305
- subject(:a_remounted_api) do
306
- Class.new(described_class) do
307
- desc 'The description of this' do
308
- tags ['not_configurable_tag', configuration[:a_configurable_tag]]
309
- end
310
- get 'location' do
311
- 'success'
312
- end
313
- end
314
- end
315
-
316
- it 'mounts the endpoint with the appropiate tags' do
317
- root_api.mount({ a_remounted_api => 'integer' }, with: { a_configurable_tag: 'a configured tag' })
318
- end
319
- end
320
-
321
- context 'on the ParamScope' do
322
- subject(:a_remounted_api) do
323
- Class.new(described_class) do
324
- params do
325
- requires configuration[:required_param], type: configuration[:required_type]
326
- end
327
-
328
- get 'location' do
329
- 'success'
330
- end
331
- end
332
- end
333
-
334
- it 'mounts the endpoint in the location it is configured' do
335
- root_api.mount({ a_remounted_api => 'string' }, with: { required_param: 'param_key', required_type: String })
336
- root_api.mount({ a_remounted_api => 'integer' }, with: { required_param: 'param_integer', required_type: Integer })
337
-
338
- get '/string/location', param_key: 'a'
339
- expect(last_response.body).to eq 'success'
340
-
341
- get '/string/location', param_integer: 1
342
- expect(last_response.status).to eq 400
343
-
344
- get '/integer/location', param_integer: 1
345
- expect(last_response.body).to eq 'success'
346
-
347
- get '/integer/location', param_integer: 'a'
348
- expect(last_response.status).to eq 400
349
- end
350
-
351
- context 'on dynamic checks' do
352
- subject(:a_remounted_api) do
353
- Class.new(described_class) do
354
- params do
355
- optional :restricted_values, values: -> { [configuration[:allowed_value], 'always'] }
356
- end
357
-
358
- get 'location' do
359
- 'success'
360
- end
361
- end
362
- end
363
-
364
- it 'can read the configuration on lambdas' do
365
- root_api.mount a_remounted_api, with: { allowed_value: 'sometimes' }
366
- get '/location', restricted_values: 'always'
367
- expect(last_response.body).to eq 'success'
368
- get '/location', restricted_values: 'sometimes'
369
- expect(last_response.body).to eq 'success'
370
- get '/location', restricted_values: 'never'
371
- expect(last_response.status).to eq 400
372
- end
373
- end
374
- end
375
-
376
- context 'when the configuration is read within a namespace' do
377
- before do
378
- a_remounted_api.namespace 'api' do
379
- params do
380
- requires configuration[:required_param]
381
- end
382
- get "/#{configuration[:path]}" do
383
- '10 votes'
384
- end
385
- end
386
- root_api.mount a_remounted_api, with: { path: 'votes', required_param: 'param_key' }
387
- root_api.mount a_remounted_api, with: { path: 'scores', required_param: 'param_key' }
388
- end
389
-
390
- it 'will use the dynamic configuration on all routes' do
391
- get 'api/votes', param_key: 'a'
392
- expect(last_response.body).to eql '10 votes'
393
- get 'api/scores', param_key: 'a'
394
- expect(last_response.body).to eql '10 votes'
395
- get 'api/votes'
396
- expect(last_response.status).to eq 400
397
- end
398
- end
399
-
400
- context 'a very complex configuration example' do
401
- before do
402
- top_level_api = Class.new(described_class) do
403
- remounted_api = Class.new(Grape::API) do
404
- get configuration[:endpoint_name] do
405
- configuration[:response]
406
- end
407
- end
408
-
409
- expression_namespace = mounted { configuration[:namespace].to_s * 2 }
410
- given(mounted { configuration[:should_mount_expressed] != false }) do
411
- namespace expression_namespace do
412
- mount remounted_api, with: { endpoint_name: configuration[:endpoint_name], response: configuration[:endpoint_response] }
413
- end
414
- end
415
- end
416
- root_api.mount top_level_api, with: configuration_options
417
- end
418
-
419
- context 'when the namespace should be mounted' do
420
- let(:configuration_options) do
421
- {
422
- should_mount_expressed: true,
423
- namespace: 'bang',
424
- endpoint_name: 'james',
425
- endpoint_response: 'bond'
426
- }
427
- end
428
-
429
- it 'gets a response' do
430
- get 'bangbang/james'
431
- expect(last_response.body).to eq 'bond'
432
- end
433
- end
434
-
435
- context 'when should be mounted is nil' do
436
- let(:configuration_options) do
437
- {
438
- should_mount_expressed: nil,
439
- namespace: 'bang',
440
- endpoint_name: 'james',
441
- endpoint_response: 'bond'
442
- }
443
- end
444
-
445
- it 'gets a response' do
446
- get 'bangbang/james'
447
- expect(last_response.body).to eq 'bond'
448
- end
449
- end
450
-
451
- context 'when it should not be mounted' do
452
- let(:configuration_options) do
453
- {
454
- should_mount_expressed: false,
455
- namespace: 'bang',
456
- endpoint_name: 'james',
457
- endpoint_response: 'bond'
458
- }
459
- end
460
-
461
- it 'gets a response' do
462
- get 'bangbang/james'
463
- expect(last_response.body).not_to eq 'bond'
464
- end
465
- end
466
- end
467
-
468
- context 'when the configuration is read in a helper' do
469
- subject(:a_remounted_api) do
470
- Class.new(described_class) do
471
- helpers do
472
- def printed_response
473
- configuration[:some_value]
474
- end
475
- end
476
-
477
- get 'location' do
478
- printed_response
479
- end
480
- end
481
- end
482
-
483
- it 'will use the dynamic configuration on all routes' do
484
- root_api.mount(a_remounted_api, with: { some_value: 'response value' })
485
-
486
- get '/location'
487
- expect(last_response.body).to eq 'response value'
488
- end
489
- end
490
-
491
- context 'when the configuration is read within the response block' do
492
- subject(:a_remounted_api) do
493
- Class.new(described_class) do
494
- get 'location' do
495
- configuration[:some_value]
496
- end
497
- end
498
- end
499
-
500
- it 'will use the dynamic configuration on all routes' do
501
- root_api.mount(a_remounted_api, with: { some_value: 'response value' })
502
-
503
- get '/location'
504
- expect(last_response.body).to eq 'response value'
505
- end
506
- end
507
- end
508
- end
509
- end