grape 1.3.3 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -2
  3. data/CONTRIBUTING.md +2 -1
  4. data/README.md +135 -23
  5. data/UPGRADING.md +237 -46
  6. data/grape.gemspec +5 -5
  7. data/lib/grape/api/instance.rb +34 -42
  8. data/lib/grape/api.rb +21 -16
  9. data/lib/grape/cookies.rb +2 -0
  10. data/lib/grape/dsl/callbacks.rb +1 -1
  11. data/lib/grape/dsl/desc.rb +3 -5
  12. data/lib/grape/dsl/headers.rb +5 -2
  13. data/lib/grape/dsl/helpers.rb +8 -5
  14. data/lib/grape/dsl/inside_route.rb +72 -53
  15. data/lib/grape/dsl/middleware.rb +4 -4
  16. data/lib/grape/dsl/parameters.rb +11 -7
  17. data/lib/grape/dsl/request_response.rb +9 -6
  18. data/lib/grape/dsl/routing.rb +8 -9
  19. data/lib/grape/dsl/settings.rb +5 -5
  20. data/lib/grape/dsl/validations.rb +18 -1
  21. data/lib/grape/eager_load.rb +1 -1
  22. data/lib/grape/endpoint.rb +29 -42
  23. data/lib/grape/error_formatter/json.rb +2 -6
  24. data/lib/grape/error_formatter/xml.rb +2 -6
  25. data/lib/grape/exceptions/empty_message_body.rb +11 -0
  26. data/lib/grape/exceptions/validation.rb +2 -3
  27. data/lib/grape/exceptions/validation_errors.rb +1 -1
  28. data/lib/grape/formatter/json.rb +1 -0
  29. data/lib/grape/formatter/serializable_hash.rb +2 -1
  30. data/lib/grape/formatter/xml.rb +1 -0
  31. data/lib/grape/locale/en.yml +1 -1
  32. data/lib/grape/middleware/auth/base.rb +3 -3
  33. data/lib/grape/middleware/auth/dsl.rb +7 -1
  34. data/lib/grape/middleware/base.rb +6 -3
  35. data/lib/grape/middleware/error.rb +11 -13
  36. data/lib/grape/middleware/formatter.rb +7 -7
  37. data/lib/grape/middleware/stack.rb +10 -3
  38. data/lib/grape/middleware/versioner/accept_version_header.rb +3 -5
  39. data/lib/grape/middleware/versioner/header.rb +6 -4
  40. data/lib/grape/middleware/versioner/param.rb +1 -0
  41. data/lib/grape/middleware/versioner/parse_media_type_patch.rb +2 -1
  42. data/lib/grape/middleware/versioner/path.rb +2 -0
  43. data/lib/grape/parser/json.rb +1 -1
  44. data/lib/grape/parser/xml.rb +1 -1
  45. data/lib/grape/path.rb +1 -0
  46. data/lib/grape/request.rb +4 -1
  47. data/lib/grape/router/attribute_translator.rb +3 -3
  48. data/lib/grape/router/pattern.rb +1 -1
  49. data/lib/grape/router/route.rb +2 -2
  50. data/lib/grape/router.rb +31 -30
  51. data/lib/grape/{serve_file → serve_stream}/file_body.rb +1 -1
  52. data/lib/grape/{serve_file → serve_stream}/sendfile_response.rb +1 -1
  53. data/lib/grape/{serve_file/file_response.rb → serve_stream/stream_response.rb} +8 -8
  54. data/lib/grape/util/base_inheritable.rb +2 -2
  55. data/lib/grape/util/inheritable_setting.rb +1 -3
  56. data/lib/grape/util/lazy_value.rb +4 -2
  57. data/lib/grape/util/strict_hash_configuration.rb +1 -1
  58. data/lib/grape/validations/attributes_iterator.rb +8 -0
  59. data/lib/grape/validations/multiple_attributes_iterator.rb +1 -1
  60. data/lib/grape/validations/params_scope.rb +97 -62
  61. data/lib/grape/validations/single_attribute_iterator.rb +1 -1
  62. data/lib/grape/validations/types/custom_type_coercer.rb +16 -3
  63. data/lib/grape/validations/types/dry_type_coercer.rb +1 -1
  64. data/lib/grape/validations/types/invalid_value.rb +24 -0
  65. data/lib/grape/validations/types/json.rb +2 -1
  66. data/lib/grape/validations/types/primitive_coercer.rb +4 -5
  67. data/lib/grape/validations/types.rb +1 -4
  68. data/lib/grape/validations/validator_factory.rb +1 -1
  69. data/lib/grape/validations/validators/all_or_none.rb +8 -5
  70. data/lib/grape/validations/validators/allow_blank.rb +9 -7
  71. data/lib/grape/validations/validators/as.rb +6 -8
  72. data/lib/grape/validations/validators/at_least_one_of.rb +7 -4
  73. data/lib/grape/validations/validators/base.rb +74 -69
  74. data/lib/grape/validations/validators/coerce.rb +63 -76
  75. data/lib/grape/validations/validators/default.rb +36 -34
  76. data/lib/grape/validations/validators/exactly_one_of.rb +9 -6
  77. data/lib/grape/validations/validators/except_values.rb +13 -11
  78. data/lib/grape/validations/validators/multiple_params_base.rb +24 -19
  79. data/lib/grape/validations/validators/mutual_exclusion.rb +8 -5
  80. data/lib/grape/validations/validators/presence.rb +7 -4
  81. data/lib/grape/validations/validators/regexp.rb +8 -5
  82. data/lib/grape/validations/validators/same_as.rb +18 -15
  83. data/lib/grape/validations/validators/values.rb +61 -56
  84. data/lib/grape/validations.rb +6 -0
  85. data/lib/grape/version.rb +1 -1
  86. data/lib/grape.rb +7 -3
  87. data/spec/grape/api/custom_validations_spec.rb +77 -45
  88. data/spec/grape/api/deeply_included_options_spec.rb +3 -3
  89. data/spec/grape/api/defines_boolean_in_params_spec.rb +2 -1
  90. data/spec/grape/api/invalid_format_spec.rb +2 -0
  91. data/spec/grape/api/recognize_path_spec.rb +1 -1
  92. data/spec/grape/api/routes_with_requirements_spec.rb +8 -8
  93. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +9 -15
  94. data/spec/grape/api_remount_spec.rb +25 -19
  95. data/spec/grape/api_spec.rb +576 -211
  96. data/spec/grape/dsl/callbacks_spec.rb +2 -1
  97. data/spec/grape/dsl/headers_spec.rb +39 -9
  98. data/spec/grape/dsl/helpers_spec.rb +3 -2
  99. data/spec/grape/dsl/inside_route_spec.rb +185 -34
  100. data/spec/grape/dsl/logger_spec.rb +16 -18
  101. data/spec/grape/dsl/middleware_spec.rb +2 -1
  102. data/spec/grape/dsl/parameters_spec.rb +2 -0
  103. data/spec/grape/dsl/request_response_spec.rb +1 -0
  104. data/spec/grape/dsl/routing_spec.rb +10 -7
  105. data/spec/grape/endpoint/declared_spec.rb +848 -0
  106. data/spec/grape/endpoint_spec.rb +77 -589
  107. data/spec/grape/entity_spec.rb +29 -23
  108. data/spec/grape/exceptions/body_parse_errors_spec.rb +3 -0
  109. data/spec/grape/exceptions/invalid_accept_header_spec.rb +61 -22
  110. data/spec/grape/exceptions/validation_errors_spec.rb +13 -10
  111. data/spec/grape/exceptions/validation_spec.rb +5 -3
  112. data/spec/grape/extensions/param_builders/hash_spec.rb +7 -7
  113. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +8 -8
  114. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +8 -8
  115. data/spec/grape/integration/rack_sendfile_spec.rb +13 -9
  116. data/spec/grape/loading_spec.rb +8 -8
  117. data/spec/grape/middleware/auth/dsl_spec.rb +15 -6
  118. data/spec/grape/middleware/auth/strategies_spec.rb +61 -21
  119. data/spec/grape/middleware/base_spec.rb +24 -15
  120. data/spec/grape/middleware/error_spec.rb +3 -3
  121. data/spec/grape/middleware/exception_spec.rb +111 -161
  122. data/spec/grape/middleware/formatter_spec.rb +28 -7
  123. data/spec/grape/middleware/globals_spec.rb +7 -4
  124. data/spec/grape/middleware/stack_spec.rb +15 -12
  125. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +2 -1
  126. data/spec/grape/middleware/versioner/header_spec.rb +14 -13
  127. data/spec/grape/middleware/versioner/param_spec.rb +7 -1
  128. data/spec/grape/middleware/versioner/path_spec.rb +5 -1
  129. data/spec/grape/middleware/versioner_spec.rb +1 -1
  130. data/spec/grape/parser_spec.rb +4 -0
  131. data/spec/grape/path_spec.rb +52 -52
  132. data/spec/grape/presenters/presenter_spec.rb +7 -6
  133. data/spec/grape/request_spec.rb +6 -4
  134. data/spec/grape/util/inheritable_setting_spec.rb +7 -7
  135. data/spec/grape/util/inheritable_values_spec.rb +3 -2
  136. data/spec/grape/util/reverse_stackable_values_spec.rb +3 -1
  137. data/spec/grape/util/stackable_values_spec.rb +7 -5
  138. data/spec/grape/validations/instance_behaivour_spec.rb +9 -10
  139. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +14 -3
  140. data/spec/grape/validations/params_scope_spec.rb +72 -10
  141. data/spec/grape/validations/single_attribute_iterator_spec.rb +18 -6
  142. data/spec/grape/validations/types/primitive_coercer_spec.rb +63 -7
  143. data/spec/grape/validations/types_spec.rb +8 -8
  144. data/spec/grape/validations/validators/all_or_none_spec.rb +50 -56
  145. data/spec/grape/validations/validators/allow_blank_spec.rb +136 -140
  146. data/spec/grape/validations/validators/at_least_one_of_spec.rb +50 -56
  147. data/spec/grape/validations/validators/coerce_spec.rb +248 -33
  148. data/spec/grape/validations/validators/default_spec.rb +121 -78
  149. data/spec/grape/validations/validators/exactly_one_of_spec.rb +71 -77
  150. data/spec/grape/validations/validators/except_values_spec.rb +4 -3
  151. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +71 -77
  152. data/spec/grape/validations/validators/presence_spec.rb +16 -1
  153. data/spec/grape/validations/validators/regexp_spec.rb +25 -31
  154. data/spec/grape/validations/validators/same_as_spec.rb +14 -20
  155. data/spec/grape/validations/validators/values_spec.rb +183 -178
  156. data/spec/grape/validations_spec.rb +342 -29
  157. data/spec/integration/eager_load/eager_load_spec.rb +15 -0
  158. data/spec/integration/multi_json/json_spec.rb +1 -1
  159. data/spec/integration/multi_xml/xml_spec.rb +1 -1
  160. data/spec/shared/versioning_examples.rb +32 -29
  161. data/spec/spec_helper.rb +12 -12
  162. data/spec/support/basic_auth_encode_helpers.rb +1 -1
  163. data/spec/support/chunks.rb +14 -0
  164. data/spec/support/versioned_helpers.rb +4 -6
  165. metadata +110 -102
