grape 1.5.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.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/CONTRIBUTING.md +2 -1
  4. data/README.md +31 -3
  5. data/UPGRADING.md +46 -4
  6. data/grape.gemspec +5 -5
  7. data/lib/grape/api/instance.rb +13 -17
  8. data/lib/grape/api.rb +17 -12
  9. data/lib/grape/cookies.rb +2 -0
  10. data/lib/grape/dsl/desc.rb +3 -5
  11. data/lib/grape/dsl/headers.rb +5 -2
  12. data/lib/grape/dsl/helpers.rb +7 -5
  13. data/lib/grape/dsl/inside_route.rb +17 -8
  14. data/lib/grape/dsl/middleware.rb +4 -4
  15. data/lib/grape/dsl/parameters.rb +3 -3
  16. data/lib/grape/dsl/request_response.rb +9 -6
  17. data/lib/grape/dsl/routing.rb +2 -2
  18. data/lib/grape/dsl/settings.rb +5 -5
  19. data/lib/grape/endpoint.rb +20 -35
  20. data/lib/grape/error_formatter/json.rb +2 -6
  21. data/lib/grape/error_formatter/xml.rb +2 -6
  22. data/lib/grape/exceptions/validation.rb +1 -2
  23. data/lib/grape/formatter/json.rb +1 -0
  24. data/lib/grape/formatter/serializable_hash.rb +2 -1
  25. data/lib/grape/formatter/xml.rb +1 -0
  26. data/lib/grape/middleware/auth/dsl.rb +7 -1
  27. data/lib/grape/middleware/base.rb +3 -1
  28. data/lib/grape/middleware/formatter.rb +4 -4
  29. data/lib/grape/middleware/stack.rb +2 -2
  30. data/lib/grape/middleware/versioner/accept_version_header.rb +3 -5
  31. data/lib/grape/middleware/versioner/header.rb +6 -4
  32. data/lib/grape/middleware/versioner/param.rb +1 -0
  33. data/lib/grape/middleware/versioner/parse_media_type_patch.rb +2 -1
  34. data/lib/grape/middleware/versioner/path.rb +2 -0
  35. data/lib/grape/path.rb +1 -0
  36. data/lib/grape/request.rb +1 -0
  37. data/lib/grape/router/pattern.rb +1 -1
  38. data/lib/grape/router/route.rb +2 -2
  39. data/lib/grape/router.rb +6 -0
  40. data/lib/grape/util/inheritable_setting.rb +1 -3
  41. data/lib/grape/util/lazy_value.rb +3 -2
  42. data/lib/grape/util/strict_hash_configuration.rb +1 -1
  43. data/lib/grape/validations/params_scope.rb +88 -55
  44. data/lib/grape/validations/types/custom_type_coercer.rb +1 -0
  45. data/lib/grape/validations/types/dry_type_coercer.rb +1 -1
  46. data/lib/grape/validations/types/json.rb +2 -1
  47. data/lib/grape/validations/types/primitive_coercer.rb +3 -3
  48. data/lib/grape/validations/validators/all_or_none.rb +8 -5
  49. data/lib/grape/validations/validators/allow_blank.rb +9 -7
  50. data/lib/grape/validations/validators/as.rb +6 -8
  51. data/lib/grape/validations/validators/at_least_one_of.rb +7 -4
  52. data/lib/grape/validations/validators/base.rb +75 -70
  53. data/lib/grape/validations/validators/coerce.rb +63 -79
  54. data/lib/grape/validations/validators/default.rb +37 -34
  55. data/lib/grape/validations/validators/exactly_one_of.rb +9 -6
  56. data/lib/grape/validations/validators/except_values.rb +13 -11
  57. data/lib/grape/validations/validators/multiple_params_base.rb +24 -20
  58. data/lib/grape/validations/validators/mutual_exclusion.rb +8 -5
  59. data/lib/grape/validations/validators/presence.rb +7 -4
  60. data/lib/grape/validations/validators/regexp.rb +8 -5
  61. data/lib/grape/validations/validators/same_as.rb +18 -15
  62. data/lib/grape/validations/validators/values.rb +61 -56
  63. data/lib/grape/validations.rb +6 -0
  64. data/lib/grape/version.rb +1 -1
  65. data/lib/grape.rb +3 -1
  66. data/spec/grape/api/custom_validations_spec.rb +77 -45
  67. data/spec/grape/api/deeply_included_options_spec.rb +3 -3
  68. data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -1
  69. data/spec/grape/api/invalid_format_spec.rb +2 -0
  70. data/spec/grape/api/recognize_path_spec.rb +1 -1
  71. data/spec/grape/api/routes_with_requirements_spec.rb +8 -8
  72. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -15
  73. data/spec/grape/api_remount_spec.rb +16 -15
  74. data/spec/grape/api_spec.rb +440 -227
  75. data/spec/grape/dsl/callbacks_spec.rb +2 -1
  76. data/spec/grape/dsl/headers_spec.rb +39 -9
  77. data/spec/grape/dsl/helpers_spec.rb +3 -2
  78. data/spec/grape/dsl/inside_route_spec.rb +6 -4
  79. data/spec/grape/dsl/logger_spec.rb +16 -18
  80. data/spec/grape/dsl/middleware_spec.rb +2 -1
  81. data/spec/grape/dsl/parameters_spec.rb +2 -0
  82. data/spec/grape/dsl/request_response_spec.rb +1 -0
  83. data/spec/grape/dsl/routing_spec.rb +10 -7
  84. data/spec/grape/endpoint/declared_spec.rb +259 -12
  85. data/spec/grape/endpoint_spec.rb +64 -55
  86. data/spec/grape/entity_spec.rb +22 -22
  87. data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -0
  88. data/spec/grape/exceptions/invalid_accept_header_spec.rb +61 -22
  89. data/spec/grape/exceptions/validation_errors_spec.rb +13 -10
  90. data/spec/grape/exceptions/validation_spec.rb +5 -3
  91. data/spec/grape/extensions/param_builders/hash_spec.rb +7 -7
  92. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -8
  93. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -8
  94. data/spec/grape/integration/rack_sendfile_spec.rb +1 -1
  95. data/spec/grape/loading_spec.rb +8 -8
  96. data/spec/grape/middleware/auth/dsl_spec.rb +15 -6
  97. data/spec/grape/middleware/auth/strategies_spec.rb +60 -20
  98. data/spec/grape/middleware/base_spec.rb +24 -15
  99. data/spec/grape/middleware/error_spec.rb +2 -2
  100. data/spec/grape/middleware/exception_spec.rb +111 -161
  101. data/spec/grape/middleware/formatter_spec.rb +27 -6
  102. data/spec/grape/middleware/globals_spec.rb +7 -4
  103. data/spec/grape/middleware/stack_spec.rb +14 -12
  104. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -1
  105. data/spec/grape/middleware/versioner/header_spec.rb +14 -13
  106. data/spec/grape/middleware/versioner/param_spec.rb +7 -1
  107. data/spec/grape/middleware/versioner/path_spec.rb +5 -1
  108. data/spec/grape/middleware/versioner_spec.rb +1 -1
  109. data/spec/grape/parser_spec.rb +4 -0
  110. data/spec/grape/path_spec.rb +52 -52
  111. data/spec/grape/presenters/presenter_spec.rb +7 -6
  112. data/spec/grape/request_spec.rb +6 -4
  113. data/spec/grape/util/inheritable_setting_spec.rb +7 -7
  114. data/spec/grape/util/inheritable_values_spec.rb +3 -2
  115. data/spec/grape/util/reverse_stackable_values_spec.rb +3 -1
  116. data/spec/grape/util/stackable_values_spec.rb +7 -5
  117. data/spec/grape/validations/instance_behaivour_spec.rb +9 -10
  118. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +1 -0
  119. data/spec/grape/validations/params_scope_spec.rb +46 -10
  120. data/spec/grape/validations/single_attribute_iterator_spec.rb +2 -1
  121. data/spec/grape/validations/types/primitive_coercer_spec.rb +4 -4
  122. data/spec/grape/validations/types_spec.rb +8 -8
  123. data/spec/grape/validations/validators/all_or_none_spec.rb +50 -56
  124. data/spec/grape/validations/validators/allow_blank_spec.rb +136 -140
  125. data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -56
  126. data/spec/grape/validations/validators/coerce_spec.rb +23 -22
  127. data/spec/grape/validations/validators/default_spec.rb +72 -78
  128. data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -77
  129. data/spec/grape/validations/validators/except_values_spec.rb +3 -3
  130. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -77
  131. data/spec/grape/validations/validators/presence_spec.rb +16 -1
  132. data/spec/grape/validations/validators/regexp_spec.rb +25 -31
  133. data/spec/grape/validations/validators/same_as_spec.rb +14 -20
  134. data/spec/grape/validations/validators/values_spec.rb +183 -178
  135. data/spec/grape/validations_spec.rb +99 -58
  136. data/spec/integration/eager_load/eager_load_spec.rb +2 -2
  137. data/spec/integration/multi_json/json_spec.rb +1 -1
  138. data/spec/integration/multi_xml/xml_spec.rb +1 -1
  139. data/spec/shared/versioning_examples.rb +12 -9
  140. data/spec/spec_helper.rb +12 -2
  141. data/spec/support/basic_auth_encode_helpers.rb +1 -1
  142. metadata +103 -103
