grape 1.2.3 → 1.2.4

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.
@@ -472,12 +472,12 @@ describe Grape::Endpoint do
472
472
  expect(last_response.status).to eq(200)
473
473
  end
474
474
 
475
- it 'does not include aliased missing attributes if that option is passed' do
475
+ it 'does not include renamed missing attributes if that option is passed' do
476
476
  subject.params do
477
- optional :aliased_original, as: :aliased
477
+ optional :renamed_original, as: :renamed
478
478
  end
479
479
  subject.get '/declared' do
480
- error! 'expected nil', 400 if declared(params, include_missing: false).key?(:aliased)
480
+ error! 'expected nil', 400 if declared(params, include_missing: false).key?(:renamed)
481
481
  ''
482
482
  end
483
483
 
@@ -1089,6 +1089,36 @@ describe Grape::Endpoint do
1089
1089
  expect(last_response.headers['X-Custom']).to eq('value')
1090
1090
  end
1091
1091
 
1092
+ it 'merges additional headers with headers set before call' do
1093
+ subject.before do
1094
+ header 'X-Before-Test', 'before-sample'
1095
+ end
1096
+
1097
+ subject.get '/hey' do
1098
+ header 'X-Test', 'test-sample'
1099
+ error!({ 'dude' => 'rad' }, 403, 'X-Error' => 'error')
1100
+ end
1101
+
1102
+ get '/hey.json'
1103
+ expect(last_response.headers['X-Before-Test']).to eq('before-sample')
1104
+ expect(last_response.headers['X-Test']).to eq('test-sample')
1105
+ expect(last_response.headers['X-Error']).to eq('error')
1106
+ end
1107
+
1108
+ it 'does not merges additional headers with headers set after call' do
1109
+ subject.after do
1110
+ header 'X-After-Test', 'after-sample'
1111
+ end
1112
+
1113
+ subject.get '/hey' do
1114
+ error!({ 'dude' => 'rad' }, 403, 'X-Error' => 'error')
1115
+ end
1116
+
1117
+ get '/hey.json'
1118
+ expect(last_response.headers['X-Error']).to eq('error')
1119
+ expect(last_response.headers['X-After-Test']).to be_nil
1120
+ end
1121
+
1092
1122
  it 'sets the status code for the endpoint' do
1093
1123
  memoized_endpoint = nil
1094
1124
 
@@ -1492,6 +1522,9 @@ describe Grape::Endpoint do
1492
1522
  have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1493
1523
  filters: [],
1494
1524
  type: :after }),
1525
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1526
+ filters: [],
1527
+ type: :finally }),
1495
1528
  have_attributes(name: 'endpoint_run.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1496
1529
  env: an_instance_of(Hash) }),
1497
1530
  have_attributes(name: 'format_response.grape', payload: { env: an_instance_of(Hash),
@@ -1518,6 +1551,9 @@ describe Grape::Endpoint do
1518
1551
  have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1519
1552
  filters: [],
1520
1553
  type: :after }),
1554
+ have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1555
+ filters: [],
1556
+ type: :finally }),
1521
1557
  have_attributes(name: 'format_response.grape', payload: { env: an_instance_of(Hash),
1522
1558
  formatter: a_kind_of(Module) })
1523
1559
  )
@@ -121,14 +121,14 @@ describe Grape::Validations::ParamsScope do
121
121
  end
122
122
  end
123
123
 
124
- context 'param alias' do
124
+ context 'param renaming' do
125
125
  it do
126
126
  subject.params do
127
127
  requires :foo, as: :bar
128
128
  optional :super, as: :hiper
129
129
  end
130
- subject.get('/alias') { "#{declared(params)['bar']}-#{declared(params)['hiper']}" }
131
- get '/alias', foo: 'any', super: 'any2'
130
+ subject.get('/renaming') { "#{declared(params)['bar']}-#{declared(params)['hiper']}" }
131
+ get '/renaming', foo: 'any', super: 'any2'
132
132
 
133
133
  expect(last_response.status).to eq(200)
134
134
  expect(last_response.body).to eq('any-any2')
@@ -138,8 +138,8 @@ describe Grape::Validations::ParamsScope do
138
138
  subject.params do
139
139
  requires :foo, as: :bar, type: String, coerce_with: ->(c) { c.strip }
140
140
  end
141
- subject.get('/alias-coerced') { "#{params['bar']}-#{params['foo']}" }
142
- get '/alias-coerced', foo: ' there we go '
141
+ subject.get('/renaming-coerced') { "#{params['bar']}-#{params['foo']}" }
142
+ get '/renaming-coerced', foo: ' there we go '
143
143
 
