apipie-rails 1.4.0 → 1.4.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +46 -135
- data/CHANGELOG.md +16 -0
- data/apipie-rails.gemspec +1 -0
- data/lib/apipie/application.rb +6 -6
- data/lib/apipie/error_description.rb +7 -5
- data/lib/apipie/extractor/recorder.rb +3 -3
- data/lib/apipie/extractor/writer.rb +6 -6
- data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +2 -2
- data/lib/apipie/generator/swagger/method_description/parameters_service.rb +7 -7
- data/lib/apipie/generator/swagger/param_description/builder.rb +3 -3
- data/lib/apipie/generator/swagger/param_description/in.rb +1 -1
- data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +10 -10
- data/lib/apipie/generator/swagger/param_description/type.rb +5 -1
- data/lib/apipie/generator/swagger/resource_description_composite.rb +5 -5
- data/lib/apipie/generator/swagger/type_extractor.rb +1 -1
- data/lib/apipie/generator/swagger/warning.rb +2 -2
- data/lib/apipie/helpers.rb +1 -1
- data/lib/apipie/response_description.rb +10 -5
- data/lib/apipie/routes_formatter.rb +1 -1
- data/lib/apipie/static_dispatcher.rb +2 -2
- data/lib/apipie/version.rb +1 -1
- data/lib/tasks/apipie.rake +4 -4
- data/spec/controllers/api/v1/architectures_controller_spec.rb +3 -3
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +1 -1
- data/spec/controllers/concerns_controller_spec.rb +2 -2
- data/spec/controllers/extended_controller_spec.rb +2 -2
- data/spec/controllers/included_param_group_controller_spec.rb +1 -1
- data/spec/controllers/pets_controller_spec.rb +1 -1
- data/spec/controllers/users_controller_spec.rb +64 -63
- data/spec/dummy/app/controllers/extending_concern.rb +7 -7
- data/spec/dummy/app/controllers/pets_controller.rb +4 -4
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +2 -2
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +16 -16
- data/spec/dummy/app/controllers/sample_controller.rb +31 -31
- data/spec/lib/apipie/application_spec.rb +2 -2
- data/spec/lib/apipie/extractor/writer_spec.rb +8 -8
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +30 -0
- data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +29 -2
- data/spec/lib/apipie/method_description_spec.rb +2 -2
- data/spec/lib/apipie/param_description_spec.rb +47 -47
- data/spec/lib/apipie/param_group_spec.rb +4 -4
- data/spec/lib/apipie/resource_description_spec.rb +2 -2
- data/spec/lib/apipie/validator_spec.rb +12 -12
- data/spec/lib/swagger/swagger_dsl_spec.rb +40 -40
- data/spec/spec_helper.rb +5 -2
- data/spec/test_engine/memes_controller_spec.rb +1 -1
- metadata +138 -4
@@ -145,6 +145,36 @@ describe Apipie::Generator::Swagger::ParamDescription::Builder do
|
|
145
145
|
/is optional but default value is not specified/
|
146
146
|
).to_stderr
|
147
147
|
end
|
148
|
+
|
149
|
+
context 'and param is a prop desc' do
|
150
|
+
let(:param_description) do
|
151
|
+
Apipie.prop(:param, 'object', param_description_options, [])
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with a delegated controller method' do
|
155
|
+
let(:method_desc) do
|
156
|
+
Apipie::Generator::Swagger::MethodDescription::Decorator.new(
|
157
|
+
Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'warns' do
|
162
|
+
expect { subject }.to output(
|
163
|
+
/is optional but default value is not specified/
|
164
|
+
).to_stderr
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'with a nil controller method' do
|
169
|
+
let(:method_desc) { nil }
|
170
|
+
|
171
|
+
it 'warns' do
|
172
|
+
expect { subject }.to output(
|
173
|
+
/is optional but default value is not specified/
|
174
|
+
).to_stderr
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
148
178
|
end
|
149
179
|
end
|
150
180
|
end
|
@@ -3,7 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe Apipie::Generator::Swagger::ParamDescription::Type do
|
4
4
|
let(:validator_options) { {} }
|
5
5
|
let(:param_description_options) { {}.merge(validator_options) }
|
6
|
-
let(:with_null) { false }
|
7
6
|
let(:http_method) { :GET }
|
8
7
|
let(:path) { '/api' }
|
9
8
|
let(:validator) { String }
|
@@ -63,9 +62,11 @@ describe Apipie::Generator::Swagger::ParamDescription::Type do
|
|
63
62
|
)
|
64
63
|
end
|
65
64
|
|
65
|
+
let(:controller_method) { 'index' }
|
66
|
+
|
66
67
|
let(:type_definition) do
|
67
68
|
described_class.
|
68
|
-
new(param_description, with_null:
|
69
|
+
new(param_description, with_null: false, controller_method: controller_method).
|
69
70
|
to_hash
|
70
71
|
end
|
71
72
|
|
@@ -178,6 +179,32 @@ describe Apipie::Generator::Swagger::ParamDescription::Type do
|
|
178
179
|
it 'outputs a hash without internal typespec warning' do
|
179
180
|
expect { subject }.to output(/is a generic Hash without an internal type specification/).to_stderr
|
180
181
|
end
|
182
|
+
|
183
|
+
context 'and param is a prop desc' do
|
184
|
+
let(:param_description) do
|
185
|
+
Apipie.prop(param_description_name, 'object', {}, [])
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'with a delegated controller method' do
|
189
|
+
let(:controller_method) do
|
190
|
+
Apipie::Generator::Swagger::MethodDescription::Decorator.new(
|
191
|
+
method_desc
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'outputs a hash without internal typespec warning' do
|
196
|
+
expect { subject }.to output(/is a generic Hash without an internal type specification/).to_stderr
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'and controller method is nil' do
|
201
|
+
let(:controller_method) { nil }
|
202
|
+
|
203
|
+
it 'outputs a hash without internal typespec warning' do
|
204
|
+
expect { subject }.to output(/is a generic Hash without an internal type specification/).to_stderr
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
181
208
|
end
|
182
209
|
end
|
183
210
|
end
|
@@ -58,7 +58,7 @@ describe Apipie::MethodDescription do
|
|
58
58
|
)
|
59
59
|
end
|
60
60
|
|
61
|
-
it '
|
61
|
+
it 'is ordered' do
|
62
62
|
expect(json_params).to eq(%w[a b c])
|
63
63
|
end
|
64
64
|
|
@@ -75,7 +75,7 @@ describe Apipie::MethodDescription do
|
|
75
75
|
)
|
76
76
|
end
|
77
77
|
|
78
|
-
it '
|
78
|
+
it 'ignores response-only parameters' do
|
79
79
|
expect(json_params).to eq(%w[a c])
|
80
80
|
end
|
81
81
|
end
|
@@ -14,12 +14,12 @@ describe Apipie::ParamDescription do
|
|
14
14
|
|
15
15
|
describe "metadata" do
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "returns nil when no metadata is provided" do
|
18
18
|
param = Apipie::ParamDescription.new(method_desc, :some_param, String)
|
19
19
|
expect(param.to_json[:metadata]).to eq(nil)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "returns the metadata" do
|
23
23
|
meta = {
|
24
24
|
:length => 32,
|
25
25
|
:weight => '830g'
|
@@ -32,12 +32,12 @@ describe Apipie::ParamDescription do
|
|
32
32
|
|
33
33
|
describe "show option" do
|
34
34
|
|
35
|
-
it "
|
35
|
+
it "returns true when show option is not provided" do
|
36
36
|
param = Apipie::ParamDescription.new(method_desc, :some_param, String)
|
37
37
|
expect(param.to_json[:show]).to eq(true)
|
38
38
|
end
|
39
39
|
|
40
|
-
it "
|
40
|
+
it "returns the show option" do
|
41
41
|
param = Apipie::ParamDescription.new(method_desc, :some_param, String, :show => true)
|
42
42
|
expect(param.to_json[:show]).to eq(true)
|
43
43
|
|
@@ -50,7 +50,7 @@ describe Apipie::ParamDescription do
|
|
50
50
|
describe "full_name" do
|
51
51
|
context "with no nested parameters" do
|
52
52
|
|
53
|
-
it "
|
53
|
+
it "returns name" do
|
54
54
|
param = Apipie::ParamDescription.new(method_desc, :some_param, String)
|
55
55
|
expect(param.to_json[:full_name]).to eq('some_param')
|
56
56
|
end
|
@@ -59,7 +59,7 @@ describe Apipie::ParamDescription do
|
|
59
59
|
|
60
60
|
context "with nested parameters" do
|
61
61
|
|
62
|
-
it "
|
62
|
+
it "returns the parameter's name nested in the parents name" do
|
63
63
|
parent_param = Apipie::ParamDescription.new(method_desc, :parent, String)
|
64
64
|
nested_param = Apipie::ParamDescription.new(method_desc, :nested, String, :parent => parent_param)
|
65
65
|
|
@@ -68,7 +68,7 @@ describe Apipie::ParamDescription do
|
|
68
68
|
|
69
69
|
context "with the parent parameter set to not show" do
|
70
70
|
|
71
|
-
it "
|
71
|
+
it "returns just the parameter's name" do
|
72
72
|
parent_param = Apipie::ParamDescription.new(method_desc, :parent, String, :show => false)
|
73
73
|
nested_param = Apipie::ParamDescription.new(method_desc, :nested, String, :parent => parent_param)
|
74
74
|
|
@@ -80,13 +80,13 @@ describe Apipie::ParamDescription do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
describe "manual validation text" do
|
83
|
-
it "
|
83
|
+
it "allows manual text" do
|
84
84
|
param = Apipie::ParamDescription.new(method_desc, :hidden_param, nil, :validations => "must be foo")
|
85
85
|
|
86
86
|
expect(param.validations).to include("\n<p>must be foo</p>\n")
|
87
87
|
end
|
88
88
|
|
89
|
-
it "
|
89
|
+
it "allows multiple items" do
|
90
90
|
param = Apipie::ParamDescription.new(method_desc, :hidden_param, nil, :validations => ["> 0", "< 5"])
|
91
91
|
|
92
92
|
expect(param.validations).to include("\n<p>> 0</p>\n")
|
@@ -96,16 +96,16 @@ describe Apipie::ParamDescription do
|
|
96
96
|
|
97
97
|
describe "validator selection" do
|
98
98
|
|
99
|
-
it "
|
99
|
+
it "allows nil validator" do
|
100
100
|
param = Apipie::ParamDescription.new(method_desc, :hidden_param, nil)
|
101
101
|
expect(param.validator).to be_nil
|
102
102
|
end
|
103
103
|
|
104
|
-
it "
|
104
|
+
it "throws exception on unknown validator" do
|
105
105
|
expect { Apipie::ParamDescription.new(method_desc, :param, :unknown) }.to raise_error(RuntimeError, /Validator.*not found/)
|
106
106
|
end
|
107
107
|
|
108
|
-
it "
|
108
|
+
it "picks type validator" do
|
109
109
|
expect(Apipie::Validator::BaseValidator).to receive(:find).and_return(:validator_instance)
|
110
110
|
param = Apipie::ParamDescription.new(method_desc, :param, String)
|
111
111
|
expect(param.validator).to eq(:validator_instance)
|
@@ -137,7 +137,7 @@ describe Apipie::ParamDescription do
|
|
137
137
|
context 'when validation value is false' do
|
138
138
|
let(:validation_value) { false }
|
139
139
|
|
140
|
-
it '
|
140
|
+
it 'does not raise an error' do
|
141
141
|
expect { subject }.not_to raise_error
|
142
142
|
end
|
143
143
|
end
|
@@ -145,7 +145,7 @@ describe Apipie::ParamDescription do
|
|
145
145
|
context 'when validation value is an empty string' do
|
146
146
|
let(:validation_value) { '' }
|
147
147
|
|
148
|
-
it '
|
148
|
+
it 'raises an error' do
|
149
149
|
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
150
150
|
end
|
151
151
|
end
|
@@ -157,7 +157,7 @@ describe Apipie::ParamDescription do
|
|
157
157
|
context 'when validation value is false' do
|
158
158
|
let(:validation_value) { false }
|
159
159
|
|
160
|
-
it '
|
160
|
+
it 'does not raise an error' do
|
161
161
|
expect { subject }.not_to raise_error
|
162
162
|
end
|
163
163
|
end
|
@@ -165,7 +165,7 @@ describe Apipie::ParamDescription do
|
|
165
165
|
context 'when validation value is true' do
|
166
166
|
let(:validation_value) { true }
|
167
167
|
|
168
|
-
it '
|
168
|
+
it 'does not raise an error' do
|
169
169
|
expect { subject }.not_to raise_error
|
170
170
|
end
|
171
171
|
end
|
@@ -173,7 +173,7 @@ describe Apipie::ParamDescription do
|
|
173
173
|
context 'when validation value is an empty string' do
|
174
174
|
let(:validation_value) { '' }
|
175
175
|
|
176
|
-
it '
|
176
|
+
it 'raises an error' do
|
177
177
|
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
178
178
|
end
|
179
179
|
end
|
@@ -185,14 +185,14 @@ describe Apipie::ParamDescription do
|
|
185
185
|
context 'when validation value is empty string' do
|
186
186
|
let(:validation_value) { '' }
|
187
187
|
|
188
|
-
it '
|
188
|
+
it 'does not raise an error' do
|
189
189
|
expect { subject }.not_to raise_error
|
190
190
|
end
|
191
191
|
|
192
192
|
context 'when allow_blank is specified as true' do
|
193
193
|
let(:allow_blank) { true }
|
194
194
|
|
195
|
-
it '
|
195
|
+
it 'does not raise an error' do
|
196
196
|
expect { subject }.not_to raise_error
|
197
197
|
end
|
198
198
|
end
|
@@ -206,14 +206,14 @@ describe Apipie::ParamDescription do
|
|
206
206
|
context 'when validation value' do
|
207
207
|
let(:validation_value) { false }
|
208
208
|
|
209
|
-
it '
|
209
|
+
it 'does not raise an error' do
|
210
210
|
expect { subject }.not_to raise_error
|
211
211
|
end
|
212
212
|
|
213
213
|
context 'when allow_blank is false' do
|
214
214
|
let(:allow_blank) { false }
|
215
215
|
|
216
|
-
it '
|
216
|
+
it 'does not raise an error' do
|
217
217
|
expect { subject }.not_to raise_error
|
218
218
|
end
|
219
219
|
end
|
@@ -221,7 +221,7 @@ describe Apipie::ParamDescription do
|
|
221
221
|
context 'when allow_blank is true' do
|
222
222
|
let(:allow_blank) { true }
|
223
223
|
|
224
|
-
it '
|
224
|
+
it 'does not raise an error' do
|
225
225
|
expect { subject }.not_to raise_error
|
226
226
|
end
|
227
227
|
end
|
@@ -230,7 +230,7 @@ describe Apipie::ParamDescription do
|
|
230
230
|
context 'when validation value is empty string' do
|
231
231
|
let(:validation_value) { '' }
|
232
232
|
|
233
|
-
it '
|
233
|
+
it 'raises an error' do
|
234
234
|
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
235
235
|
end
|
236
236
|
end
|
@@ -242,7 +242,7 @@ describe Apipie::ParamDescription do
|
|
242
242
|
context 'when validation value is false' do
|
243
243
|
let(:validation_value) { false }
|
244
244
|
|
245
|
-
it '
|
245
|
+
it 'does not raise an error' do
|
246
246
|
expect { subject }.not_to raise_error
|
247
247
|
end
|
248
248
|
end
|
@@ -250,7 +250,7 @@ describe Apipie::ParamDescription do
|
|
250
250
|
context 'when validation value is true' do
|
251
251
|
let(:validation_value) { true }
|
252
252
|
|
253
|
-
it '
|
253
|
+
it 'does not raise an error' do
|
254
254
|
expect { subject }.not_to raise_error
|
255
255
|
end
|
256
256
|
end
|
@@ -258,7 +258,7 @@ describe Apipie::ParamDescription do
|
|
258
258
|
context 'when validation value is an empty string' do
|
259
259
|
let(:validation_value) { '' }
|
260
260
|
|
261
|
-
it '
|
261
|
+
it 'raises an error' do
|
262
262
|
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
263
263
|
end
|
264
264
|
end
|
@@ -275,14 +275,14 @@ describe Apipie::ParamDescription do
|
|
275
275
|
context 'when a blank but valid value is passed' do
|
276
276
|
let(:validation_value) { false }
|
277
277
|
|
278
|
-
it '
|
278
|
+
it 'does not raise an error' do
|
279
279
|
expect { subject }.not_to raise_error
|
280
280
|
end
|
281
281
|
|
282
282
|
context 'when allow_blank is false' do
|
283
283
|
let(:allow_blank) { false }
|
284
284
|
|
285
|
-
it '
|
285
|
+
it 'does not raise an error' do
|
286
286
|
expect { subject }.not_to raise_error
|
287
287
|
end
|
288
288
|
end
|
@@ -291,7 +291,7 @@ describe Apipie::ParamDescription do
|
|
291
291
|
context 'when a blank but invalid value is passed' do
|
292
292
|
let(:validation_value) { '' }
|
293
293
|
|
294
|
-
it '
|
294
|
+
it 'raises an error' do
|
295
295
|
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
296
296
|
end
|
297
297
|
end
|
@@ -304,7 +304,7 @@ describe Apipie::ParamDescription do
|
|
304
304
|
context 'when a blank but invalid value is passed' do
|
305
305
|
let(:validation_value) { '' }
|
306
306
|
|
307
|
-
it '
|
307
|
+
it 'raises an error' do
|
308
308
|
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
309
309
|
end
|
310
310
|
end
|
@@ -315,7 +315,7 @@ describe Apipie::ParamDescription do
|
|
315
315
|
context 'when and empty string is given' do
|
316
316
|
let(:validation_value) { '' }
|
317
317
|
|
318
|
-
it '
|
318
|
+
it 'does not raise an error' do
|
319
319
|
expect { subject }.not_to raise_error
|
320
320
|
end
|
321
321
|
end
|
@@ -335,27 +335,27 @@ describe Apipie::ParamDescription do
|
|
335
335
|
Apipie::MethodDescription.new(:show, concern_resource_desc, concern_dsl_data)
|
336
336
|
end
|
337
337
|
|
338
|
-
it "
|
338
|
+
it "replaces string parameter name with colon prefix" do
|
339
339
|
param = Apipie::ParamDescription.new(concern_method_desc, ":string_subst", String)
|
340
340
|
expect(param.name).to eq("string")
|
341
341
|
end
|
342
342
|
|
343
|
-
it "
|
343
|
+
it "replaces symbol parameter name" do
|
344
344
|
param = Apipie::ParamDescription.new(concern_method_desc, :concern, String)
|
345
345
|
expect(param.name).to eq(:user)
|
346
346
|
end
|
347
347
|
|
348
|
-
it "
|
348
|
+
it "keeps original value for strings without colon prefixes" do
|
349
349
|
param = Apipie::ParamDescription.new(concern_method_desc, "string_subst", String)
|
350
350
|
expect(param.name).to eq("string_subst")
|
351
351
|
end
|
352
352
|
|
353
|
-
it "
|
353
|
+
it "keeps the original value when a string can't be replaced" do
|
354
354
|
param = Apipie::ParamDescription.new(concern_method_desc, ":param", String)
|
355
355
|
expect(param.name).to eq(":param")
|
356
356
|
end
|
357
357
|
|
358
|
-
it "
|
358
|
+
it "keeps the original value when a symbol can't be replaced" do
|
359
359
|
param = Apipie::ParamDescription.new(concern_method_desc, :param, String)
|
360
360
|
expect(param.name).to eq(:param)
|
361
361
|
end
|
@@ -366,12 +366,12 @@ describe Apipie::ParamDescription do
|
|
366
366
|
|
367
367
|
before { Apipie.configuration.required_by_default = true }
|
368
368
|
|
369
|
-
it "
|
369
|
+
it "sets param as required by default" do
|
370
370
|
param = Apipie::ParamDescription.new(method_desc, :required_by_default, String)
|
371
371
|
expect(param.required).to be true
|
372
372
|
end
|
373
373
|
|
374
|
-
it "
|
374
|
+
it "is possible to set param as optional" do
|
375
375
|
param = Apipie::ParamDescription.new(method_desc, :optional, String, :required => false)
|
376
376
|
expect(param.required).to be false
|
377
377
|
end
|
@@ -382,12 +382,12 @@ describe Apipie::ParamDescription do
|
|
382
382
|
|
383
383
|
before { Apipie.configuration.required_by_default = false }
|
384
384
|
|
385
|
-
it "
|
385
|
+
it "sets param as optional by default" do
|
386
386
|
param = Apipie::ParamDescription.new(method_desc, :optional_by_default, String)
|
387
387
|
expect(param.required).to be false
|
388
388
|
end
|
389
389
|
|
390
|
-
it "
|
390
|
+
it "is possible to set param as required" do
|
391
391
|
param = Apipie::ParamDescription.new(method_desc, :required, String, 'description','required' => true)
|
392
392
|
expect(param.required).to be true
|
393
393
|
end
|
@@ -402,21 +402,21 @@ describe Apipie::ParamDescription do
|
|
402
402
|
end
|
403
403
|
|
404
404
|
context "when the param is required for current action" do
|
405
|
-
it "
|
405
|
+
it "sets param as required" do
|
406
406
|
param = Apipie::ParamDescription.new(method_desc, :required, String, 'description','required' => :create)
|
407
407
|
expect(param.required).to be true
|
408
408
|
end
|
409
409
|
end
|
410
410
|
|
411
411
|
context "when the param is required for multiple actions" do
|
412
|
-
it "
|
412
|
+
it "sets param as required if it match current action" do
|
413
413
|
param = Apipie::ParamDescription.new(method_desc, :required, String, 'description','required' => [:update, :create])
|
414
414
|
expect(param.required).to be true
|
415
415
|
end
|
416
416
|
end
|
417
417
|
|
418
418
|
context "when the param is not required for current action" do
|
419
|
-
it "
|
419
|
+
it "sets param as not required" do
|
420
420
|
param = Apipie::ParamDescription.new(method_desc, :required, String, 'description','required' => :update)
|
421
421
|
expect(param.required).to be false
|
422
422
|
end
|
@@ -500,7 +500,7 @@ describe Apipie::ParamDescription do
|
|
500
500
|
end
|
501
501
|
end
|
502
502
|
|
503
|
-
it "
|
503
|
+
it "includes the nested params in the json" do
|
504
504
|
sub_params = subject.to_json[:params]
|
505
505
|
expect(sub_params.size).to eq(1)
|
506
506
|
sub_param = sub_params.first
|
@@ -518,7 +518,7 @@ describe Apipie::ParamDescription do
|
|
518
518
|
end
|
519
519
|
end
|
520
520
|
|
521
|
-
it "
|
521
|
+
it "includes the nested params in the json" do
|
522
522
|
sub_params = subject.to_json[:params]
|
523
523
|
expect(sub_params.size).to eq(1)
|
524
524
|
sub_param = sub_params.first
|
@@ -534,7 +534,7 @@ describe Apipie::ParamDescription do
|
|
534
534
|
Apipie::ParamDescription.new(method_desc, :param, String)
|
535
535
|
end
|
536
536
|
|
537
|
-
it "
|
537
|
+
it "includes the nested params in the json" do
|
538
538
|
expect(subject.to_json[:params]).to be_nil
|
539
539
|
end
|
540
540
|
|
@@ -543,7 +543,7 @@ describe Apipie::ParamDescription do
|
|
543
543
|
end
|
544
544
|
|
545
545
|
describe "Array with classes" do
|
546
|
-
it "
|
546
|
+
it "is valid for objects included in class array" do
|
547
547
|
param = Apipie::ParamDescription.new(method_desc, :param, [Integer, String])
|
548
548
|
expect { param.validate("1") }.not_to raise_error
|
549
549
|
expect { param.validate(Integer) }.to raise_error(Apipie::ParamInvalid)
|
@@ -20,7 +20,7 @@ describe "param groups" do
|
|
20
20
|
expect(user_create_params.map(&:to_s).sort).to eq(%w[membership name pass])
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "allows adding additional params to group" do
|
24
24
|
user_create_desc = Apipie["users#create"].params[:user]
|
25
25
|
user_create_params = user_create_desc.validator.params_ordered.map(&:name)
|
26
26
|
expect(user_create_params.map(&:to_s).sort).to eq(%w[membership name pass permalink])
|
@@ -43,16 +43,16 @@ describe "param groups" do
|
|
43
43
|
expect(arch_v1_params.sort_by(&:to_s)).to eq(arch_v2_params.sort_by(&:to_s))
|
44
44
|
end
|
45
45
|
|
46
|
-
it "
|
46
|
+
it "replaces parameter name in a group when it comes from concern" do
|
47
47
|
expect(Apipie["overridden_concern_resources#update"].params.key?(:user)).to eq(true)
|
48
48
|
end
|
49
49
|
|
50
|
-
it "
|
50
|
+
it "does not replace parameter name in a group redefined in the controller" do
|
51
51
|
expect(Apipie["overridden_concern_resources#create"].params.key?(:concern)).to eq(true)
|
52
52
|
expect(Apipie["overridden_concern_resources#create"].params.key?(:user)).to eq(false)
|
53
53
|
end
|
54
54
|
|
55
|
-
it "
|
55
|
+
it "does not replace name of a parameter defined in the controller" do
|
56
56
|
expect(Apipie["overridden_concern_resources#custom"].params.key?(:concern)).to eq(true)
|
57
57
|
expect(Apipie["overridden_concern_resources#custom"].params.key?(:user)).to eq(false)
|
58
58
|
end
|
@@ -25,7 +25,7 @@ describe Apipie::ResourceDescription do
|
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
28
|
+
it 'is ordered' do
|
29
29
|
expect(methods.keys).to eq([:a, :b, :c])
|
30
30
|
end
|
31
31
|
end
|
@@ -63,7 +63,7 @@ describe Apipie::ResourceDescription do
|
|
63
63
|
)
|
64
64
|
end
|
65
65
|
|
66
|
-
it '
|
66
|
+
it 'is ordered' do
|
67
67
|
expect(methods_as_json.map { |h| h[:name] }).to eq(%w[a b c])
|
68
68
|
end
|
69
69
|
end
|
@@ -20,22 +20,22 @@ describe Apipie::Validator do
|
|
20
20
|
|
21
21
|
context "expected type" do
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "returns hash for type Hash" do
|
24
24
|
validator = Apipie::Validator::TypeValidator.new(params_desc, Hash)
|
25
25
|
expect(validator.expected_type).to eq('hash')
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "returns array for type Array" do
|
29
29
|
validator = Apipie::Validator::TypeValidator.new(params_desc, Array)
|
30
30
|
expect(validator.expected_type).to eq('array')
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "returns numeric for type Numeric" do
|
34
34
|
validator = Apipie::Validator::TypeValidator.new(params_desc, Numeric)
|
35
35
|
expect(validator.expected_type).to eq('numeric')
|
36
36
|
end
|
37
37
|
|
38
|
-
it "
|
38
|
+
it "returns string by default" do
|
39
39
|
validator = Apipie::Validator::TypeValidator.new(params_desc, Symbol)
|
40
40
|
expect(validator.expected_type).to eq('string')
|
41
41
|
end
|
@@ -43,7 +43,7 @@ describe Apipie::Validator do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe 'NumberValidator' do
|
46
|
-
it '
|
46
|
+
it 'expects a Numeric type' do
|
47
47
|
validator = Apipie::Validator::BaseValidator.find(params_desc, :number, nil, nil)
|
48
48
|
expect(validator.expected_type).to eq('numeric')
|
49
49
|
end
|
@@ -86,7 +86,7 @@ describe Apipie::Validator do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
describe '#validate' do
|
89
|
-
it "
|
89
|
+
it "validates by object class" do
|
90
90
|
expect(validator_instance.validate("1")).to be_truthy
|
91
91
|
expect(validator_instance.validate(1)).to be_truthy
|
92
92
|
expect(validator_instance.validate(true)).to be_truthy
|
@@ -104,21 +104,21 @@ describe Apipie::Validator do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
describe 'ArrayClassValidator' do
|
107
|
-
it "
|
107
|
+
it "validates by object class" do
|
108
108
|
validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [Integer, String])
|
109
109
|
expect(validator.validate("1")).to be_truthy
|
110
110
|
expect(validator.validate(1)).to be_truthy
|
111
111
|
expect(validator.validate({ 1 => 1 })).to be_falsey
|
112
112
|
end
|
113
113
|
|
114
|
-
it "
|
114
|
+
it "has a valid description" do
|
115
115
|
validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [Float, String])
|
116
116
|
expect(validator.description).to eq('Must be one of: <code>Float</code>, <code>String</code>.')
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
describe 'RegexpValidator' do
|
121
|
-
it "
|
121
|
+
it "validates by object class" do
|
122
122
|
validator = Apipie::Validator::RegexpValidator.new(params_desc, /^valid( extra)*$/)
|
123
123
|
expect(validator.validate("valid")).to be_truthy
|
124
124
|
expect(validator.validate("valid extra")).to be_truthy
|
@@ -126,14 +126,14 @@ describe Apipie::Validator do
|
|
126
126
|
expect(validator.validate("invalid")).to be_falsey
|
127
127
|
end
|
128
128
|
|
129
|
-
it "
|
129
|
+
it "has a valid description" do
|
130
130
|
validator = Apipie::Validator::RegexpValidator.new(params_desc, /^valid( extra)*$/)
|
131
131
|
expect(validator.description).to eq('Must match regular expression <code>/^valid( extra)*$/</code>.')
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
describe 'EnumValidator' do
|
136
|
-
it "
|
136
|
+
it "validates by object class" do
|
137
137
|
validator = Apipie::Validator::EnumValidator.new(params_desc, ['first', 'second & third'])
|
138
138
|
expect(validator.validate("first")).to be_truthy
|
139
139
|
expect(validator.validate("second & third")).to be_truthy
|
@@ -141,7 +141,7 @@ describe Apipie::Validator do
|
|
141
141
|
expect(validator.validate({ 1 => 1 })).to be_falsey
|
142
142
|
end
|
143
143
|
|
144
|
-
it "
|
144
|
+
it "has a valid description" do
|
145
145
|
validator = Apipie::Validator::EnumValidator.new(params_desc, ['first', 'second & third'])
|
146
146
|
expect(validator.description).to eq('Must be one of: <code>first</code>, <code>second & third</code>.')
|
147
147
|
end
|