@@ -4,17 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  describe Grape::Validations do
6
6
  context 'using a custom length validator' do
7
- before do
8
- module CustomValidationsSpec
9
- class DefaultLength < Grape::Validations::Base
10
- def validate_param!(attr_name, params)
11
- @option = params[:max].to_i if params.key?(:max)
12
- return if params[attr_name].length <= @option
13
- raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long")
14
- end
15
- end
16
- end
17
- end
18
7
  subject do
19
8
  Class.new(Grape::API) do
20
9
  params do
@@ -26,6 +15,25 @@ describe Grape::Validations do
26
15
  end
27
16
  end
28
17
 
18
+ let(:default_length_validator) do
19
+ Class.new(Grape::Validations::Validators::Base) do
20
+ def validate_param!(attr_name, params)
21
+ @option = params[:max].to_i if params.key?(:max)
22
+ return if params[attr_name].length <= @option
23
+
24
+ raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long")
25
+ end
26
+ end
27
+ end
28
+
29
+ before do
30
+ described_class.register_validator('default_length', default_length_validator)
31
+ end
32
+
33
+ after do
34
+ described_class.deregister_validator('default_length')
35
+ end
36
+
29
37
  def app
30
38
  subject
31
39
  end
@@ -35,11 +43,13 @@ describe Grape::Validations do
35
43
  expect(last_response.status).to eq 200