@@ -2,11 +2,12 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Grape::Validations::ValuesValidator do
6
- module ValidationsSpec
7
- class ValuesModel
8
- DEFAULT_VALUES = ['valid-type1', 'valid-type2', 'valid-type3'].freeze
9
- DEFAULT_EXCEPTS = ['invalid-type1', 'invalid-type2', 'invalid-type3'].freeze
5
+ describe Grape::Validations::Validators::ValuesValidator do
6
+ let_it_be(:values_model) do
7
+ Class.new do
8
+ DEFAULT_VALUES = %w[valid-type1 valid-type2 valid-type3].freeze
9
+ DEFAULT_EXCEPTS = %w[invalid-type1 invalid-type2 invalid-type3].freeze
10
+
10
11
  class << self
11
12
  def values
12
13
  @values ||= []
@@ -27,214 +28,219 @@ describe Grape::Validations::ValuesValidator do
27
28
  @excepts ||= []
28
29
  @excepts << except
29
30
  end
31
+
32
+ def include?(value)
33
+ values.include?(value)
34
+ end
30
35
  end
31
36
  end
37
+ end
32
38
 
33
- module ValuesValidatorSpec
34
- class API < Grape::API
35
- default_format :json
36
-
37
- resources :custom_message do
38
- params do
39
- requires :type, values: { value: ValuesModel.values, message: 'value does not include in values' }
40
- end
41
- get '/' do
42
- { type: params[:type] }
43
- end
44
-
45
- params do
46
- optional :type, values: { value: -> { ValuesModel.values }, message: 'value does not include in values' }, default: 'valid-type2'
47
- end
48
- get '/lambda' do
49
- { type: params[:type] }
50
- end
51
-
52
- params do
53
- requires :type, values: { except: ValuesModel.excepts, except_message: 'value is on exclusions list', message: 'default exclude message' }
54
- end
55
- get '/exclude/exclude_message'
56
-
57
- params do
58
- requires :type, values: { except: -> { ValuesModel.excepts }, except_message: 'value is on exclusions list' }
59
- end
60
- get '/exclude/lambda/exclude_message'
61
-
62
- params do
63
- requires :type, values: { except: ValuesModel.excepts, message: 'default exclude message' }
64
- end
65
- get '/exclude/fallback_message'
66
- end
39
+ before do
40
+ stub_const('ValuesModel', values_model)
41
+ end
42
+
43
+ let_it_be(:app) do
44
+ ValuesModel = values_model
45
+ Class.new(Grape::API) do
46
+ default_format :json
67
47
 