144
144
  expect(last_response.status).to eq(200)
145
145
  expect(last_response.body).to eq('there we go-')
@@ -149,8 +149,8 @@ describe Grape::Validations::ParamsScope do
149
149
  subject.params do
150
150
  requires :foo, as: :bar, allow_blank: false
151
151
  end
152
- subject.get('/alias-not-blank') {}
153
- get '/alias-not-blank', foo: ''
152
+ subject.get('/renaming-not-blank') {}
153
+ get '/renaming-not-blank', foo: ''
154
154
 
155
155
  expect(last_response.status).to eq(400)
156
156
  expect(last_response.body).to eq('foo is empty')
@@ -160,8 +160,8 @@ describe Grape::Validations::ParamsScope do
160
160
  subject.params do
161
161
  requires :foo, as: :bar, allow_blank: false
162
162
  end
163
- subject.get('/alias-not-blank-with-value') {}
164
- get '/alias-not-blank-with-value', foo: 'any'
163
+ subject.get('/renaming-not-blank-with-value') {}
164
+ get '/renaming-not-blank-with-value', foo: 'any'
165
165
 
166
166
  expect(last_response.status).to eq(200)
167
167
  end
@@ -532,7 +532,7 @@ describe Grape::Validations::ParamsScope do
532
532
  expect(last_response.body).to eq({ a: 'a', b: 'b', c: 'c', d: 'd' }.to_json)
533
533
  end
534
534
 
535
- it 'allows aliasing of dependent parameters' do
535
+ it 'allows renaming of dependent parameters' do
536
536
  subject.params do
537
537
  optional :a
538
538
  given :a do
@@ -550,7 +550,7 @@ describe Grape::Validations::ParamsScope do
550
550
  expect(body.keys).to_not include('b')
551
551
  end
552
552
 
553
- it 'allows aliasing of dependent on parameter' do
553
+ it 'allows renaming of dependent on parameter' do
554
554
  subject.params do
555
555
  optional :a, as: :b
556
556
  given b: ->(val) { val == 'x' } do
@@ -567,7 +567,7 @@ describe Grape::Validations::ParamsScope do
567
567
  expect(last_response.status).to eq 200
568
568
  end
569
569
 
570
- it 'raises an error if the dependent parameter is not the aliased one' do
570
+ it 'raises an error if the dependent parameter is not the renamed one' do
571
571
  expect do
572
572
  subject.params do
573
573
  optional :a, as: :b
@@ -700,6 +700,26 @@ describe Grape::Validations::ParamsScope do
700
700
  end
701
701
 
702
702
  context 'when validations are dependent on a parameter within an array param' do
703
+ before do
704
+ subject.params do
705
+ requires :foos, type: Array do
706
+ optional :foo
707
+ given :foo do
708
+ requires :bar
709
+ end
710
+ end
711
+ end
712
+ subject.get('/test') { 'ok' }
713
+ end
714
+
715
+ it 'should pass none Hash params' do
716
+ get '/test', foos: ['']
717
+ expect(last_response.status).to eq(200)
718
+ expect(last_response.body).to eq('ok')
719
+ end
720
+ end
721
+
722
+ context 'when validations are dependent on a parameter within an array param within #declared(params).to_json' do
703
723
  before do
704
724
  subject.params do
705
725
  requires :foos, type: Array do
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: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-16 00:00:00.000000000 Z
11
+ date: 2019-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -126,7 +126,6 @@ files:
126
126
  - gemfiles/rails_5.gemfile
127
127
  - gemfiles/rails_5.gemfile.lock
128
128
  - gemfiles/rails_edge.gemfile
129
- - gemfiles/rails_edge.gemfile.lock
130
129
  - grape.gemspec
131
130
  - grape.png
132
131
  - lib/grape.rb
@@ -220,10 +219,12 @@ files:
220
219
  - lib/grape/serve_file/file_response.rb
221
220
  - lib/grape/serve_file/sendfile_response.rb
222
221
  - lib/grape/util/content_types.rb
222
+ - lib/grape/util/endpoint_configuration.rb
223
223
  - lib/grape/util/env.rb
224
224
  - lib/grape/util/inheritable_setting.rb
225
225
  - lib/grape/util/inheritable_values.rb
226
226
  - lib/grape/util/json.rb
227
+ - lib/grape/util/lazy_value.rb
227
228
  - lib/grape/util/registrable.rb
228
229
  - lib/grape/util/reverse_stackable_values.rb
229
230
  - lib/grape/util/stackable_values.rb
@@ -260,6 +261,7 @@ files:
260
261
  - lib/grape/version.rb
261
262
  - pkg/grape-1.2.0.gem