36
44
  expect(last_response.body).to eq 'bacon'
37
45
  end
46
+
38
47
  it 'over 140 characters' do
39
48
  get '/', text: 'a' * 141
40
49
  expect(last_response.status).to eq 400
41
50
  expect(last_response.body).to eq 'text must be at the most 140 characters long'
42
51
  end
52
+
43
53
  it 'specified in the query string' do
44
54
  get '/', text: 'a' * 141, max: 141
45
55
  expect(last_response.status).to eq 200
@@ -48,15 +58,6 @@ describe Grape::Validations do
48
58
  end
49
59
 
50
60
  context 'using a custom body-only validator' do
51
- before do
52
- module CustomValidationsSpec
53
- class InBody < Grape::Validations::PresenceValidator
54
- def validate(request)
55
- validate!(request.env['api.request.body'])
56
- end
57
- end
58
- end
59
- end
60
61
  subject do
61
62
  Class.new(Grape::API) do
62
63
  params do
@@ -68,6 +69,22 @@ describe Grape::Validations do
68
69
  end
69
70
  end
70
71
 
72
+ let(:in_body_validator) do
73
+ Class.new(Grape::Validations::Validators::PresenceValidator) do
74
+ def validate(request)
75
+ validate!(request.env['api.request.body'])
76
+ end
77
+ end
78
+ end
79
+
80
+ before do
81
+ described_class.register_validator('in_body', in_body_validator)
82
+ end
83
+
84
+ after do
85
+ described_class.deregister_validator('in_body')
86
+ end
87
+
71
88
  def app
72
89
  subject
73
90
  end
@@ -77,6 +94,7 @@ describe Grape::Validations do
77
94
  expect(last_response.status).to eq 200
78
95
  expect(last_response.body).to eq 'bacon'
79
96
  end
97
+
80
98
  it 'ignores field in query' do
81
99
  get '/', nil, text: 'abc'
82
100
  expect(last_response.status).to eq 400
@@ -85,15 +103,6 @@ describe Grape::Validations do
85
103
  end
86
104
 
87
105
  context 'using a custom validator with message_key' do
88
- before do
89
- module CustomValidationsSpec
90
- class WithMessageKey < Grape::Validations::PresenceValidator
91
- def validate_param!(attr_name, _params)
92
- raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: :presence)
93
- end
94
- end
95
- end
96
- end
97
106
  subject do
98
107
  Class.new(Grape::API) do
