grape 1.0.1 → 1.0.2

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.

Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +1 -1
  3. data/CHANGELOG.md +18 -0
  4. data/Dangerfile +1 -0
  5. data/Gemfile +9 -10
  6. data/Gemfile.lock +42 -40
  7. data/LICENSE +1 -1
  8. data/README.md +89 -40
  9. data/Rakefile +1 -46
  10. data/gemfiles/multi_json.gemfile +9 -10
  11. data/gemfiles/multi_xml.gemfile +9 -10
  12. data/gemfiles/rack_1.5.2.gemfile +9 -10
  13. data/gemfiles/rack_edge.gemfile +9 -10
  14. data/gemfiles/rails_3.gemfile +9 -10
  15. data/gemfiles/rails_4.gemfile +9 -10
  16. data/gemfiles/rails_5.gemfile +9 -10
  17. data/gemfiles/rails_edge.gemfile +9 -10
  18. data/grape.gemspec +3 -3
  19. data/lib/grape/api.rb +2 -2
  20. data/lib/grape/dsl/inside_route.rb +30 -10
  21. data/lib/grape/dsl/routing.rb +1 -1
  22. data/lib/grape/dsl/settings.rb +6 -6
  23. data/lib/grape/endpoint.rb +1 -1
  24. data/lib/grape/exceptions/incompatible_option_values.rb +0 -1
  25. data/lib/grape/exceptions/invalid_accept_header.rb +0 -1
  26. data/lib/grape/exceptions/invalid_formatter.rb +0 -1
  27. data/lib/grape/exceptions/invalid_message_body.rb +0 -1
  28. data/lib/grape/exceptions/invalid_version_header.rb +0 -1
  29. data/lib/grape/exceptions/invalid_versioner_option.rb +0 -1
  30. data/lib/grape/exceptions/invalid_with_option_for_represent.rb +0 -1
  31. data/lib/grape/exceptions/method_not_allowed.rb +0 -1
  32. data/lib/grape/exceptions/missing_group_type.rb +0 -1
  33. data/lib/grape/exceptions/missing_mime_type.rb +0 -1
  34. data/lib/grape/exceptions/missing_option.rb +0 -1
  35. data/lib/grape/exceptions/missing_vendor_option.rb +0 -1
  36. data/lib/grape/exceptions/unknown_options.rb +0 -1
  37. data/lib/grape/exceptions/unknown_parameter.rb +0 -1
  38. data/lib/grape/exceptions/unknown_validator.rb +0 -1
  39. data/lib/grape/exceptions/unsupported_group_type.rb +0 -1
  40. data/lib/grape/namespace.rb +1 -1
  41. data/lib/grape/router.rb +2 -0
  42. data/lib/grape/router/pattern.rb +1 -1
  43. data/lib/grape/router/route.rb +14 -14
  44. data/lib/grape/validations/params_scope.rb +3 -4
  45. data/lib/grape/validations/types.rb +14 -1
  46. data/lib/grape/validations/types/build_coercer.rb +8 -0
  47. data/lib/grape/validations/types/custom_type_coercer.rb +1 -1
  48. data/lib/grape/validations/types/custom_type_collection_coercer.rb +71 -0
  49. data/lib/grape/validations/validators/allow_blank.rb +1 -1
  50. data/lib/grape/validations/validators/base.rb +1 -0
  51. data/lib/grape/validations/validators/coerce.rb +6 -0
  52. data/lib/grape/version.rb +1 -1
  53. data/pkg/grape-1.0.1.gem +0 -0
  54. data/spec/grape/api_spec.rb +22 -12
  55. data/spec/grape/dsl/inside_route_spec.rb +1 -1
  56. data/spec/grape/dsl/parameters_spec.rb +5 -5
  57. data/spec/grape/dsl/settings_spec.rb +2 -2
  58. data/spec/grape/endpoint_spec.rb +25 -12
  59. data/spec/grape/entity_spec.rb +1 -1
  60. data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -1
  61. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -1
  62. data/spec/grape/exceptions/missing_option_spec.rb +0 -1
  63. data/spec/grape/exceptions/unknown_options_spec.rb +1 -2
  64. data/spec/grape/exceptions/unknown_validator_spec.rb +0 -1
  65. data/spec/grape/exceptions/validation_errors_spec.rb +1 -1
  66. data/spec/grape/middleware/exception_spec.rb +36 -12
  67. data/spec/grape/middleware/formatter_spec.rb +1 -1
  68. data/spec/grape/middleware/versioner/header_spec.rb +1 -1
  69. data/spec/grape/middleware/versioner/param_spec.rb +1 -1
  70. data/spec/grape/middleware/versioner/path_spec.rb +1 -1
  71. data/spec/grape/path_spec.rb +3 -3
  72. data/spec/grape/util/inheritable_setting_spec.rb +2 -2
  73. data/spec/grape/util/reverse_stackable_values_spec.rb +13 -13
  74. data/spec/grape/util/stackable_values_spec.rb +13 -13
  75. data/spec/grape/util/strict_hash_configuration_spec.rb +1 -1
  76. data/spec/grape/validations/params_scope_spec.rb +19 -7
  77. data/spec/grape/validations/validators/all_or_none_spec.rb +1 -1
  78. data/spec/grape/validations/validators/at_least_one_of_spec.rb +1 -1
  79. data/spec/grape/validations/validators/coerce_spec.rb +94 -13
  80. data/spec/grape/validations/validators/default_spec.rb +40 -0
  81. data/spec/grape/validations/validators/exactly_one_of_spec.rb +1 -1
  82. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +1 -1
  83. data/spec/grape/validations/validators/values_spec.rb +3 -3
  84. data/spec/grape/validations_spec.rb +9 -9
  85. data/spec/shared/versioning_examples.rb +58 -0
  86. data/spec/support/content_type_helpers.rb +1 -1
  87. metadata +26 -24
