grape 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grape might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -4
- data/Gemfile.lock +13 -13
- data/README.md +290 -12
- data/UPGRADING.md +68 -1
- data/gemfiles/rails_3.gemfile +1 -1
- data/lib/grape.rb +8 -2
- data/lib/grape/api.rb +40 -34
- data/lib/grape/dsl/configuration.rb +2 -115
- data/lib/grape/dsl/desc.rb +101 -0
- data/lib/grape/dsl/headers.rb +16 -0
- data/lib/grape/dsl/helpers.rb +5 -9
- data/lib/grape/dsl/inside_route.rb +3 -11
- data/lib/grape/dsl/logger.rb +20 -0
- data/lib/grape/dsl/parameters.rb +12 -10
- data/lib/grape/dsl/request_response.rb +17 -4
- data/lib/grape/dsl/routing.rb +24 -7
- data/lib/grape/dsl/settings.rb +8 -2
- data/lib/grape/endpoint.rb +30 -26
- data/lib/grape/error_formatter.rb +31 -0
- data/lib/grape/error_formatter/base.rb +0 -28
- data/lib/grape/error_formatter/json.rb +13 -2
- data/lib/grape/error_formatter/txt.rb +3 -1
- data/lib/grape/error_formatter/xml.rb +3 -1
- data/lib/grape/exceptions/base.rb +11 -4
- data/lib/grape/exceptions/incompatible_option_values.rb +1 -1
- data/lib/grape/exceptions/invalid_accept_header.rb +1 -1
- data/lib/grape/exceptions/invalid_formatter.rb +1 -1
- data/lib/grape/exceptions/invalid_message_body.rb +1 -1
- data/lib/grape/exceptions/invalid_version_header.rb +1 -1
- data/lib/grape/exceptions/invalid_versioner_option.rb +1 -1
- data/lib/grape/exceptions/invalid_with_option_for_represent.rb +1 -1
- data/lib/grape/exceptions/method_not_allowed.rb +10 -0
- data/lib/grape/exceptions/missing_group_type.rb +1 -1
- data/lib/grape/exceptions/missing_mime_type.rb +1 -1
- data/lib/grape/exceptions/missing_option.rb +1 -1
- data/lib/grape/exceptions/missing_vendor_option.rb +1 -1
- data/lib/grape/exceptions/unknown_options.rb +1 -1
- data/lib/grape/exceptions/unknown_parameter.rb +1 -1
- data/lib/grape/exceptions/unknown_validator.rb +1 -1
- data/lib/grape/exceptions/unsupported_group_type.rb +1 -1
- data/lib/grape/exceptions/validation.rb +2 -1
- data/lib/grape/formatter.rb +31 -0
- data/lib/grape/middleware/base.rb +28 -2
- data/lib/grape/middleware/error.rb +24 -1
- data/lib/grape/middleware/formatter.rb +4 -3
- data/lib/grape/middleware/versioner/param.rb +13 -2
- data/lib/grape/parser.rb +29 -0
- data/lib/grape/util/sendfile_response.rb +19 -0
- data/lib/grape/util/strict_hash_configuration.rb +1 -1
- data/lib/grape/validations/params_scope.rb +39 -9
- data/lib/grape/validations/types.rb +16 -0
- data/lib/grape/validations/validators/all_or_none.rb +1 -1
- data/lib/grape/validations/validators/allow_blank.rb +2 -2
- data/lib/grape/validations/validators/at_least_one_of.rb +1 -1
- data/lib/grape/validations/validators/base.rb +26 -0
- data/lib/grape/validations/validators/coerce.rb +16 -14
- data/lib/grape/validations/validators/default.rb +1 -1
- data/lib/grape/validations/validators/exactly_one_of.rb +10 -1
- data/lib/grape/validations/validators/mutual_exclusion.rb +1 -1
- data/lib/grape/validations/validators/presence.rb +1 -1
- data/lib/grape/validations/validators/regexp.rb +2 -2
- data/lib/grape/validations/validators/values.rb +2 -2
- data/lib/grape/version.rb +1 -1
- data/spec/grape/api/custom_validations_spec.rb +156 -21
- data/spec/grape/api/namespace_parameters_in_route_spec.rb +38 -0
- data/spec/grape/api/optional_parameters_in_route_spec.rb +43 -0
- data/spec/grape/api/required_parameters_in_route_spec.rb +37 -0
- data/spec/grape/api_spec.rb +118 -60
- data/spec/grape/dsl/configuration_spec.rb +0 -75
- data/spec/grape/dsl/desc_spec.rb +77 -0
- data/spec/grape/dsl/headers_spec.rb +32 -0
- data/spec/grape/dsl/inside_route_spec.rb +0 -18
- data/spec/grape/dsl/logger_spec.rb +26 -0
- data/spec/grape/dsl/parameters_spec.rb +13 -7
- data/spec/grape/dsl/request_response_spec.rb +17 -3
- data/spec/grape/dsl/routing_spec.rb +8 -1
- data/spec/grape/dsl/settings_spec.rb +42 -0
- data/spec/grape/endpoint_spec.rb +60 -9
- data/spec/grape/exceptions/validation_errors_spec.rb +2 -2
- data/spec/grape/exceptions/validation_spec.rb +7 -0
- data/spec/grape/integration/rack_sendfile_spec.rb +44 -0
- data/spec/grape/middleware/base_spec.rb +100 -0
- data/spec/grape/middleware/exception_spec.rb +1 -2
- data/spec/grape/middleware/formatter_spec.rb +12 -2
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +1 -1
- data/spec/grape/middleware/versioner/header_spec.rb +11 -1
- data/spec/grape/middleware/versioner/param_spec.rb +105 -1
- data/spec/grape/validations/params_scope_spec.rb +77 -0
- data/spec/grape/validations/validators/allow_blank_spec.rb +277 -0
- data/spec/grape/validations/validators/coerce_spec.rb +91 -0
- data/spec/grape/validations/validators/default_spec.rb +6 -0
- data/spec/grape/validations/validators/presence_spec.rb +27 -0
- data/spec/grape/validations/validators/regexp_spec.rb +36 -0
- data/spec/grape/validations/validators/values_spec.rb +44 -0
- data/spec/grape/validations_spec.rb +149 -4
- data/spec/spec_helper.rb +1 -0
- metadata +26 -5
- data/lib/grape/formatter/base.rb +0 -31
- data/lib/grape/parser/base.rb +0 -29
- data/pkg/grape-0.13.0.gem +0 -0
@@ -165,6 +165,12 @@ describe Grape::Validations::DefaultValidator do
|
|
165
165
|
expect(last_response.status).to eq(201)
|
166
166
|
expect(last_response.body).to eq({ optional_hash_without_default: nil }.to_json)
|
167
167
|
end
|
168
|
+
|
169
|
+
it 'does not fail even if invalid params is passed to default validator' do
|
170
|
+
expect { post '/optional_hash_without_default', optional_hash_without_default: '5678' }.not_to raise_error
|
171
|
+
expect(last_response.status).to eq(400)
|
172
|
+
expect(last_response.body).to eq({ error: 'optional_hash_without_default is invalid' }.to_json)
|
173
|
+
end
|
168
174
|
end
|
169
175
|
|
170
176
|
context 'optional hash with default value includes optional param with default value' do
|
@@ -25,6 +25,33 @@ describe Grape::Validations::PresenceValidator do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
context 'with a custom validation message' do
|
29
|
+
before do
|
30
|
+
subject.resource :requires do
|
31
|
+
params do
|
32
|
+
requires :email, type: String, allow_blank: { value: false, message: 'has no value' }, regexp: { value: /^\S+$/, message: 'format is invalid' }, message: 'is required'
|
33
|
+
end
|
34
|
+
get do
|
35
|
+
'Hello'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
it 'requires when missing' do
|
40
|
+
get '/requires'
|
41
|
+
expect(last_response.status).to eq(400)
|
42
|
+
expect(last_response.body).to eq('{"error":"email is required, email has no value"}')
|
43
|
+
end
|
44
|
+
it 'requires when empty' do
|
45
|
+
get '/requires', email: ''
|
46
|
+
expect(last_response.body).to eq('{"error":"email has no value, email format is invalid"}')
|
47
|
+
end
|
48
|
+
it 'valid when set' do
|
49
|
+
get '/requires', email: 'bob@example.com'
|
50
|
+
expect(last_response.status).to eq(200)
|
51
|
+
expect(last_response.body).to eq('Hello'.to_json)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
28
55
|
context 'with a required regexp parameter supplied in the POST body' do
|
29
56
|
before do
|
30
57
|
subject.format :json
|
@@ -6,6 +6,14 @@ describe Grape::Validations::RegexpValidator do
|
|
6
6
|
class API < Grape::API
|
7
7
|
default_format :json
|
8
8
|
|
9
|
+
resources :custom_message do
|
10
|
+
params do
|
11
|
+
requires :name, regexp: { value: /^[a-z]+$/, message: 'format is invalid' }
|
12
|
+
end
|
13
|
+
get do
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
9
17
|
params do
|
10
18
|
requires :name, regexp: /^[a-z]+$/
|
11
19
|
end
|
@@ -19,15 +27,43 @@ describe Grape::Validations::RegexpValidator do
|
|
19
27
|
ValidationsSpec::RegexpValidatorSpec::API
|
20
28
|
end
|
21
29
|
|
30
|
+
context 'custom validation message' do
|
31
|
+
context 'with invalid input' do
|
32
|
+
it 'refuses inapppopriate' do
|
33
|
+
get '/custom_message', name: 'invalid name'
|
34
|
+
expect(last_response.status).to eq(400)
|
35
|
+
expect(last_response.body).to eq('{"error":"name format is invalid"}')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'refuses empty' do
|
39
|
+
get '/custom_message', name: ''
|
40
|
+
expect(last_response.status).to eq(400)
|
41
|
+
expect(last_response.body).to eq('{"error":"name format is invalid"}')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'accepts nil' do
|
46
|
+
get '/custom_message', name: nil
|
47
|
+
expect(last_response.status).to eq(200)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'accepts valid input' do
|
51
|
+
get '/custom_message', name: 'bob'
|
52
|
+
expect(last_response.status).to eq(200)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
22
56
|
context 'invalid input' do
|
23
57
|
it 'refuses inapppopriate' do
|
24
58
|
get '/', name: 'invalid name'
|
25
59
|
expect(last_response.status).to eq(400)
|
60
|
+
expect(last_response.body).to eq('{"error":"name is invalid"}')
|
26
61
|
end
|
27
62
|
|
28
63
|
it 'refuses empty' do
|
29
64
|
get '/', name: ''
|
30
65
|
expect(last_response.status).to eq(400)
|
66
|
+
expect(last_response.body).to eq('{"error":"name is invalid"}')
|
31
67
|
end
|
32
68
|
end
|
33
69
|
|
@@ -21,6 +21,22 @@ describe Grape::Validations::ValuesValidator do
|
|
21
21
|
class API < Grape::API
|
22
22
|
default_format :json
|
23
23
|
|
24
|
+
resources :custom_message do
|
25
|
+
params do
|
26
|
+
requires :type, values: { value: ValuesModel.values, message: 'value does not include in values' }
|
27
|
+
end
|
28
|
+
get '/' do
|
29
|
+
{ type: params[:type] }
|
30
|
+
end
|
31
|
+
|
32
|
+
params do
|
33
|
+
optional :type, values: { value: -> { ValuesModel.values }, message: 'value does not include in values' }, default: 'valid-type2'
|
34
|
+
end
|
35
|
+
get '/lambda' do
|
36
|
+
{ type: params[:type] }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
24
40
|
params do
|
25
41
|
requires :type, values: ValuesModel.values
|
26
42
|
end
|
@@ -91,6 +107,34 @@ describe Grape::Validations::ValuesValidator do
|
|
91
107
|
ValidationsSpec::ValuesValidatorSpec::API
|
92
108
|
end
|
93
109
|
|
110
|
+
context 'with a custom validation message' do
|
111
|
+
it 'allows a valid value for a parameter' do
|
112
|
+
get('/custom_message', type: 'valid-type1')
|
113
|
+
expect(last_response.status).to eq 200
|
114
|
+
expect(last_response.body).to eq({ type: 'valid-type1' }.to_json)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'does not allow an invalid value for a parameter' do
|
118
|
+
get('/custom_message', type: 'invalid-type')
|
119
|
+
expect(last_response.status).to eq 400
|
120
|
+
expect(last_response.body).to eq({ error: 'type value does not include in values' }.to_json)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'validates against values in a proc' do
|
124
|
+
ValidationsSpec::ValuesModel.add_value('valid-type4')
|
125
|
+
|
126
|
+
get('/custom_message/lambda', type: 'valid-type4')
|
127
|
+
expect(last_response.status).to eq 200
|
128
|
+
expect(last_response.body).to eq({ type: 'valid-type4' }.to_json)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'does not allow an invalid value for a parameter using lambda' do
|
132
|
+
get('/custom_message/lambda', type: 'invalid-type')
|
133
|
+
expect(last_response.status).to eq 400
|
134
|
+
expect(last_response.body).to eq({ error: 'type value does not include in values' }.to_json)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
94
138
|
it 'allows a valid value for a parameter' do
|
95
139
|
get('/', type: 'valid-type1')
|
96
140
|
expect(last_response.status).to eq 200
|
@@ -366,7 +366,7 @@ describe Grape::Validations do
|
|
366
366
|
end
|
367
367
|
|
368
368
|
it "doesn't throw a missing param when param is present" do
|
369
|
-
get '/required', items: [key: 'hello'
|
369
|
+
get '/required', items: [key: 'hello']
|
370
370
|
expect(last_response.status).to eq(200)
|
371
371
|
expect(last_response.body).to eq('required works')
|
372
372
|
end
|
@@ -942,14 +942,14 @@ describe Grape::Validations do
|
|
942
942
|
class CustomvalidatorWithOptions < Grape::Validations::Base
|
943
943
|
def validate_param!(attr_name, params)
|
944
944
|
return if params[attr_name] == @option[:text]
|
945
|
-
fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message:
|
945
|
+
fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message
|
946
946
|
end
|
947
947
|
end
|
948
948
|
end
|
949
949
|
|
950
950
|
before do
|
951
951
|
subject.params do
|
952
|
-
optional :custom, customvalidator_with_options: { text: 'im custom with options',
|
952
|
+
optional :custom, customvalidator_with_options: { text: 'im custom with options', message: 'is not custom with options!' }
|
953
953
|
end
|
954
954
|
subject.get '/optional_custom' do
|
955
955
|
'optional with custom works!'
|
@@ -1078,8 +1078,62 @@ describe Grape::Validations do
|
|
1078
1078
|
end
|
1079
1079
|
end
|
1080
1080
|
|
1081
|
+
context 'all or none' do
|
1082
|
+
context 'optional params' do
|
1083
|
+
before :each do
|
1084
|
+
subject.resource :custom_message do
|
1085
|
+
params do
|
1086
|
+
optional :beer
|
1087
|
+
optional :wine
|
1088
|
+
optional :juice
|
1089
|
+
all_or_none_of :beer, :wine, :juice, message: 'all params are required or none is required'
|
1090
|
+
end
|
1091
|
+
get '/all_or_none' do
|
1092
|
+
'all_or_none works!'
|
1093
|
+
end
|
1094
|
+
end
|
1095
|
+
end
|
1096
|
+
context 'with a custom validation message' do
|
1097
|
+
it 'errors when any one is present' do
|
1098
|
+
get '/custom_message/all_or_none', beer: 'string'
|
1099
|
+
expect(last_response.status).to eq(400)
|
1100
|
+
expect(last_response.body).to eq 'beer, wine, juice all params are required or none is required'
|
1101
|
+
end
|
1102
|
+
it 'works when all params are present' do
|
1103
|
+
get '/custom_message/all_or_none', beer: 'string', wine: 'anotherstring', juice: 'anotheranotherstring'
|
1104
|
+
expect(last_response.status).to eq(200)
|
1105
|
+
expect(last_response.body).to eq 'all_or_none works!'
|
1106
|
+
end
|
1107
|
+
it 'works when none are present' do
|
1108
|
+
get '/custom_message/all_or_none'
|
1109
|
+
expect(last_response.status).to eq(200)
|
1110
|
+
expect(last_response.body).to eq 'all_or_none works!'
|
1111
|
+
end
|
1112
|
+
end
|
1113
|
+
end
|
1114
|
+
end
|
1115
|
+
|
1081
1116
|
context 'mutually exclusive' do
|
1082
1117
|
context 'optional params' do
|
1118
|
+
context 'with custom validation message' do
|
1119
|
+
it 'errors when two or more are present' do
|
1120
|
+
subject.resources :custom_message do
|
1121
|
+
params do
|
1122
|
+
optional :beer
|
1123
|
+
optional :wine
|
1124
|
+
optional :juice
|
1125
|
+
mutually_exclusive :beer, :wine, :juice, message: 'are mutually exclusive cannot pass both params'
|
1126
|
+
end
|
1127
|
+
get '/mutually_exclusive' do
|
1128
|
+
'mutually_exclusive works!'
|
1129
|
+
end
|
1130
|
+
end
|
1131
|
+
get '/custom_message/mutually_exclusive', beer: 'string', wine: 'anotherstring'
|
1132
|
+
expect(last_response.status).to eq(400)
|
1133
|
+
expect(last_response.body).to eq 'beer, wine are mutually exclusive cannot pass both params'
|
1134
|
+
end
|
1135
|
+
end
|
1136
|
+
|
1083
1137
|
it 'errors when two or more are present' do
|
1084
1138
|
subject.params do
|
1085
1139
|
optional :beer
|
@@ -1098,6 +1152,34 @@ describe Grape::Validations do
|
|
1098
1152
|
end
|
1099
1153
|
|
1100
1154
|
context 'more than one set of mutually exclusive params' do
|
1155
|
+
context 'with a custom validation message' do
|
1156
|
+
it 'errors for all sets' do
|
1157
|
+
subject.resources :custom_message do
|
1158
|
+
params do
|
1159
|
+
optional :beer
|
1160
|
+
optional :wine
|
1161
|
+
mutually_exclusive :beer, :wine, message: 'are mutually exclusive pass only one'
|
1162
|
+
optional :nested, type: Hash do
|
1163
|
+
optional :scotch
|
1164
|
+
optional :aquavit
|
1165
|
+
mutually_exclusive :scotch, :aquavit, message: 'are mutually exclusive pass only one'
|
1166
|
+
end
|
1167
|
+
optional :nested2, type: Array do
|
1168
|
+
optional :scotch2
|
1169
|
+
optional :aquavit2
|
1170
|
+
mutually_exclusive :scotch2, :aquavit2, message: 'are mutually exclusive pass only one'
|
1171
|
+
end
|
1172
|
+
end
|
1173
|
+
get '/mutually_exclusive' do
|
1174
|
+
'mutually_exclusive works!'
|
1175
|
+
end
|
1176
|
+
end
|
1177
|
+
get '/custom_message/mutually_exclusive', beer: 'true', wine: 'true', nested: { scotch: 'true', aquavit: 'true' }, nested2: [{ scotch2: 'true' }, { scotch2: 'true', aquavit2: 'true' }]
|
1178
|
+
expect(last_response.status).to eq(400)
|
1179
|
+
expect(last_response.body).to eq 'beer, wine are mutually exclusive pass only one, scotch, aquavit are mutually exclusive pass only one, scotch2, aquavit2 are mutually exclusive pass only one'
|
1180
|
+
end
|
1181
|
+
end
|
1182
|
+
|
1101
1183
|
it 'errors for all sets' do
|
1102
1184
|
subject.params do
|
1103
1185
|
optional :beer
|
@@ -1131,7 +1213,6 @@ describe Grape::Validations do
|
|
1131
1213
|
optional :wine
|
1132
1214
|
optional :beer
|
1133
1215
|
optional :juice
|
1134
|
-
|
1135
1216
|
mutually_exclusive :beer, :wine, :juice
|
1136
1217
|
end
|
1137
1218
|
end
|
@@ -1185,6 +1266,18 @@ describe Grape::Validations do
|
|
1185
1266
|
context 'exactly one of' do
|
1186
1267
|
context 'params' do
|
1187
1268
|
before :each do
|
1269
|
+
subject.resources :custom_message do
|
1270
|
+
params do
|
1271
|
+
optional :beer
|
1272
|
+
optional :wine
|
1273
|
+
optional :juice
|
1274
|
+
exactly_one_of :beer, :wine, :juice, message: { exactly_one: 'are missing, exactly one parameter is required', mutual_exclusion: 'are mutually exclusive, exactly one parameter is required' }
|
1275
|
+
end
|
1276
|
+
get '/exactly_one_of' do
|
1277
|
+
'exactly_one_of works!'
|
1278
|
+
end
|
1279
|
+
end
|
1280
|
+
|
1188
1281
|
subject.params do
|
1189
1282
|
optional :beer
|
1190
1283
|
optional :wine
|
@@ -1196,6 +1289,26 @@ describe Grape::Validations do
|
|
1196
1289
|
end
|
1197
1290
|
end
|
1198
1291
|
|
1292
|
+
context 'with a custom validation message' do
|
1293
|
+
it 'errors when none are present' do
|
1294
|
+
get '/custom_message/exactly_one_of'
|
1295
|
+
expect(last_response.status).to eq(400)
|
1296
|
+
expect(last_response.body).to eq 'beer, wine, juice are missing, exactly one parameter is required'
|
1297
|
+
end
|
1298
|
+
|
1299
|
+
it 'succeeds when one is present' do
|
1300
|
+
get '/custom_message/exactly_one_of', beer: 'string'
|
1301
|
+
expect(last_response.status).to eq(200)
|
1302
|
+
expect(last_response.body).to eq 'exactly_one_of works!'
|
1303
|
+
end
|
1304
|
+
|
1305
|
+
it 'errors when two or more are present' do
|
1306
|
+
get '/custom_message/exactly_one_of', beer: 'string', wine: 'anotherstring'
|
1307
|
+
expect(last_response.status).to eq(400)
|
1308
|
+
expect(last_response.body).to eq 'beer, wine are mutually exclusive, exactly one parameter is required'
|
1309
|
+
end
|
1310
|
+
end
|
1311
|
+
|
1199
1312
|
it 'errors when none are present' do
|
1200
1313
|
get '/exactly_one_of'
|
1201
1314
|
expect(last_response.status).to eq(400)
|
@@ -1259,6 +1372,18 @@ describe Grape::Validations do
|
|
1259
1372
|
context 'at least one of' do
|
1260
1373
|
context 'params' do
|
1261
1374
|
before :each do
|
1375
|
+
subject.resources :custom_message do
|
1376
|
+
params do
|
1377
|
+
optional :beer
|
1378
|
+
optional :wine
|
1379
|
+
optional :juice
|
1380
|
+
at_least_one_of :beer, :wine, :juice, message: 'are missing, please specify at least one param'
|
1381
|
+
end
|
1382
|
+
get '/at_least_one_of' do
|
1383
|
+
'at_least_one_of works!'
|
1384
|
+
end
|
1385
|
+
end
|
1386
|
+
|
1262
1387
|
subject.params do
|
1263
1388
|
optional :beer
|
1264
1389
|
optional :wine
|
@@ -1270,6 +1395,26 @@ describe Grape::Validations do
|
|
1270
1395
|
end
|
1271
1396
|
end
|
1272
1397
|
|
1398
|
+
context 'with a custom validation message' do
|
1399
|
+
it 'errors when none are present' do
|
1400
|
+
get '/custom_message/at_least_one_of'
|
1401
|
+
expect(last_response.status).to eq(400)
|
1402
|
+
expect(last_response.body).to eq 'beer, wine, juice are missing, please specify at least one param'
|
1403
|
+
end
|
1404
|
+
|
1405
|
+
it 'does not error when one is present' do
|
1406
|
+
get '/custom_message/at_least_one_of', beer: 'string'
|
1407
|
+
expect(last_response.status).to eq(200)
|
1408
|
+
expect(last_response.body).to eq 'at_least_one_of works!'
|
1409
|
+
end
|
1410
|
+
|
1411
|
+
it 'does not error when two are present' do
|
1412
|
+
get '/custom_message/at_least_one_of', beer: 'string', wine: 'string'
|
1413
|
+
expect(last_response.status).to eq(200)
|
1414
|
+
expect(last_response.body).to eq 'at_least_one_of works!'
|
1415
|
+
end
|
1416
|
+
end
|
1417
|
+
|
1273
1418
|
it 'errors when none are present' do
|
1274
1419
|
get '/at_least_one_of'
|
1275
1420
|
expect(last_response.status).to eq(400)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -349,8 +349,11 @@ files:
|
|
349
349
|
- lib/grape/dsl/api.rb
|
350
350
|
- lib/grape/dsl/callbacks.rb
|
351
351
|
- lib/grape/dsl/configuration.rb
|
352
|
+
- lib/grape/dsl/desc.rb
|
353
|
+
- lib/grape/dsl/headers.rb
|
352
354
|
- lib/grape/dsl/helpers.rb
|
353
355
|
- lib/grape/dsl/inside_route.rb
|
356
|
+
- lib/grape/dsl/logger.rb
|
354
357
|
- lib/grape/dsl/middleware.rb
|
355
358
|
- lib/grape/dsl/parameters.rb
|
356
359
|
- lib/grape/dsl/request_response.rb
|
@@ -358,6 +361,7 @@ files:
|
|
358
361
|
- lib/grape/dsl/settings.rb
|
359
362
|
- lib/grape/dsl/validations.rb
|
360
363
|
- lib/grape/endpoint.rb
|
364
|
+
- lib/grape/error_formatter.rb
|
361
365
|
- lib/grape/error_formatter/base.rb
|
362
366
|
- lib/grape/error_formatter/json.rb
|
363
367
|
- lib/grape/error_formatter/txt.rb
|
@@ -370,6 +374,7 @@ files:
|
|
370
374
|
- lib/grape/exceptions/invalid_version_header.rb
|
371
375
|
- lib/grape/exceptions/invalid_versioner_option.rb
|
372
376
|
- lib/grape/exceptions/invalid_with_option_for_represent.rb
|
377
|
+
- lib/grape/exceptions/method_not_allowed.rb
|
373
378
|
- lib/grape/exceptions/missing_group_type.rb
|
374
379
|
- lib/grape/exceptions/missing_mime_type.rb
|
375
380
|
- lib/grape/exceptions/missing_option.rb
|
@@ -380,7 +385,7 @@ files:
|
|
380
385
|
- lib/grape/exceptions/unsupported_group_type.rb
|
381
386
|
- lib/grape/exceptions/validation.rb
|
382
387
|
- lib/grape/exceptions/validation_errors.rb
|
383
|
-
- lib/grape/formatter
|
388
|
+
- lib/grape/formatter.rb
|
384
389
|
- lib/grape/formatter/json.rb
|
385
390
|
- lib/grape/formatter/serializable_hash.rb
|
386
391
|
- lib/grape/formatter/txt.rb
|
@@ -403,7 +408,7 @@ files:
|
|
403
408
|
- lib/grape/middleware/versioner/parse_media_type_patch.rb
|
404
409
|
- lib/grape/middleware/versioner/path.rb
|
405
410
|
- lib/grape/namespace.rb
|
406
|
-
- lib/grape/parser
|
411
|
+
- lib/grape/parser.rb
|
407
412
|
- lib/grape/parser/json.rb
|
408
413
|
- lib/grape/parser/xml.rb
|
409
414
|
- lib/grape/path.rb
|
@@ -415,6 +420,7 @@ files:
|
|
415
420
|
- lib/grape/util/file_response.rb
|
416
421
|
- lib/grape/util/inheritable_setting.rb
|
417
422
|
- lib/grape/util/inheritable_values.rb
|
423
|
+
- lib/grape/util/sendfile_response.rb
|
418
424
|
- lib/grape/util/stackable_values.rb
|
419
425
|
- lib/grape/util/strict_hash_configuration.rb
|
420
426
|
- lib/grape/validations.rb
|
@@ -441,16 +447,21 @@ files:
|
|
441
447
|
- lib/grape/validations/validators/regexp.rb
|
442
448
|
- lib/grape/validations/validators/values.rb
|
443
449
|
- lib/grape/version.rb
|
444
|
-
- pkg/grape-0.13.0.gem
|
445
450
|
- spec/grape/api/custom_validations_spec.rb
|
446
451
|
- spec/grape/api/deeply_included_options_spec.rb
|
452
|
+
- spec/grape/api/namespace_parameters_in_route_spec.rb
|
447
453
|
- spec/grape/api/nested_helpers_spec.rb
|
454
|
+
- spec/grape/api/optional_parameters_in_route_spec.rb
|
455
|
+
- spec/grape/api/required_parameters_in_route_spec.rb
|
448
456
|
- spec/grape/api/shared_helpers_spec.rb
|
449
457
|
- spec/grape/api_spec.rb
|
450
458
|
- spec/grape/dsl/callbacks_spec.rb
|
451
459
|
- spec/grape/dsl/configuration_spec.rb
|
460
|
+
- spec/grape/dsl/desc_spec.rb
|
461
|
+
- spec/grape/dsl/headers_spec.rb
|
452
462
|
- spec/grape/dsl/helpers_spec.rb
|
453
463
|
- spec/grape/dsl/inside_route_spec.rb
|
464
|
+
- spec/grape/dsl/logger_spec.rb
|
454
465
|
- spec/grape/dsl/middleware_spec.rb
|
455
466
|
- spec/grape/dsl/parameters_spec.rb
|
456
467
|
- spec/grape/dsl/request_response_spec.rb
|
@@ -468,6 +479,8 @@ files:
|
|
468
479
|
- spec/grape/exceptions/unknown_options_spec.rb
|
469
480
|
- spec/grape/exceptions/unknown_validator_spec.rb
|
470
481
|
- spec/grape/exceptions/validation_errors_spec.rb
|
482
|
+
- spec/grape/exceptions/validation_spec.rb
|
483
|
+
- spec/grape/integration/rack_sendfile_spec.rb
|
471
484
|
- spec/grape/integration/rack_spec.rb
|
472
485
|
- spec/grape/loading_spec.rb
|
473
486
|
- spec/grape/middleware/auth/base_spec.rb
|
@@ -539,13 +552,19 @@ summary: A simple Ruby framework for building REST-like APIs.
|
|
539
552
|
test_files:
|
540
553
|
- spec/grape/api/custom_validations_spec.rb
|
541
554
|
- spec/grape/api/deeply_included_options_spec.rb
|
555
|
+
- spec/grape/api/namespace_parameters_in_route_spec.rb
|
542
556
|
- spec/grape/api/nested_helpers_spec.rb
|
557
|
+
- spec/grape/api/optional_parameters_in_route_spec.rb
|
558
|
+
- spec/grape/api/required_parameters_in_route_spec.rb
|
543
559
|
- spec/grape/api/shared_helpers_spec.rb
|
544
560
|
- spec/grape/api_spec.rb
|
545
561
|
- spec/grape/dsl/callbacks_spec.rb
|
546
562
|
- spec/grape/dsl/configuration_spec.rb
|
563
|
+
- spec/grape/dsl/desc_spec.rb
|
564
|
+
- spec/grape/dsl/headers_spec.rb
|
547
565
|
- spec/grape/dsl/helpers_spec.rb
|
548
566
|
- spec/grape/dsl/inside_route_spec.rb
|
567
|
+
- spec/grape/dsl/logger_spec.rb
|
549
568
|
- spec/grape/dsl/middleware_spec.rb
|
550
569
|
- spec/grape/dsl/parameters_spec.rb
|
551
570
|
- spec/grape/dsl/request_response_spec.rb
|
@@ -563,6 +582,8 @@ test_files:
|
|
563
582
|
- spec/grape/exceptions/unknown_options_spec.rb
|
564
583
|
- spec/grape/exceptions/unknown_validator_spec.rb
|
565
584
|
- spec/grape/exceptions/validation_errors_spec.rb
|
585
|
+
- spec/grape/exceptions/validation_spec.rb
|
586
|
+
- spec/grape/integration/rack_sendfile_spec.rb
|
566
587
|
- spec/grape/integration/rack_spec.rb
|
567
588
|
- spec/grape/loading_spec.rb
|
568
589
|
- spec/grape/middleware/auth/base_spec.rb
|