99
108
  params do
@@ -105,6 +114,22 @@ describe Grape::Validations do
105
114
  end
106
115
  end
107
116
 
117
+ let(:message_key_validator) do
118
+ Class.new(Grape::Validations::Validators::PresenceValidator) do
119
+ def validate_param!(attr_name, _params)
120
+ raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: :presence)
121
+ end
122
+ end
123
+ end
124
+
125
+ before do
126
+ described_class.register_validator('with_message_key', message_key_validator)
127
+ end
128
+
129
+ after do
130
+ described_class.deregister_validator('with_message_key')
131
+ end
132
+
108
133
  def app
109
134
  subject
110
135
  end
@@ -117,22 +142,6 @@ describe Grape::Validations do
117
142
  end
118
143
 
119
144
  context 'using a custom request/param validator' do
120
- before do
121
- module CustomValidationsSpec
122
- class Admin < Grape::Validations::Base
123
- def validate(request)
124
- # return if the param we are checking was not in request
125
- # @attrs is a list containing the attribute we are currently validating
126
- return unless request.params.key? @attrs.first
127
- # check if admin flag is set to true
128
- return unless @option
129
- # check if user is admin or not
130
- # as an example get a token from request and check if it's admin or not
131
- raise Grape::Exceptions::Validation.new(params: @attrs, message: 'Can not set Admin only field.') unless request.headers['X-Access-Token'] == 'admin'
132
- end
133
- end
134
- end
135
- end
136
145
  subject do
137
146
  Class.new(Grape::API) do
138
147
  params do
@@ -146,6 +155,29 @@ describe Grape::Validations do
146
155
  end
147
156
  end
148
157
 
158
+ let(:admin_validator) do
159
+ Class.new(Grape::Validations::Validators::Base) do
160
+ def validate(request)
161
+ # return if the param we are checking was not in request
162
+ # @attrs is a list containing the attribute we are currently validating
163
+ return unless request.params.key? @attrs.first
164
+ # check if admin flag is set to true
165
+ return unless @option
166
+ # check if user is admin or not
167
+ # as an example get a token from request and check if it's admin or not
168
+ raise Grape::Exceptions::Validation.new(params: @attrs, message: 'Can not set Admin only field.') unless request.headers['X-Access-Token'] == 'admin'
169
+ end
170
+ end
171
+ end
172
+
173
+ before do
174
+ described_class.register_validator('admin', admin_validator)
175
+ end
176
+
177
+ after do
178
+ described_class.deregister_validator('admin')
179
+ end
180
+
149
181
  def app
150
182
  subject
151
183
  end
@@ -41,18 +41,18 @@ describe Grape::API do
41
41
 
42
42
  it 'works for unspecified format' do
43
43
  get '/users'
44
- expect(last_response.status).to eql 200
44
+ expect(last_response.status).to be 200
45
45
  expect(last_response.content_type).to eql 'application/json'
46
46
  end
47
47
 
48
48
  it 'works for specified format' do
49
49
  get '/users.json'
50
- expect(last_response.status).to eql 200
50
+ expect(last_response.status).to be 200
51
51
  expect(last_response.content_type).to eql 'application/json'
52
52
  end
53
53
 
54
54
  it "doesn't work for format different than specified" do
55
55
  get '/users.txt'
56
- expect(last_response.status).to eql 404
56
+ expect(last_response.status).to be 404
57
57
  end
58
58
  end
@@ -31,8 +31,9 @@ describe Grape::API::Instance do
31
31
 
32
32
  context 'Params endpoint type' do
33
33
  subject { DefinesBooleanInstanceSpec::API.new.router.map['POST'].first.options[:params]['message'][:type] }
34
+
34
35
  it 'params type is a boolean' do
35
- is_expected.to eq 'Grape::API::Boolean'
36
+ expect(subject).to eq 'Grape::API::Boolean'
36
37
  end
37
38
  end
38
39
  end
@@ -31,11 +31,13 @@ describe Grape::Endpoint do
31
31
  expect(last_response.status).to eq 200
32
32
  expect(last_response.body).to eq(::Grape::Json.dump(id: 'foo', format: nil))
33
33
  end
34
+
34
35
  it 'json format' do
35
36
  get '/foo.json'
36
37
  expect(last_response.status).to eq 200
37
38
  expect(last_response.body).to eq(::Grape::Json.dump(id: 'foo', format: 'json'))
38
39
  end