48
+ resources :custom_message do
68
49
  params do
69
- requires :type, values: ValuesModel.values
50
+ requires :type, values: { value: ValuesModel.values, message: 'value does not include in values' }
70
51
  end
71
52
  get '/' do
72
53
  { type: params[:type] }
73
54
  end
74
55
 
75
56
  params do
76
- requires :type, values: []
57
+ optional :type, values: { value: -> { ValuesModel.values }, message: 'value does not include in values' }, default: 'valid-type2'
77
58
  end
78
- get '/empty'
79
-
80
- params do
81
- optional :type, values: { value: ValuesModel.values }, default: 'valid-type2'
82
- end
83
- get '/default/hash/valid' do
59
+ get '/lambda' do
84
60
  { type: params[:type] }
85
61
  end
86
62
 
87
63
  params do
88
- optional :type, values: ValuesModel.values, default: 'valid-type2'
89
- end
90
- get '/default/valid' do
91
- { type: params[:type] }
64
+ requires :type, values: { except: ValuesModel.excepts, except_message: 'value is on exclusions list', message: 'default exclude message' }
92
65
  end
66
+ get '/exclude/exclude_message'
93
67
 
94
68
  params do
95
- optional :type, values: { except: ValuesModel.excepts }, default: 'valid-type2'
96
- end
97
- get '/default/except' do
98
- { type: params[:type] }
69
+ requires :type, values: { except: -> { ValuesModel.excepts }, except_message: 'value is on exclusions list' }
99
70
  end