@@ -9,7 +9,7 @@ describe Grape::Validations::MutualExclusionValidator do
9
9
  end
10
10
  end
11
11
  end
12
- let(:mutually_exclusive_params) { [:beer, :wine, :grapefruit] }
12
+ let(:mutually_exclusive_params) { %i[beer wine grapefruit] }
13
13
  let(:validator) { described_class.new(mutually_exclusive_params, {}, false, scope.new) }
14
14
 
15
15
  context 'when all mutually exclusive params are present' do
@@ -159,7 +159,7 @@ describe Grape::Validations::ValuesValidator do
159
159
 
160
160
  params do
161
161
  optional :optional, type: Array do
162
- requires :type, values: %w(a b)
162
+ requires :type, values: %w[a b]
163
163
  end
164
164
  end
165
165
  get '/optional_with_required_values'
@@ -207,7 +207,7 @@ describe Grape::Validations::ValuesValidator do
207
207
  end
208
208
 
209
209
  params do
210
- optional :optional, type: Array[String], values: %w(a b c)
210
+ optional :optional, type: Array[String], values: %w[a b c]
211
211
  end
212
212
  put '/optional_with_array_of_string_values'
213
213
 
@@ -555,7 +555,7 @@ describe Grape::Validations::ValuesValidator do
555
555
  end
556
556
 
557
557
  it 'rejects an array of values if any of them matches except' do
558
- get '/except/exclusive', type: %w(valid1 valid2 invalid-type1 valid4)
558
+ get '/except/exclusive', type: %w[valid1 valid2 invalid-type1 valid4]
559
559
  expect(last_response.status).to eq 400
560
560
  expect(last_response.body).to eq({ error: 'type has a value not allowed' }.to_json)
561
561
  end
@@ -63,7 +63,7 @@ describe Grape::Validations do
63
63
 
64
64
  it 'adds entity documentation to declared params' do