40
+
39
41
  it 'invalid format' do
40
42
  get '/foo.invalid'
41
43
  expect(last_response.status).to eq 200
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Grape::API do
6
6
  describe '.recognize_path' do
7
- subject { Class.new(Grape::API) }
7
+ subject { Class.new(described_class) }
8
8
 
9
9
  it 'fetches endpoint by given path' do
10
10
  subject.get('/foo/:id') {}
@@ -11,7 +11,7 @@ describe Grape::Endpoint do
11
11
 
12
12
  context 'get' do
13
13
  it 'routes to a namespace param with dots' do
14
- subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do
14
+ subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^/]+} } do
15
15
  get '/' do
16
16
  params[:ns_with_dots]
17
17
  end
@@ -23,8 +23,8 @@ describe Grape::Endpoint do
23
23
  end
24
24
 
25
25
  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{[^\/]+} } do
26
+ subject.get ':id_with_dots/:another_id_with_dots', requirements: { id_with_dots: %r{[^/]+},
27
+ another_id_with_dots: %r{[^/]+} } do
28
28
  "#{params[:id_with_dots]}/#{params[:another_id_with_dots]}"
29
29
  end
30
30
 
@@ -34,9 +34,9 @@ describe Grape::Endpoint do
34
34
  end
35
35
 
36
36
  it 'routes to namespace and path params with dots, with overridden requirements' do
37
- subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do
38
- get ':another_id_with_dots', requirements: { ns_with_dots: %r{[^\/]+},
39
- another_id_with_dots: %r{[^\/]+} } do
37
+ subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^/]+} } do
38
+ get ':another_id_with_dots', requirements: { ns_with_dots: %r{[^/]+},
39
+ another_id_with_dots: %r{[^/]+} } do
40
40
  "#{params[:ns_with_dots]}/#{params[:another_id_with_dots]}"
41
41
  end
42
42
  end
@@ -47,8 +47,8 @@ describe Grape::Endpoint do
47
47
  end
48
48
 
49
49
  it 'routes to namespace and path params with dots, with merged requirements' do
50
- subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do
51
- get ':another_id_with_dots', requirements: { another_id_with_dots: %r{[^\/]+} } do
50
+ subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^/]+} } do
51
+ get ':another_id_with_dots', requirements: { another_id_with_dots: %r{[^/]+} } do
52
52
  "#{params[:ns_with_dots]}/#{params[:another_id_with_dots]}"
53
53
  end
54
54
  end
@@ -3,19 +3,17 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Grape::API::Helpers do
6
- subject do
7
- shared_params = Module.new do
8
- extend Grape::API::Helpers
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ helpers Module.new do
9
+ extend Grape::API::Helpers
9
10
 
10
- params :drink do
11
- optional :beer
12
- optional :wine
13
- exactly_one_of :beer, :wine
11
+ params :drink do
12
+ optional :beer
13
+ optional :wine
14
+ exactly_one_of :beer, :wine
15
+ end
14
16
  end
15
- end
16
-
17
- Class.new(Grape::API) do
18
- helpers shared_params
19
17
  format :json
20
18
 
21
19
  params do
@@ -35,10 +33,6 @@ describe Grape::API::Helpers do
35
33
  end
36
34
  end
37
35
 
38
- def app
39
- subject
40
- end
41
-
42
36
  it 'defines parameters' do
43
37
  get '/', orderType: 'food', pizza: 'mista'
44
38
  expect(last_response.status).to eq 200
@@ -4,8 +4,9 @@ require 'spec_helper'
4
4
  require 'shared/versioning_examples'
5
5
 
6
6
  describe Grape::API do
7
- subject(:a_remounted_api) { Class.new(Grape::API) }
8
- let(:root_api) { Class.new(Grape::API) }
7
+ subject(:a_remounted_api) { Class.new(described_class) }
8
+
9
+ let(:root_api) { Class.new(described_class) }
9
10
 
10
11
  def app
11
12
  root_api
@@ -68,7 +69,7 @@ describe Grape::API do
68
69
  describe 'with dynamic configuration' do
69
70
  context 'when mounting an endpoint conditional on a configuration' do
70
71
  subject(:a_remounted_api) do
71
- Class.new(Grape::API) do
72
+ Class.new(described_class) do
72
73
  get 'always' do
73
74
  'success'
74
75
  end
@@ -101,7 +102,7 @@ describe Grape::API do
101
102
 