71
+ get '/exclude/lambda/exclude_message'
100
72
 
101
73
  params do
102
- optional :type, values: -> { ValuesModel.values }, default: 'valid-type2'
103
- end
104
- get '/lambda' do
105
- { type: params[:type] }
74
+ requires :type, values: { except: ValuesModel.excepts, message: 'default exclude message' }
106
75
  end
76
+ get '/exclude/fallback_message'
77
+ end
107
78
 
108
- params do
109
- requires :type, values: ->(v) { ValuesModel.values.include? v }
110
- end
111
- get '/lambda_val' do
112
- { type: params[:type] }
113
- end
79
+ params do
80
+ requires :type, values: ValuesModel.values
81
+ end
82
+ get '/' do
83
+ { type: params[:type] }
84
+ end
114
85
 
115
- params do
116
- requires :number, type: Integer, values: ->(v) { v > 0 }
117
- end
118
- get '/lambda_int_val' do
119
- { number: params[:number] }
120
- end
86
+ params do
87
+ requires :type, values: []
88
+ end
89
+ get '/empty'
121
90
 
122
- params do
123
- requires :type, values: -> { [] }
124
- end
125
- get '/empty_lambda'
91
+ params do
92
+ optional :type, values: { value: ValuesModel.values }, default: 'valid-type2'
93
+ end
94
+ get '/default/hash/valid' do
95
+ { type: params[:type] }
96
+ end
126
97
 