262
263
  - pkg/grape-1.2.1.gem
264
+ - pkg/grape-1.2.3.gem
263
265
  - spec/grape/api/custom_validations_spec.rb
264
266
  - spec/grape/api/deeply_included_options_spec.rb
265
267
  - spec/grape/api/inherited_helpers_spec.rb
@@ -1,335 +0,0 @@
1
- GIT
2
- remote: git://github.com/rails/rails.git
3
- revision: bad1041b82df941d588ae2565f62424d88104933
4
- specs:
5
- actioncable (6.0.0.alpha)
6
- actionpack (= 6.0.0.alpha)
7
- nio4r (~> 2.0)
8
- websocket-driver (>= 0.6.1)
9
- actionmailer (6.0.0.alpha)
10
- actionpack (= 6.0.0.alpha)
11
- actionview (= 6.0.0.alpha)
12
- activejob (= 6.0.0.alpha)
13
- mail (~> 2.5, >= 2.5.4)
14
- rails-dom-testing (~> 2.0)
15
- actionpack (6.0.0.alpha)
16
- actionview (= 6.0.0.alpha)
17
- activesupport (= 6.0.0.alpha)
18
- rack (~> 2.0)
19
- rack-test (>= 0.6.3)
20
- rails-dom-testing (~> 2.0)
21
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
22
- actionview (6.0.0.alpha)
23
- activesupport (= 6.0.0.alpha)
24
- builder (~> 3.1)
25
- erubi (~> 1.4)
26
- rails-dom-testing (~> 2.0)
27
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
28
- activejob (6.0.0.alpha)
29
- activesupport (= 6.0.0.alpha)
30
- globalid (>= 0.3.6)
31
- activemodel (6.0.0.alpha)
32
- activesupport (= 6.0.0.alpha)
33
- activerecord (6.0.0.alpha)
34
- activemodel (= 6.0.0.alpha)
35
- activesupport (= 6.0.0.alpha)
36
- activestorage (6.0.0.alpha)
37
- actionpack (= 6.0.0.alpha)
38
- activerecord (= 6.0.0.alpha)
39
- marcel (~> 0.3.1)
40
- activesupport (6.0.0.alpha)
41
- concurrent-ruby (~> 1.0, >= 1.0.2)
42
- i18n (>= 0.7, < 2)
43
- minitest (~> 5.1)
44
- tzinfo (~> 1.1)
45
- rails (6.0.0.alpha)
46
- actioncable (= 6.0.0.alpha)
47
- actionmailer (= 6.0.0.alpha)
48
- actionpack (= 6.0.0.alpha)
49
- actionview (= 6.0.0.alpha)
50
- activejob (= 6.0.0.alpha)
51
- activemodel (= 6.0.0.alpha)
52
- activerecord (= 6.0.0.alpha)
53
- activestorage (= 6.0.0.alpha)
54
- activesupport (= 6.0.0.alpha)
55
- bundler (>= 1.3.0)
56
- railties (= 6.0.0.alpha)
57
- sprockets-rails (>= 2.0.0)
58
- railties (6.0.0.alpha)
59
- actionpack (= 6.0.0.alpha)
60
- activesupport (= 6.0.0.alpha)
61
- method_source
62
- rake (>= 0.8.7)
63
- thor (>= 0.20.3, < 2.0)
64
-
65
- PATH
66
- remote: ..
67
- specs:
68
- grape (1.2.3)
69
- activesupport
70
- builder
71
- mustermann-grape (~> 1.0.0)
72
- rack (>= 1.3.0)
73
- rack-accept
74
- virtus (>= 1.0.0)
75
-
76
- GEM
77
- remote: https://rubygems.org/
78
- specs:
79
- addressable (2.5.2)
80
- public_suffix (>= 2.0.2, < 4.0)
81
- appraisal (2.2.0)
82
- bundler
83
- rake
84
- thor (>= 0.14.0)
85
- ast (2.4.0)
86
- axiom-types (0.1.1)
87
- descendants_tracker (~> 0.0.4)
88
- ice_nine (~> 0.11.0)
89
- thread_safe (~> 0.3, >= 0.3.1)
90
- benchmark-ips (2.7.2)
91
- builder (3.2.3)
92
- claide (1.0.2)
93
- claide-plugins (0.9.2)
94
- cork
95
- nap
96
- open4 (~> 1.3)
97
- coderay (1.1.2)
98
- coercible (1.0.0)
99
- descendants_tracker (~> 0.0.1)
100
- colored (1.2)
101
- colored2 (3.1.2)
102
- concurrent-ruby (1.1.3)
103
- cookiejar (0.3.3)
104
- cork (0.3.0)
105
- colored2 (~> 3.1)
106
- coveralls (0.7.1)
107
- multi_json (~> 1.3)
108
- rest-client
109
- simplecov (>= 0.7)
110
- term-ansicolor
111
- thor
112
- crass (1.0.4)
113
- danger (4.0.5)
114
- claide (~> 1.0)
115
- claide-plugins (>= 0.9.2)
116
- colored (~> 1.2)
117
- cork (~> 0.1)
118
- faraday (~> 0.9)
119
- faraday-http-cache (~> 1.0)
120
- git (~> 1)
121
- kramdown (~> 1.5)
122
- octokit (~> 4.2)
123
- terminal-table (~> 1)
124
- danger-changelog (0.2.1)
125
- danger-plugin-api (~> 1.0)
126
- danger-plugin-api (1.0.0)
127
- danger (> 2.0)
128
- danger-toc (0.1.3)
129
- activesupport
130
- danger-plugin-api (~> 1.0)
131
- kramdown
132
- descendants_tracker (0.0.4)
133
- thread_safe (~> 0.3, >= 0.3.1)
134
- diff-lcs (1.3)
135
- docile (1.3.1)
136
- domain_name (0.5.20180417)
137
- unf (>= 0.0.5, < 1.0.0)
138
- equalizer (0.0.11)
139
- erubi (1.7.1)
140
- faraday (0.15.4)
141
- multipart-post (>= 1.2, < 3)
142
- faraday-http-cache (1.3.1)
143
- faraday (~> 0.8)
144
- ffi (1.9.25)
145
- formatador (0.2.5)
146
- git (1.5.0)
147
- globalid (0.4.1)
148
- activesupport (>= 4.2.0)
149
- grape-entity (0.7.1)
150
- activesupport (>= 4.0)
151
- multi_json (>= 1.3.2)
152
- guard (2.15.0)
153
- formatador (>= 0.2.4)
154
- listen (>= 2.7, < 4.0)
155
- lumberjack (>= 1.0.12, < 2.0)
156
- nenv (~> 0.1)
157
- notiffany (~> 0.0)
158
- pry (>= 0.9.12)
159
- shellany (~> 0.0)
160
- thor (>= 0.18.1)
161
- guard-compat (1.2.1)
162
- guard-rspec (4.7.3)
163
- guard (~> 2.1)
164
- guard-compat (~> 1.1)
165
- rspec (>= 2.99.0, < 4.0)
166
- guard-rubocop (1.3.0)
167
- guard (~> 2.0)
168
- rubocop (~> 0.20)
169
- hashie (3.6.0)
170
- http-cookie (1.0.3)
171
- domain_name (~> 0.5)
172
- i18n (1.1.1)
173
- concurrent-ruby (~> 1.0)
174
- ice_nine (0.11.2)
175
- json (2.1.0)
176
- kramdown (1.17.0)
177
- listen (3.1.5)
178
- rb-fsevent (~> 0.9, >= 0.9.4)
179
- rb-inotify (~> 0.9, >= 0.9.7)
180
- ruby_dep (~> 1.2)
181
- loofah (2.2.3)
182
- crass (~> 1.0.2)
183
- nokogiri (>= 1.5.9)
184
- lumberjack (1.0.13)
185
- mail (2.7.1)
186
- mini_mime (>= 0.1.1)
187
- marcel (0.3.3)
188
- mimemagic (~> 0.3.2)
189
- maruku (0.7.3)
190
- method_source (0.9.2)
191
- mime-types (3.2.2)
192
- mime-types-data (~> 3.2015)
193
- mime-types-data (3.2018.0812)
194
- mimemagic (0.3.2)
195
- mini_mime (1.0.1)
196
- mini_portile2 (2.3.0)
197
- minitest (5.11.3)
198
- multi_json (1.13.1)
199
- multipart-post (2.0.0)
200
- mustermann (1.0.3)
201
- mustermann-grape (1.0.0)
202
- mustermann (~> 1.0.0)
203
- nap (1.1.0)
204
- nenv (0.3.0)
205
- netrc (0.11.0)
206
- nio4r (2.3.1)
207
- nokogiri (1.8.5)
208
- mini_portile2 (~> 2.3.0)
209
- notiffany (0.1.1)
210
- nenv (~> 0.1)
211
- shellany (~> 0.0)
212
- octokit (4.13.0)
213
- sawyer (~> 0.8.0, >= 0.5.3)
214
- open4 (1.3.4)
215
- parallel (1.12.1)
216
- parser (2.5.3.0)
217
- ast (~> 2.4.0)
218
- powerpack (0.1.2)
219
- pry (0.12.2)
220
- coderay (~> 1.1.0)
221
- method_source (~> 0.9.0)
222
- public_suffix (3.0.3)
223
- rack (2.0.6)
224
- rack-accept (0.4.5)
225
- rack (>= 0.4)
226
- rack-jsonp (1.3.1)
227
- rack
228
- rack-test (0.6.3)
229
- rack (>= 1.0)
230
- rails-dom-testing (2.0.3)
231
- activesupport (>= 4.2.0)
232
- nokogiri (>= 1.6)
233
- rails-html-sanitizer (1.0.4)
234
- loofah (~> 2.2, >= 2.2.2)
235
- rainbow (2.2.2)
236
- rake
237
- rake (12.3.2)
238
- rb-fsevent (0.10.3)
239
- rb-inotify (0.9.10)
240
- ffi (>= 0.5.0, < 2)
241
- rest-client (2.0.2)
242
- http-cookie (>= 1.0.2, < 2.0)
243
- mime-types (>= 1.16, < 4.0)
244
- netrc (~> 0.8)
245
- rspec (3.8.0)
246
- rspec-core (~> 3.8.0)
247
- rspec-expectations (~> 3.8.0)
248
- rspec-mocks (~> 3.8.0)
249
- rspec-core (3.8.0)
250
- rspec-support (~> 3.8.0)
251
- rspec-expectations (3.8.2)
252
- diff-lcs (>= 1.2.0, < 2.0)
253
- rspec-support (~> 3.8.0)
254
- rspec-mocks (3.8.0)
255
- diff-lcs (>= 1.2.0, < 2.0)
256
- rspec-support (~> 3.8.0)
257
- rspec-support (3.8.0)
258
- rubocop (0.51.0)
259
- parallel (~> 1.10)
260
- parser (>= 2.3.3.1, < 3.0)
261
- powerpack (~> 0.1)
262
- rainbow (>= 2.2.2, < 3.0)
263
- ruby-progressbar (~> 1.7)
264
- unicode-display_width (~> 1.0, >= 1.0.1)
265
- ruby-grape-danger (0.1.1)
266
- danger (~> 4.0.1)
267
- danger-changelog (~> 0.2.0)
268
- ruby-progressbar (1.10.0)
269
- ruby_dep (1.5.0)
270
- sawyer (0.8.1)
271
- addressable (>= 2.3.5, < 2.6)
272
- faraday (~> 0.8, < 1.0)
273
- shellany (0.0.1)
274
- simplecov (0.16.1)
275
- docile (~> 1.1)
276
- json (>= 1.8, < 3)
277
- simplecov-html (~> 0.10.0)
278
- simplecov-html (0.10.2)
279
- sprockets (3.7.2)
280
- concurrent-ruby (~> 1.0)
281
- rack (> 1, < 3)
282
- sprockets-rails (3.2.1)
283
- actionpack (>= 4.0)
284
- activesupport (>= 4.0)
285
- sprockets (>= 3.0.0)
286
- term-ansicolor (1.7.0)
287
- tins (~> 1.0)
288
- terminal-table (1.8.0)
289
- unicode-display_width (~> 1.1, >= 1.1.1)
290
- thor (0.20.3)
291
- thread_safe (0.3.6)
292
- tins (1.20.2)
293
- tzinfo (1.2.5)
294
- thread_safe (~> 0.1)
295
- unf (0.1.4)
296
- unf_ext
297
- unf_ext (0.0.7.5)
298
- unicode-display_width (1.4.0)
299
- virtus (1.0.5)
300
- axiom-types (~> 0.1)
301
- coercible (~> 1.0)
302
- descendants_tracker (~> 0.0, >= 0.0.3)
303
- equalizer (~> 0.0, >= 0.0.9)
304
- websocket-driver (0.7.0)
305
- websocket-extensions (>= 0.1.0)
306
- websocket-extensions (0.1.3)
307
-
308
- PLATFORMS
309
- ruby
310
-
311
- DEPENDENCIES
312
- appraisal
313
- benchmark-ips
314
- bundler
315
- cookiejar
316
- coveralls
317
- danger-toc (~> 0.1.2)
318
- grape!
319
- grape-entity (~> 0.6)
320
- guard
321
- guard-rspec
322
- guard-rubocop
323
- hashie
324
- maruku
325
- mime-types
326
- rack-jsonp
327
- rack-test (~> 0.6.3)
328
- rails!
329
- rake
330
- rspec (~> 3.0)
331
- rubocop (= 0.51.0)
332
- ruby-grape-danger (~> 0.1.0)
333
-
334
- BUNDLED WITH
335
- 1.16.2