65
65
  define_optional_using
66
- expect(subject.route_setting(:declared_params)).to eq([:field_a, :field_b])
66
+ expect(subject.route_setting(:declared_params)).to eq(%i[field_a field_b])
67
67
  end
68
68
 
69
69
  it 'works when field_a and field_b are not present' do
@@ -139,7 +139,7 @@ describe Grape::Validations do
139
139
 
140
140
  it 'adds entity documentation to declared params' do
141
141
  define_requires_all
142
- expect(subject.route_setting(:declared_params)).to eq([:required_field, :optional_field])
142
+ expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field])
143
143
  end
144
144
 
145
145
  it 'errors when required_field is not present' do
@@ -174,7 +174,7 @@ describe Grape::Validations do
174
174
 
175
175
  it 'adds entity documentation to declared params' do
176
176
  define_requires_none
177
- expect(subject.route_setting(:declared_params)).to eq([:required_field, :optional_field])
177
+ expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field])
178
178
  end
179
179
 
180
180
  it 'errors when required_field is not present' do
@@ -204,7 +204,7 @@ describe Grape::Validations do
204
204
 
205
205
  it 'adds only the entity documentation to declared params, nothing more' do
206
206
  define_requires_all
207
- expect(subject.route_setting(:declared_params)).to eq([:required_field, :optional_field])
207
+ expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field])
208
208
  end
209
209
  end
210
210
 
@@ -350,7 +350,7 @@ describe Grape::Validations do
350
350
  before do
351
351
  subject.params do
352
352
  requires :items, type: Hash do
353
- requires :key, type: String, values: %w(a b)
353
+ requires :key, type: String, values: %w[a b]
354
354
  end
355
355
  end
356
356
  subject.get '/required' do
@@ -1058,14 +1058,14 @@ describe Grape::Validations do
1058
1058
  subject.params do
1059
1059
  use :pagination
1060
1060
  end
1061
- expect(subject.route_setting(:declared_params)).to eq [:page, :per_page]
1061
+ expect(subject.route_setting(:declared_params)).to eq %i[page per_page]
1062
1062
  end
1063
1063
 
1064
1064
  it 'by #use with multiple params' do
1065
1065
  subject.params do
1066
1066
  use :pagination, :period
1067
1067
  end
1068
- expect(subject.route_setting(:declared_params)).to eq [:page, :per_page, :start_date, :end_date]
1068
+ expect(subject.route_setting(:declared_params)).to eq %i[page per_page start_date end_date]
1069
1069
  end
1070
1070
  end
1071
1071
 
@@ -1073,13 +1073,13 @@ describe Grape::Validations do
1073
1073
  before do
1074
1074
  subject.helpers do
1075
1075
  params :order do |options|
1076
- optional :order, type: Symbol, values: [:asc, :desc], default: options[:default_order]
1076
+ optional :order, type: Symbol, values: %i[asc desc], default: options[:default_order]
1077
1077
  optional :order_by, type: Symbol, values: options[:order_by], default: options[:default_order_by]
1078
1078
  end
1079
1079
  end
1080
1080
  subject.format :json
1081
1081
  subject.params do
1082
- use :order, default_order: :asc, order_by: [:name, :created_at], default_order_by: :created_at
1082
+ use :order, default_order: :asc, order_by: %i[name created_at], default_order_by: :created_at
1083
1083
  end
1084
1084
  subject.get '/order' do