127
- params do
128
- optional :type, values: ValuesModel.values, default: -> { ValuesModel.values.sample }
129
- end
130
- get '/default_lambda' do
131
- { type: params[:type] }
132
- end
98
+ params do
99
+ optional :type, values: ValuesModel.values, default: 'valid-type2'
100
+ end
101
+ get '/default/valid' do
102
+ { type: params[:type] }
103
+ end
133
104
 
134
- params do
135
- optional :type, values: -> { ValuesModel.values }, default: -> { ValuesModel.values.sample }
136
- end
137
- get '/default_and_values_lambda' do
138
- { type: params[:type] }
139
- end
105
+ params do
106
+ optional :type, values: { except: ValuesModel.excepts }, default: 'valid-type2'
107
+ end
108
+ get '/default/except' do
109
+ { type: params[:type] }
110
+ end
140
111
 
141
- params do
142
- optional :type, type: Boolean, desc: 'A boolean', values: [true]
143
- end
144
- get '/values/optional_boolean' do
145
- { type: params[:type] }
146
- end
112
+ params do
113
+ optional :type, values: -> { ValuesModel.values }, default: 'valid-type2'
114
+ end
115
+ get '/lambda' do
116
+ { type: params[:type] }
117
+ end
147
118
 
148
- params do
149
- requires :type, type: Integer, desc: 'An integer', values: [10, 11], default: 10
150
- end
151
- get '/values/coercion' do
152
- { type: params[:type] }
153
- end
119
+ params do
120
+ requires :type, values: ->(v) { ValuesModel.include? v }
121
+ end
122
+ get '/lambda_val' do
123
+ { type: params[:type] }
124
+ end
154
125
 
155
- params do
156
- requires :type, type: Array[Integer], desc: 'An integer', values: [10, 11], default: 10
157
- end
158
- get '/values/array_coercion' do
159
- { type: params[:type] }
160
- end
126
+ params do
127
+ requires :number, type: Integer, values: ->(v) { v > 0 }
128
+ end
129
+ get '/lambda_int_val' do
130
+ { number: params[:number] }
131
+ end
161
132
 
162
- params do
163
- optional :optional, type: Array do
164
- requires :type, values: %w[a b]
165
- end
166
- end
167
- get '/optional_with_required_values'
133
+ params do
134
+ requires :type, values: -> { [] }
135
+ end
136
+ get '/empty_lambda'
168
137
 
169
- params do
170
- requires :type, values: { except: ValuesModel.excepts }
171
- end
172
- get '/except/exclusive' do
173
- { type: params[:type] }
174
- end
138
+ params do
139
+ optional :type, values: ValuesModel.values, default: -> { ValuesModel.values.sample }
140
+ end
141
+ get '/default_lambda' do
142
+ { type: params[:type] }
143
+ end
175
144
 
176
- params do
177
- requires :type, type: String, values: { except: ValuesModel.excepts }
178
- end
179
- get '/except/exclusive/type' do
180
- { type: params[:type] }
181
- end
145
+ params do
146
+ optional :type, values: -> { ValuesModel.values }, default: -> { ValuesModel.values.sample }
147
+ end
148
+ get '/default_and_values_lambda' do
149
+ { type: params[:type] }
150
+ end
182
151
 
183
- params do
184
- requires :type, values: { except: -> { ValuesModel.excepts } }
185
- end
186
- get '/except/exclusive/lambda' do
187
- { type: params[:type] }
188
- end
152
+ params do
153
+ optional :type, type: Grape::API::Boolean, desc: 'A boolean', values: [true]
154
+ end
155
+ get '/values/optional_boolean' do
156
+ { type: params[:type] }
157
+ end
189
158
 