102
103
  context 'when using an expression derived from a configuration' do
103
104
  subject(:a_remounted_api) do
104
- Class.new(Grape::API) do
105
+ Class.new(described_class) do
105
106
  get(mounted { "api_name_#{configuration[:api_name]}" }) do
106
107
  'success'
107
108
  end
@@ -126,7 +127,7 @@ describe Grape::API do
126
127
 
127
128
  context 'when the expression lives in a namespace' do
128
129
  subject(:a_remounted_api) do
129
- Class.new(Grape::API) do
130
+ Class.new(described_class) do
130
131
  namespace :base do
131
132
  get(mounted { "api_name_#{configuration[:api_name]}" }) do
132
133
  'success'
@@ -149,7 +150,7 @@ describe Grape::API do
149
150
 
150
151
  context 'when executing a standard block within a `mounted` block with all dynamic params' do
151
152
  subject(:a_remounted_api) do
152
- Class.new(Grape::API) do
153
+ Class.new(described_class) do
153
154
  mounted do
154
155
  desc configuration[:description] do
155
156
  headers configuration[:headers]
@@ -191,7 +192,7 @@ describe Grape::API do
191
192
 
192
193
  context 'when executing a custom block on mount' do
193
194
  subject(:a_remounted_api) do
194
- Class.new(Grape::API) do
195
+ Class.new(described_class) do
195
196
  get 'always' do
196
197
  'success'
197
198
  end
@@ -215,7 +216,7 @@ describe Grape::API do
215
216
 
216
217
  context 'when the configuration is part of the arguments of a method' do
217
218
  subject(:a_remounted_api) do
218
- Class.new(Grape::API) do
219
+ Class.new(described_class) do
219
220
  get configuration[:endpoint_name] do
220
221
  'success'
221
222
  end
@@ -237,7 +238,7 @@ describe Grape::API do
237
238
 
238
239
  context 'when the configuration is the value in a key-arg pair' do
239
240
  subject(:a_remounted_api) do
240
- Class.new(Grape::API) do
241
+ Class.new(described_class) do
241
242
  version 'v1', using: :param, parameter: configuration[:version_param]
242
243
  get 'endpoint' do
243
244
  'version 1'
@@ -267,7 +268,7 @@ describe Grape::API do
267
268
 
268
269
  context 'on the DescSCope' do
269
270
  subject(:a_remounted_api) do
270
- Class.new(Grape::API) do
271
+ Class.new(described_class) do
271
272
  desc 'The description of this' do
272
273
  tags ['not_configurable_tag', configuration[:a_configurable_tag]]
273
274
  end
@@ -284,7 +285,7 @@ describe Grape::API do
284
285
 
285
286
  context 'on the ParamScope' do
286
287
  subject(:a_remounted_api) do
287
- Class.new(Grape::API) do
288
+ Class.new(described_class) do
288
289
  params do
289
290
  requires configuration[:required_param], type: configuration[:required_type]
290
291
  end
@@ -314,7 +315,7 @@ describe Grape::API do
314
315
 
315
316
  context 'on dynamic checks' do
316
317
  subject(:a_remounted_api) do
317
- Class.new(Grape::API) do
318
+ Class.new(described_class) do
318
319
  params do
319
320
  optional :restricted_values, values: -> { [configuration[:allowed_value], 'always'] }
320
321
  end
@@ -363,7 +364,7 @@ describe Grape::API do
363
364
 
364
365
  context 'a very complex configuration example' do
365
366
  before do
366
- top_level_api = Class.new(Grape::API) do
367
+ top_level_api = Class.new(described_class) do
367
368
  remounted_api = Class.new(Grape::API) do
368
369
  get configuration[:endpoint_name] do
369
370
  configuration[:response]
@@ -431,7 +432,7 @@ describe Grape::API do
431
432
 
432
433
  context 'when the configuration is read in a helper' do
433
434
  subject(:a_remounted_api) do
434
- Class.new(Grape::API) do
435
+ Class.new(described_class) do
435
436
  helpers do
436
437
  def printed_response
437
438
  configuration[:some_value]
@@ -454,7 +455,7 @@ describe Grape::API do
454
455
 
455
456
  context 'when the configuration is read within the response block' do
456
457
  subject(:a_remounted_api) do
457
- Class.new(Grape::API) do
458
+ Class.new(described_class) do
458
459
  get 'location' do
459
460
  configuration[:some_value]
460
461
  end