1085
1085
  {
@@ -149,4 +149,62 @@ shared_examples_for 'versioning' do
149
149
  versioned_get '/api_version_with_version_param?version=1', 'v1', macro_options
150
150
  expect(last_response.body).to eql '1'
151
151
  end
152
+
153
+ context 'with catch-all' do
154
+ let(:options) { macro_options }
155
+ let(:v1) do
156
+ klass = Class.new(Grape::API)
157
+ klass.version 'v1', options
158
+ klass.get 'version' do
159
+ 'v1'
160
+ end
161
+ klass
162
+ end
163
+ let(:v2) do
164
+ klass = Class.new(Grape::API)
165
+ klass.version 'v2', options
166
+ klass.get 'version' do
167
+ 'v2'
168
+ end
169
+ klass
170
+ end
171
+ before do
172
+ subject.format :txt
173
+
174
+ subject.mount v1
175
+ subject.mount v2
176
+
177
+ subject.route :any, '*path' do
178
+ params[:path]
179
+ end
180
+ end
181
+
182
+ context 'v1' do
183
+ it 'finds endpoint' do
184
+ versioned_get '/version', 'v1', macro_options
185
+ expect(last_response.status).to eq(200)
186
+ expect(last_response.body).to eq('v1')
187
+ end
188
+
189
+ it 'finds catch all' do
190
+ versioned_get '/whatever', 'v1', macro_options
191
+ expect(last_response.status).to eq(200)
192
+ expect(last_response.body).to end_with 'whatever'
193
+ end
194
+ end
195
+
196
+ context 'v2' do
197
+ it 'finds endpoint' do
198
+ versioned_get '/version', 'v2', macro_options
199
+ expect(last_response.status).to eq(200)
200
+ expect(last_response.body).to eq('v2')
201
+ end
202
+
203
+ it 'finds catch all' do
204
+ versioned_get '/whatever', 'v2', macro_options
205
+ expect(last_response.status).to eq(200)
206
+ expect(last_response.body).to end_with 'whatever'
207
+ end
208
+ end
209
+ end
152
210
  end
@@ -1,7 +1,7 @@
1
1
  module Spec
2
2
  module Support
3
3
  module Helpers
4
- %w(put patch post delete).each do |method|
4
+ %w[put patch post delete].each do |method|
5
5
  define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block|
6
6
  params = params.to_json
7
7
  env['CONTENT_TYPE'] ||= 'application/json'
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-08 00:00:00.000000000 Z
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rack
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.0
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: builder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mustermann-grape
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -39,21 +53,21 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: 1.0.0
41
55
  - !ruby/object:Gem::Dependency
42
- name: rack-accept
56
+ name: rack
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: 1.3.0
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 1.3.0
55
69
  - !ruby/object:Gem::Dependency
56
- name: activesupport
70
+ name: rack-accept
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -80,20 +94,6 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: 1.0.0
83
- - !ruby/object:Gem::Dependency
84
- name: builder
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
97
  description: A Ruby framework for rapid API development with great conventions.
98
98
  email:
99
99
  - michael@intridea.com
@@ -228,6 +228,7 @@ files:
228
228
  - lib/grape/validations/types.rb
229
229
  - lib/grape/validations/types/build_coercer.rb
230
230
  - lib/grape/validations/types/custom_type_coercer.rb
231
+ - lib/grape/validations/types/custom_type_collection_coercer.rb
231
232
  - lib/grape/validations/types/file.rb
232
233
  - lib/grape/validations/types/json.rb
233
234
  - lib/grape/validations/types/multiple_type_coercer.rb
@@ -250,6 +251,7 @@ files:
250
251
  - lib/grape/validations/validators/values.rb
251
252
  - lib/grape/version.rb
252
253
  - pkg/grape-0.19.1.gem
254
+ - pkg/grape-1.0.1.gem
253
255
  - spec/grape/api/custom_validations_spec.rb
254
256
  - spec/grape/api/deeply_included_options_spec.rb
255
257
  - spec/grape/api/inherited_helpers_spec.rb
@@ -366,7 +368,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
366
368
  version: '0'
367
369
  requirements: []
368
370
  rubyforge_project:
369
- rubygems_version: 2.6.10
371
+ rubygems_version: 2.7.3
370
372
  signing_key:
371
373
  specification_version: 4
372
374
  summary: A simple Ruby framework for building REST-like APIs.