190
- params do
191
- requires :type, type: String, values: { except: -> { ValuesModel.excepts } }
192
- end
193
- get '/except/exclusive/lambda/type' do
194
- { type: params[:type] }
195
- end
159
+ params do
160
+ requires :type, type: Integer, desc: 'An integer', values: [10, 11], default: 10
161
+ end
162
+ get '/values/coercion' do
163
+ { type: params[:type] }
164
+ end
196
165
 
197
- params do
198
- requires :type, type: Integer, values: { except: -> { [3, 4, 5] } }
199
- end
200
- get '/except/exclusive/lambda/coercion' do
201
- { type: params[:type] }
202
- end
166
+ params do
167
+ requires :type, type: Array[Integer], desc: 'An integer', values: [10, 11], default: 10
168
+ end
169
+ get '/values/array_coercion' do
170
+ { type: params[:type] }
171
+ end
203
172
 
204
- params do
205
- requires :type, type: Integer, values: { value: 1..5, except: [3] }
206
- end
207
- get '/mixed/value/except' do
208
- { type: params[:type] }
173
+ params do
174
+ optional :optional, type: Array do
175
+ requires :type, values: %w[a b]
209
176
  end
177
+ end
178
+ get '/optional_with_required_values'
210
179
 
211
- params do
212
- optional :optional, type: Array[String], values: %w[a b c]
213
- end
214
- put '/optional_with_array_of_string_values'
180
+ params do
181
+ requires :type, values: { except: ValuesModel.excepts }
182
+ end
183
+ get '/except/exclusive' do
184
+ { type: params[:type] }
185
+ end
215
186
 
216
- params do
217
- requires :type, values: { proc: ->(v) { ValuesModel.values.include? v } }
218
- end
219
- get '/proc' do
220
- { type: params[:type] }
221
- end
187
+ params do
188
+ requires :type, type: String, values: { except: ValuesModel.excepts }
189
+ end
190
+ get '/except/exclusive/type' do
191
+ { type: params[:type] }
192
+ end
222
193
 
223
- params do
224
- requires :type, values: { proc: ->(v) { ValuesModel.values.include? v }, message: 'failed check' }
225
- end
226
- get '/proc/message'
194
+ params do
195
+ requires :type, values: { except: -> { ValuesModel.excepts } }
196
+ end
197
+ get '/except/exclusive/lambda' do
198
+ { type: params[:type] }
199
+ end
227
200
 
228
- params do
229
- optional :name, type: String, values: %w[a b], allow_blank: true
230
- end
231
- get '/allow_blank'
201
+ params do
202
+ requires :type, type: String, values: { except: -> { ValuesModel.excepts } }
203
+ end
204
+ get '/except/exclusive/lambda/type' do
205
+ { type: params[:type] }
232
206
  end
233
- end
234
- end
235
207
 
236
- def app
237
- ValidationsSpec::ValuesValidatorSpec::API
208
+ params do
209
+ requires :type, type: Integer, values: { except: -> { [3, 4, 5] } }
210
+ end
211
+ get '/except/exclusive/lambda/coercion' do
212
+ { type: params[:type] }
213
+ end
214
+
215
+ params do
216
+ requires :type, type: Integer, values: { value: 1..5, except: [3] }
217
+ end
218
+ get '/mixed/value/except' do
219
+ { type: params[:type] }
220
+ end
221
+
222
+ params do
223
+ optional :optional, type: Array[String], values: %w[a b c]
224
+ end
225
+ put '/optional_with_array_of_string_values'
226
+
227
+ params do
228
+ requires :type, values: { proc: ->(v) { ValuesModel.include? v } }
229
+ end
230
+ get '/proc' do
231
+ { type: params[:type] }
232
+ end
233
+
234
+ params do
235
+ requires :type, values: { proc: ->(v) { ValuesModel.include? v }, message: 'failed check' }
236
+ end
237
+ get '/proc/message'
238
+
239
+ params do
240
+ optional :name, type: String, values: %w[a b], allow_blank: true
241
+ end
242
+ get '/allow_blank'
243
+ end
238
244
  end
239
245
 
240
246
  context 'with a custom validation message' do
@@ -251,7 +257,7 @@ describe Grape::Validations::ValuesValidator do
251
257
  end
