grape 1.5.2 → 1.7.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 +75 -0
- data/CONTRIBUTING.md +2 -1
- data/README.md +152 -21
- data/UPGRADING.md +86 -2
- data/grape.gemspec +5 -5
- data/lib/grape/api/instance.rb +14 -18
- data/lib/grape/api.rb +18 -13
- data/lib/grape/cookies.rb +2 -0
- data/lib/grape/dry_types.rb +12 -0
- data/lib/grape/dsl/api.rb +0 -2
- data/lib/grape/dsl/callbacks.rb +0 -2
- data/lib/grape/dsl/configuration.rb +0 -2
- data/lib/grape/dsl/desc.rb +2 -19
- data/lib/grape/dsl/headers.rb +5 -2
- data/lib/grape/dsl/helpers.rb +7 -7
- data/lib/grape/dsl/inside_route.rb +43 -30
- data/lib/grape/dsl/middleware.rb +4 -6
- data/lib/grape/dsl/parameters.rb +8 -10
- data/lib/grape/dsl/request_response.rb +9 -8
- data/lib/grape/dsl/routing.rb +6 -4
- data/lib/grape/dsl/settings.rb +5 -7
- data/lib/grape/dsl/validations.rb +0 -15
- data/lib/grape/endpoint.rb +21 -36
- data/lib/grape/error_formatter/json.rb +9 -7
- data/lib/grape/error_formatter/xml.rb +2 -6
- data/lib/grape/exceptions/base.rb +2 -2
- data/lib/grape/exceptions/empty_message_body.rb +11 -0
- data/lib/grape/exceptions/missing_group_type.rb +8 -1
- data/lib/grape/exceptions/too_many_multipart_files.rb +11 -0
- data/lib/grape/exceptions/unsupported_group_type.rb +8 -1
- data/lib/grape/exceptions/validation.rb +1 -6
- 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 +9 -8
- data/lib/grape/middleware/auth/dsl.rb +7 -2
- data/lib/grape/middleware/base.rb +3 -1
- data/lib/grape/middleware/error.rb +2 -2
- data/lib/grape/middleware/formatter.rb +4 -4
- data/lib/grape/middleware/stack.rb +2 -2
- 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 +5 -0
- data/lib/grape/router/pattern.rb +1 -1
- data/lib/grape/router/route.rb +2 -2
- data/lib/grape/router.rb +6 -0
- data/lib/grape/util/inheritable_setting.rb +1 -3
- data/lib/grape/util/json.rb +2 -0
- data/lib/grape/util/lazy_value.rb +3 -2
- data/lib/grape/util/strict_hash_configuration.rb +1 -1
- data/lib/grape/validations/attributes_doc.rb +58 -0
- data/lib/grape/validations/params_scope.rb +137 -78
- data/lib/grape/validations/types/array_coercer.rb +0 -2
- data/lib/grape/validations/types/custom_type_coercer.rb +1 -2
- data/lib/grape/validations/types/dry_type_coercer.rb +4 -8
- data/lib/grape/validations/types/json.rb +2 -1
- data/lib/grape/validations/types/primitive_coercer.rb +16 -8
- data/lib/grape/validations/types/set_coercer.rb +0 -2
- data/lib/grape/validations/types.rb +98 -30
- data/lib/grape/validations/validators/all_or_none_of_validator.rb +16 -0
- data/lib/grape/validations/validators/allow_blank_validator.rb +20 -0
- data/lib/grape/validations/validators/as_validator.rb +14 -0
- data/lib/grape/validations/validators/at_least_one_of_validator.rb +15 -0
- data/lib/grape/validations/validators/base.rb +82 -70
- data/lib/grape/validations/validators/coerce_validator.rb +75 -0
- data/lib/grape/validations/validators/default_validator.rb +51 -0
- data/lib/grape/validations/validators/exactly_one_of_validator.rb +17 -0
- data/lib/grape/validations/validators/except_values_validator.rb +24 -0
- data/lib/grape/validations/validators/multiple_params_base.rb +24 -20
- data/lib/grape/validations/validators/mutual_exclusion_validator.rb +16 -0
- data/lib/grape/validations/validators/presence_validator.rb +15 -0
- data/lib/grape/validations/validators/regexp_validator.rb +16 -0
- data/lib/grape/validations/validators/same_as_validator.rb +29 -0
- data/lib/grape/validations/validators/values_validator.rb +88 -0
- data/lib/grape/validations.rb +16 -6
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +70 -29
- data/spec/grape/api/custom_validations_spec.rb +116 -45
- data/spec/grape/api/deeply_included_options_spec.rb +3 -5
- data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -3
- data/spec/grape/api/documentation_spec.rb +59 -0
- data/spec/grape/api/inherited_helpers_spec.rb +0 -2
- data/spec/grape/api/instance_spec.rb +0 -1
- data/spec/grape/api/invalid_format_spec.rb +2 -2
- data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/nested_helpers_spec.rb +0 -2
- data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/parameters_modification_spec.rb +0 -2
- data/spec/grape/api/patch_method_helpers_spec.rb +0 -2
- data/spec/grape/api/recognize_path_spec.rb +1 -3
- data/spec/grape/api/required_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -2
- data/spec/grape/api/routes_with_requirements_spec.rb +8 -10
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -17
- data/spec/grape/api/shared_helpers_spec.rb +0 -2
- data/spec/grape/api_remount_spec.rb +16 -16
- data/spec/grape/api_spec.rb +527 -224
- data/spec/grape/config_spec.rb +0 -2
- data/spec/grape/dsl/callbacks_spec.rb +2 -3
- data/spec/grape/dsl/configuration_spec.rb +0 -2
- data/spec/grape/dsl/desc_spec.rb +0 -2
- data/spec/grape/dsl/headers_spec.rb +39 -11
- data/spec/grape/dsl/helpers_spec.rb +3 -4
- data/spec/grape/dsl/inside_route_spec.rb +16 -16
- data/spec/grape/dsl/logger_spec.rb +15 -19
- data/spec/grape/dsl/middleware_spec.rb +2 -3
- data/spec/grape/dsl/parameters_spec.rb +2 -2
- data/spec/grape/dsl/request_response_spec.rb +7 -8
- data/spec/grape/dsl/routing_spec.rb +11 -10
- data/spec/grape/dsl/settings_spec.rb +0 -2
- data/spec/grape/dsl/validations_spec.rb +0 -17
- data/spec/grape/endpoint/declared_spec.rb +261 -16
- data/spec/grape/endpoint_spec.rb +98 -57
- data/spec/grape/entity_spec.rb +22 -23
- data/spec/grape/exceptions/base_spec.rb +16 -2
- data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -2
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +61 -24
- data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -2
- data/spec/grape/exceptions/invalid_response_spec.rb +0 -2
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +1 -3
- data/spec/grape/exceptions/missing_group_type_spec.rb +21 -0
- data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -2
- data/spec/grape/exceptions/missing_option_spec.rb +1 -3
- data/spec/grape/exceptions/unknown_options_spec.rb +0 -2
- data/spec/grape/exceptions/unknown_validator_spec.rb +0 -2
- data/spec/grape/exceptions/unsupported_group_type_spec.rb +23 -0
- data/spec/grape/exceptions/validation_errors_spec.rb +13 -11
- data/spec/grape/exceptions/validation_spec.rb +5 -5
- data/spec/grape/extensions/param_builders/hash_spec.rb +7 -9
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -10
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -10
- data/spec/grape/integration/global_namespace_function_spec.rb +0 -2
- data/spec/grape/integration/rack_sendfile_spec.rb +1 -3
- data/spec/grape/integration/rack_spec.rb +0 -2
- data/spec/grape/loading_spec.rb +8 -10
- data/spec/grape/middleware/auth/base_spec.rb +0 -1
- data/spec/grape/middleware/auth/dsl_spec.rb +15 -8
- data/spec/grape/middleware/auth/strategies_spec.rb +60 -22
- data/spec/grape/middleware/base_spec.rb +24 -17
- data/spec/grape/middleware/error_spec.rb +8 -3
- data/spec/grape/middleware/exception_spec.rb +111 -163
- data/spec/grape/middleware/formatter_spec.rb +27 -8
- data/spec/grape/middleware/globals_spec.rb +7 -6
- data/spec/grape/middleware/stack_spec.rb +14 -14
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -3
- data/spec/grape/middleware/versioner/header_spec.rb +30 -15
- data/spec/grape/middleware/versioner/param_spec.rb +7 -3
- data/spec/grape/middleware/versioner/path_spec.rb +5 -3
- data/spec/grape/middleware/versioner_spec.rb +1 -3
- data/spec/grape/named_api_spec.rb +0 -2
- data/spec/grape/parser_spec.rb +4 -2
- data/spec/grape/path_spec.rb +52 -54
- data/spec/grape/presenters/presenter_spec.rb +7 -8
- data/spec/grape/request_spec.rb +6 -6
- data/spec/grape/util/inheritable_setting_spec.rb +7 -8
- data/spec/grape/util/inheritable_values_spec.rb +3 -3
- data/spec/grape/util/reverse_stackable_values_spec.rb +3 -2
- data/spec/grape/util/stackable_values_spec.rb +7 -6
- data/spec/grape/util/strict_hash_configuration_spec.rb +0 -1
- data/spec/grape/validations/attributes_doc_spec.rb +153 -0
- data/spec/grape/validations/attributes_iterator_spec.rb +0 -2
- data/spec/grape/validations/instance_behaivour_spec.rb +9 -12
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +1 -2
- data/spec/grape/validations/params_scope_spec.rb +361 -96
- data/spec/grape/validations/single_attribute_iterator_spec.rb +2 -3
- data/spec/grape/validations/types/array_coercer_spec.rb +0 -2
- data/spec/grape/validations/types/primitive_coercer_spec.rb +24 -9
- data/spec/grape/validations/types/set_coercer_spec.rb +0 -2
- data/spec/grape/validations/types_spec.rb +36 -10
- data/spec/grape/validations/validators/all_or_none_spec.rb +50 -58
- data/spec/grape/validations/validators/allow_blank_spec.rb +135 -141
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -58
- data/spec/grape/validations/validators/coerce_spec.rb +99 -24
- data/spec/grape/validations/validators/default_spec.rb +72 -80
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -79
- data/spec/grape/validations/validators/except_values_spec.rb +3 -5
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -79
- data/spec/grape/validations/validators/presence_spec.rb +16 -3
- data/spec/grape/validations/validators/regexp_spec.rb +25 -33
- data/spec/grape/validations/validators/same_as_spec.rb +14 -22
- data/spec/grape/validations/validators/values_spec.rb +182 -179
- data/spec/grape/validations_spec.rb +149 -80
- data/spec/integration/eager_load/eager_load_spec.rb +2 -2
- data/spec/integration/multi_json/json_spec.rb +1 -3
- data/spec/integration/multi_xml/xml_spec.rb +1 -3
- data/spec/shared/versioning_examples.rb +12 -9
- data/spec/spec_helper.rb +21 -6
- data/spec/support/basic_auth_encode_helpers.rb +1 -1
- metadata +125 -115
- data/lib/grape/validations/validators/all_or_none.rb +0 -15
- data/lib/grape/validations/validators/allow_blank.rb +0 -18
- data/lib/grape/validations/validators/as.rb +0 -16
- data/lib/grape/validations/validators/at_least_one_of.rb +0 -14
- data/lib/grape/validations/validators/coerce.rb +0 -91
- data/lib/grape/validations/validators/default.rb +0 -48
- data/lib/grape/validations/validators/exactly_one_of.rb +0 -16
- data/lib/grape/validations/validators/except_values.rb +0 -22
- data/lib/grape/validations/validators/mutual_exclusion.rb +0 -15
- data/lib/grape/validations/validators/presence.rb +0 -12
- data/lib/grape/validations/validators/regexp.rb +0 -13
- data/lib/grape/validations/validators/same_as.rb +0 -26
- data/lib/grape/validations/validators/values.rb +0 -83
- data/spec/support/eager_load.rb +0 -19
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::API::Instance do
|
6
4
|
describe 'boolean constant' do
|
7
5
|
module DefinesBooleanInstanceSpec
|
@@ -31,8 +29,9 @@ describe Grape::API::Instance do
|
|
31
29
|
|
32
30
|
context 'Params endpoint type' do
|
33
31
|
subject { DefinesBooleanInstanceSpec::API.new.router.map['POST'].first.options[:params]['message'][:type] }
|
32
|
+
|
34
33
|
it 'params type is a boolean' do
|
35
|
-
|
34
|
+
expect(subject).to eq 'Grape::API::Boolean'
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Grape::API do
|
6
|
+
subject { Class.new(described_class) }
|
7
|
+
|
8
|
+
let(:app) { subject }
|
9
|
+
|
10
|
+
context 'an endpoint with documentation' do
|
11
|
+
it 'documents parameters' do
|
12
|
+
subject.params do
|
13
|
+
requires 'price', type: Float, desc: 'Sales price'
|
14
|
+
end
|
15
|
+
subject.get '/'
|
16
|
+
|
17
|
+
expect(subject.routes.first.params['price']).to eq(required: true,
|
18
|
+
type: 'Float',
|
19
|
+
desc: 'Sales price')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'allows documentation with a hash' do
|
23
|
+
documentation = { example: 'Joe' }
|
24
|
+
|
25
|
+
subject.params do
|
26
|
+
requires 'first_name', documentation: documentation
|
27
|
+
end
|
28
|
+
subject.get '/'
|
29
|
+
|
30
|
+
expect(subject.routes.first.params['first_name'][:documentation]).to eq(documentation)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'an endpoint without documentation' do
|
35
|
+
before do
|
36
|
+
subject.do_not_document!
|
37
|
+
|
38
|
+
subject.params do
|
39
|
+
requires :city, type: String, desc: 'Should be ignored'
|
40
|
+
optional :postal_code, type: Integer
|
41
|
+
end
|
42
|
+
subject.post '/' do
|
43
|
+
declared(params).to_json
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'does not document parameters for the endpoint' do
|
48
|
+
expect(subject.routes.first.params).to eq({})
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'still declares params internally' do
|
52
|
+
data = { city: 'Berlin', postal_code: 10_115 }
|
53
|
+
|
54
|
+
post '/', data
|
55
|
+
|
56
|
+
expect(last_response.body).to eq(data.to_json)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Endpoint do
|
6
4
|
subject { Class.new(Grape::API) }
|
7
5
|
|
@@ -31,11 +29,13 @@ describe Grape::Endpoint do
|
|
31
29
|
expect(last_response.status).to eq 200
|
32
30
|
expect(last_response.body).to eq(::Grape::Json.dump(id: 'foo', format: nil))
|
33
31
|
end
|
32
|
+
|
34
33
|
it 'json format' do
|
35
34
|
get '/foo.json'
|
36
35
|
expect(last_response.status).to eq 200
|
37
36
|
expect(last_response.body).to eq(::Grape::Json.dump(id: 'foo', format: 'json'))
|
38
37
|
end
|
38
|
+
|
39
39
|
it 'invalid format' do
|
40
40
|
get '/foo.invalid'
|
41
41
|
expect(last_response.status).to eq 200
|
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::API do
|
6
4
|
describe '.recognize_path' do
|
7
|
-
subject { Class.new(
|
5
|
+
subject { Class.new(described_class) }
|
8
6
|
|
9
7
|
it 'fetches endpoint by given path' do
|
10
8
|
subject.get('/foo/:id') {}
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Endpoint do
|
6
4
|
subject { Class.new(Grape::API) }
|
7
5
|
|
@@ -11,7 +9,7 @@ describe Grape::Endpoint do
|
|
11
9
|
|
12
10
|
context 'get' do
|
13
11
|
it 'routes to a namespace param with dots' do
|
14
|
-
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[
|
12
|
+
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^/]+} } do
|
15
13
|
get '/' do
|
16
14
|
params[:ns_with_dots]
|
17
15
|
end
|
@@ -23,8 +21,8 @@ describe Grape::Endpoint do
|
|
23
21
|
end
|
24
22
|
|
25
23
|
it 'routes to a path with multiple params with dots' do
|
26
|
-
subject.get ':id_with_dots/:another_id_with_dots', requirements: { id_with_dots: %r{[
|
27
|
-
another_id_with_dots: %r{[
|
24
|
+
subject.get ':id_with_dots/:another_id_with_dots', requirements: { id_with_dots: %r{[^/]+},
|
25
|
+
another_id_with_dots: %r{[^/]+} } do
|
28
26
|
"#{params[:id_with_dots]}/#{params[:another_id_with_dots]}"
|
29
27
|
end
|
30
28
|
|
@@ -34,9 +32,9 @@ describe Grape::Endpoint do
|
|
34
32
|
end
|
35
33
|
|
36
34
|
it 'routes to namespace and path params with dots, with overridden requirements' do
|
37
|
-
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[
|
38
|
-
get ':another_id_with_dots', requirements: { ns_with_dots: %r{[
|
39
|
-
another_id_with_dots: %r{[
|
35
|
+
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^/]+} } do
|
36
|
+
get ':another_id_with_dots', requirements: { ns_with_dots: %r{[^/]+},
|
37
|
+
another_id_with_dots: %r{[^/]+} } do
|
40
38
|
"#{params[:ns_with_dots]}/#{params[:another_id_with_dots]}"
|
41
39
|
end
|
42
40
|
end
|
@@ -47,8 +45,8 @@ describe Grape::Endpoint do
|
|
47
45
|
end
|
48
46
|
|
49
47
|
it 'routes to namespace and path params with dots, with merged requirements' do
|
50
|
-
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[
|
51
|
-
get ':another_id_with_dots', requirements: { another_id_with_dots: %r{[
|
48
|
+
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^/]+} } do
|
49
|
+
get ':another_id_with_dots', requirements: { another_id_with_dots: %r{[^/]+} } do
|
52
50
|
"#{params[:ns_with_dots]}/#{params[:another_id_with_dots]}"
|
53
51
|
end
|
54
52
|
end
|
@@ -1,21 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::API::Helpers do
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
let(:app) do
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
helpers Module.new do
|
7
|
+
extend Grape::API::Helpers
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
params :drink do
|
10
|
+
optional :beer
|
11
|
+
optional :wine
|
12
|
+
exactly_one_of :beer, :wine
|
13
|
+
end
|
14
14
|
end
|
15
|
-
end
|
16
|
-
|
17
|
-
Class.new(Grape::API) do
|
18
|
-
helpers shared_params
|
19
15
|
format :json
|
20
16
|
|
21
17
|
params do
|
@@ -35,10 +31,6 @@ describe Grape::API::Helpers do
|
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
|
-
def app
|
39
|
-
subject
|
40
|
-
end
|
41
|
-
|
42
34
|
it 'defines parameters' do
|
43
35
|
get '/', orderType: 'food', pizza: 'mista'
|
44
36
|
expect(last_response.status).to eq 200
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
3
|
require 'shared/versioning_examples'
|
5
4
|
|
6
5
|
describe Grape::API do
|
7
|
-
subject(:a_remounted_api) { Class.new(
|
8
|
-
|
6
|
+
subject(:a_remounted_api) { Class.new(described_class) }
|
7
|
+
|
8
|
+
let(:root_api) { Class.new(described_class) }
|
9
9
|
|
10
10
|
def app
|
11
11
|
root_api
|
@@ -68,7 +68,7 @@ describe Grape::API do
|
|
68
68
|
describe 'with dynamic configuration' do
|
69
69
|
context 'when mounting an endpoint conditional on a configuration' do
|
70
70
|
subject(:a_remounted_api) do
|
71
|
-
Class.new(
|
71
|
+
Class.new(described_class) do
|
72
72
|
get 'always' do
|
73
73
|
'success'
|
74
74
|
end
|
@@ -101,7 +101,7 @@ describe Grape::API do
|
|
101
101
|
|
102
102
|
context 'when using an expression derived from a configuration' do
|
103
103
|
subject(:a_remounted_api) do
|
104
|
-
Class.new(
|
104
|
+
Class.new(described_class) do
|
105
105
|
get(mounted { "api_name_#{configuration[:api_name]}" }) do
|
106
106
|
'success'
|
107
107
|
end
|
@@ -126,7 +126,7 @@ describe Grape::API do
|
|
126
126
|
|
127
127
|
context 'when the expression lives in a namespace' do
|
128
128
|
subject(:a_remounted_api) do
|
129
|
-
Class.new(
|
129
|
+
Class.new(described_class) do
|
130
130
|
namespace :base do
|
131
131
|
get(mounted { "api_name_#{configuration[:api_name]}" }) do
|
132
132
|
'success'
|
@@ -149,7 +149,7 @@ describe Grape::API do
|
|
149
149
|
|
150
150
|
context 'when executing a standard block within a `mounted` block with all dynamic params' do
|
151
151
|
subject(:a_remounted_api) do
|
152
|
-
Class.new(
|
152
|
+
Class.new(described_class) do
|
153
153
|
mounted do
|
154
154
|
desc configuration[:description] do
|
155
155
|
headers configuration[:headers]
|
@@ -191,7 +191,7 @@ describe Grape::API do
|
|
191
191
|
|
192
192
|
context 'when executing a custom block on mount' do
|
193
193
|
subject(:a_remounted_api) do
|
194
|
-
Class.new(
|
194
|
+
Class.new(described_class) do
|
195
195
|
get 'always' do
|
196
196
|
'success'
|
197
197
|
end
|
@@ -215,7 +215,7 @@ describe Grape::API do
|
|
215
215
|
|
216
216
|
context 'when the configuration is part of the arguments of a method' do
|
217
217
|
subject(:a_remounted_api) do
|
218
|
-
Class.new(
|
218
|
+
Class.new(described_class) do
|
219
219
|
get configuration[:endpoint_name] do
|
220
220
|
'success'
|
221
221
|
end
|
@@ -237,7 +237,7 @@ describe Grape::API do
|
|
237
237
|
|
238
238
|
context 'when the configuration is the value in a key-arg pair' do
|
239
239
|
subject(:a_remounted_api) do
|
240
|
-
Class.new(
|
240
|
+
Class.new(described_class) do
|
241
241
|
version 'v1', using: :param, parameter: configuration[:version_param]
|
242
242
|
get 'endpoint' do
|
243
243
|
'version 1'
|
@@ -267,7 +267,7 @@ describe Grape::API do
|
|
267
267
|
|
268
268
|
context 'on the DescSCope' do
|
269
269
|
subject(:a_remounted_api) do
|
270
|
-
Class.new(
|
270
|
+
Class.new(described_class) do
|
271
271
|
desc 'The description of this' do
|
272
272
|
tags ['not_configurable_tag', configuration[:a_configurable_tag]]
|
273
273
|
end
|
@@ -284,7 +284,7 @@ describe Grape::API do
|
|
284
284
|
|
285
285
|
context 'on the ParamScope' do
|
286
286
|
subject(:a_remounted_api) do
|
287
|
-
Class.new(
|
287
|
+
Class.new(described_class) do
|
288
288
|
params do
|
289
289
|
requires configuration[:required_param], type: configuration[:required_type]
|
290
290
|
end
|
@@ -314,7 +314,7 @@ describe Grape::API do
|
|
314
314
|
|
315
315
|
context 'on dynamic checks' do
|
316
316
|
subject(:a_remounted_api) do
|
317
|
-
Class.new(
|
317
|
+
Class.new(described_class) do
|
318
318
|
params do
|
319
319
|
optional :restricted_values, values: -> { [configuration[:allowed_value], 'always'] }
|
320
320
|
end
|
@@ -363,7 +363,7 @@ describe Grape::API do
|
|
363
363
|
|
364
364
|
context 'a very complex configuration example' do
|
365
365
|
before do
|
366
|
-
top_level_api = Class.new(
|
366
|
+
top_level_api = Class.new(described_class) do
|
367
367
|
remounted_api = Class.new(Grape::API) do
|
368
368
|
get configuration[:endpoint_name] do
|
369
369
|
configuration[:response]
|
@@ -431,7 +431,7 @@ describe Grape::API do
|
|
431
431
|
|
432
432
|
context 'when the configuration is read in a helper' do
|
433
433
|
subject(:a_remounted_api) do
|
434
|
-
Class.new(
|
434
|
+
Class.new(described_class) do
|
435
435
|
helpers do
|
436
436
|
def printed_response
|
437
437
|
configuration[:some_value]
|
@@ -454,7 +454,7 @@ describe Grape::API do
|
|
454
454
|
|
455
455
|
context 'when the configuration is read within the response block' do
|
456
456
|
subject(:a_remounted_api) do
|
457
|
-
Class.new(
|
457
|
+
Class.new(described_class) do
|
458
458
|
get 'location' do
|
459
459
|
configuration[:some_value]
|
460
460
|
end
|