252
258
 
253
259
  it 'validates against values in a proc' do
254
- ValidationsSpec::ValuesModel.add_value('valid-type4')
260
+ ValuesModel.add_value('valid-type4')
255
261
 
256
262
  get('/custom_message/lambda', type: 'valid-type4')
257
263
  expect(last_response.status).to eq 200
@@ -350,15 +356,14 @@ describe Grape::Validations::ValuesValidator do
350
356
  end
351
357
 
352
358
  it 'does not validate updated values without proc' do
353
- ValidationsSpec::ValuesModel.add_value('valid-type4')
354
-
359
+ ValuesModel.add_value('valid-type4')
355
360
  get('/', type: 'valid-type4')
356
361
  expect(last_response.status).to eq 400
357
362
  expect(last_response.body).to eq({ error: 'type does not have a valid value' }.to_json)
358
363
  end
359
364
 
360
365
  it 'validates against values in a proc' do
361
- ValidationsSpec::ValuesModel.add_value('valid-type4')
366
+ ValuesModel.add_value('valid-type4')
362
367
 
363
368
  get('/lambda', type: 'valid-type4')
364
369
  expect(last_response.status).to eq 200
@@ -420,21 +425,21 @@ describe Grape::Validations::ValuesValidator do
420
425
  it 'raises IncompatibleOptionValues on an invalid default value from proc' do
421
426
  subject = Class.new(Grape::API)
422
427
  expect do
423
- subject.params { optional :type, values: ['valid-type1', 'valid-type2', 'valid-type3'], default: ValidationsSpec::ValuesModel.values.sample + '_invalid' }
428
+ subject.params { optional :type, values: %w[valid-type1 valid-type2 valid-type3], default: "#{ValuesModel.values.sample}_invalid" }
424
429
  end.to raise_error Grape::Exceptions::IncompatibleOptionValues
425
430
  end
426
431
 
427
432
  it 'raises IncompatibleOptionValues on an invalid default value' do
428
433
  subject = Class.new(Grape::API)
429
434
  expect do
430
- subject.params { optional :type, values: ['valid-type1', 'valid-type2', 'valid-type3'], default: 'invalid-type' }
435
+ subject.params { optional :type, values: %w[valid-type1 valid-type2 valid-type3], default: 'invalid-type' }
431
436
  end.to raise_error Grape::Exceptions::IncompatibleOptionValues
432
437
  end
433
438
 
434
439
  it 'raises IncompatibleOptionValues when type is incompatible with values array' do
435
440
  subject = Class.new(Grape::API)
436
441
  expect do
437
- subject.params { optional :type, values: ['valid-type1', 'valid-type2', 'valid-type3'], type: Symbol }
442
+ subject.params { optional :type, values: %w[valid-type1 valid-type2 valid-type3], type: Symbol }
438
443
  end.to raise_error Grape::Exceptions::IncompatibleOptionValues
439
444
  end
440
445
 
@@ -648,9 +653,9 @@ describe Grape::Validations::ValuesValidator do
648
653
  end
649
654
 
650
655
  it 'accepts multiple valid values' do
651
- get '/proc', type: ['valid-type1', 'valid-type3']
656
+ get '/proc', type: %w[valid-type1 valid-type3]
652
657
  expect(last_response.status).to eq 200
653
- expect(last_response.body).to eq({ type: ['valid-type1', 'valid-type3'] }.to_json)
658
+ expect(last_response.body).to eq({ type: %w[valid-type1 valid-type3] }.to_json)
654
659
  end
655
660
 
656
661
  it 'rejects a single invalid value' do
@@ -660,7 +665,7 @@ describe Grape::Validations::ValuesValidator do
660
665
  end
661
666
 
662
667
  it 'rejects an invalid value among valid ones' do
663
- get '/proc', type: ['valid-type1', 'invalid-type1', 'valid-type3']
668
+ get '/proc', type: %w[valid-type1 invalid-type1 valid-type3]
664
669
  expect(last_response.status).to eq 400
665
670
  expect(last_response.body).to eq({ error: 'type does not have a valid value' }.to_json)
666
671
  end