sinatra-param 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41745f2481953252139149d9cd960c0d0ebfe218
4
- data.tar.gz: 690bb03e1469f59231190f46b805a5bed38a0906
3
+ metadata.gz: 8ffa4f732ac04f03dc48517e868e5a867523eb75
4
+ data.tar.gz: ab474ce1e1afb21370af3434f3c00fbd24959174
5
5
  SHA512:
6
- metadata.gz: 383b1b4052465f089c1c8c3d8cb5bd6527fb364e8acec1b7ddeeedd8ac021c598a755273fca0e25f260a757844942a4239b14980db89b6c7fb027b5aeec1b844
7
- data.tar.gz: 31afa16492bd2030f635853bea4f698bfa8cc7e283c991a2f3fb5497a9bdb77ed0055e62c9aa04bbd81d0c0a967b894cb837f0fbde8a22af907aeb8c092e9917
6
+ metadata.gz: d247a854fe31d5e93f1dbb34bdbe645c89206019ee4d5af6f15d89c1455d65867f17a40fd3f7379ad00b2912a66aa1bc8e7a4216295c58f74943e48911e6bb4b
7
+ data.tar.gz: 0fdca5b6ebd84db55cd933d77826232ba458e560b2caa5e971ba075eeeb00ffff3304c3c3c0c908dca3caf1ae2b137b8bd0a426f1625b650664219d367ed962d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-param (1.3.0)
4
+ sinatra-param (1.3.1)
5
5
  sinatra (~> 1.3)
6
6
 
7
7
  GEM
data/Rakefile CHANGED
@@ -8,3 +8,11 @@ task :build => "#{gemspec.full_name}.gem"
8
8
  file "#{gemspec.full_name}.gem" => gemspec.files + ["sinatra-param.gemspec"] do
9
9
  system "gem build sinatra-param.gemspec"
10
10
  end
11
+
12
+ begin
13
+ require 'rspec/core/rake_task'
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ task :default => :spec
17
+ rescue LoadError
18
+ end
@@ -14,7 +14,7 @@
14
14
  <img src="./assets/0.7.1/loading.gif" alt="loading"/>
15
15
  </div>
16
16
  <div id="wrapper" style="display:none;">
17
- <div class="timestamp">Generated <abbr class="timeago" title="2015-01-20T09:50:50-08:00">2015-01-20T09:50:50-08:00</abbr></div>
17
+ <div class="timestamp">Generated <abbr class="timeago" title="2015-01-22T07:13:54-08:00">2015-01-22T07:13:54-08:00</abbr></div>
18
18
  <ul class="group_tabs"></ul>
19
19
 
20
20
  <div id="content">
@@ -25,7 +25,7 @@
25
25
  covered at
26
26
  <span class="covered_strength">
27
27
  <span class="green">
28
- 19.8
28
+ 22.3
29
29
  </span>
30
30
  </span> hits/line)
31
31
  </h2>
@@ -57,7 +57,7 @@
57
57
  <td>80</td>
58
58
  <td>80</td>
59
59
  <td>0</td>
60
- <td>19.8</td>
60
+ <td>22.3</td>
61
61
  </tr>
62
62
 
63
63
  </tbody>
@@ -174,8 +174,8 @@
174
174
  <code class="ruby"> def param(name, type, options = {})</code>
175
175
  </li>
176
176
 
177
- <li class="covered" data-hits="96" data-linenumber="15">
178
- <span class="hits">96</span>
177
+ <li class="covered" data-hits="123" data-linenumber="15">
178
+ <span class="hits">123</span>
179
179
 
180
180
  <code class="ruby"> name = name.to_s</code>
181
181
  </li>
@@ -186,8 +186,8 @@
186
186
  <code class="ruby"></code>
187
187
  </li>
188
188
 
189
- <li class="covered" data-hits="96" data-linenumber="17">
190
- <span class="hits">96</span>
189
+ <li class="covered" data-hits="123" data-linenumber="17">
190
+ <span class="hits">123</span>
191
191
 
192
192
  <code class="ruby"> return unless params.member?(name) or options[:default] or options[:required]</code>
193
193
  </li>
@@ -198,32 +198,32 @@
198
198
  <code class="ruby"></code>
199
199
  </li>
200
200
 
201
- <li class="covered" data-hits="84" data-linenumber="19">
202
- <span class="hits">84</span>
201
+ <li class="covered" data-hits="92" data-linenumber="19">
202
+ <span class="hits">92</span>
203
203
 
204
204
  <code class="ruby"> begin</code>
205
205
  </li>
206
206
 
207
- <li class="covered" data-hits="84" data-linenumber="20">
208
- <span class="hits">84</span>
207
+ <li class="covered" data-hits="92" data-linenumber="20">
208
+ <span class="hits">92</span>
209
209
 
210
210
  <code class="ruby"> params[name] = coerce(params[name], type, options)</code>
211
211
  </li>
212
212
 
213
- <li class="covered" data-hits="79" data-linenumber="21">
214
- <span class="hits">79</span>
213
+ <li class="covered" data-hits="87" data-linenumber="21">
214
+ <span class="hits">87</span>
215
215
 
216
216
  <code class="ruby"> params[name] = (options[:default].call if options[:default].respond_to?(:call)) || options[:default] if params[name].nil? and options[:default]</code>
217
217
  </li>
218
218
 
219
- <li class="covered" data-hits="79" data-linenumber="22">
220
- <span class="hits">79</span>
219
+ <li class="covered" data-hits="87" data-linenumber="22">
220
+ <span class="hits">87</span>
221
221
 
222
222
  <code class="ruby"> params[name] = options[:transform].to_proc.call(params[name]) if params[name] and options[:transform]</code>
223
223
  </li>
224
224
 
225
- <li class="covered" data-hits="79" data-linenumber="23">
226
- <span class="hits">79</span>
225
+ <li class="covered" data-hits="87" data-linenumber="23">
226
+ <span class="hits">87</span>
227
227
 
228
228
  <code class="ruby"> validate!(params[name], options)</code>
229
229
  </li>
@@ -324,14 +324,14 @@
324
324
  <code class="ruby"> def one_of(*args)</code>
325
325
  </li>
326
326
 
327
- <li class="covered" data-hits="8" data-linenumber="40">
328
- <span class="hits">8</span>
327
+ <li class="covered" data-hits="17" data-linenumber="40">
328
+ <span class="hits">17</span>
329
329
 
330
330
  <code class="ruby"> options = args.last.is_a?(Hash) ? args.pop : {}</code>
331
331
  </li>
332
332
 
333
- <li class="covered" data-hits="8" data-linenumber="41">
334
- <span class="hits">8</span>
333
+ <li class="covered" data-hits="17" data-linenumber="41">
334
+ <span class="hits">17</span>
335
335
 
336
336
  <code class="ruby"> names = args.collect(&amp;:to_s)</code>
337
337
  </li>
@@ -342,10 +342,10 @@
342
342
  <code class="ruby"></code>
343
343
  </li>
344
344
 
345
- <li class="covered" data-hits="8" data-linenumber="43">
346
- <span class="hits">8</span>
345
+ <li class="covered" data-hits="17" data-linenumber="43">
346
+ <span class="hits">17</span>
347
347
 
348
- <code class="ruby"> return unless names.length &gt; 2</code>
348
+ <code class="ruby"> return unless names.length &gt;= 2</code>
349
349
  </li>
350
350
 
351
351
  <li class="never" data-hits="" data-linenumber="44">
@@ -354,26 +354,26 @@
354
354
  <code class="ruby"></code>
355
355
  </li>
356
356
 
357
- <li class="covered" data-hits="8" data-linenumber="45">
358
- <span class="hits">8</span>
357
+ <li class="covered" data-hits="13" data-linenumber="45">
358
+ <span class="hits">13</span>
359
359
 
360
360
  <code class="ruby"> begin</code>
361
361
  </li>
362
362
 
363
- <li class="covered" data-hits="8" data-linenumber="46">
364
- <span class="hits">8</span>
363
+ <li class="covered" data-hits="13" data-linenumber="46">
364
+ <span class="hits">13</span>
365
365
 
366
366
  <code class="ruby"> validate_one_of!(params, names, options)</code>
367
367
  </li>
368
368
 
369
- <li class="covered" data-hits="4" data-linenumber="47">
370
- <span class="hits">4</span>
369
+ <li class="covered" data-hits="5" data-linenumber="47">
370
+ <span class="hits">5</span>
371
371
 
372
372
  <code class="ruby"> rescue InvalidParameterError =&gt; exception</code>
373
373
  </li>
374
374
 
375
- <li class="covered" data-hits="4" data-linenumber="48">
376
- <span class="hits">4</span>
375
+ <li class="covered" data-hits="5" data-linenumber="48">
376
+ <span class="hits">5</span>
377
377
 
378
378
  <code class="ruby"> if options[:raise] or (settings.raise_sinatra_param_exceptions rescue false)</code>
379
379
  </li>
@@ -402,20 +402,20 @@
402
402
  <code class="ruby"></code>
403
403
  </li>
404
404
 
405
- <li class="covered" data-hits="3" data-linenumber="53">
406
- <span class="hits">3</span>
405
+ <li class="covered" data-hits="4" data-linenumber="53">
406
+ <span class="hits">4</span>
407
407
 
408
408
  <code class="ruby"> error = &quot;Parameters #{names.join(&#39;, &#39;)} are mutually exclusive&quot;</code>
409
409
  </li>
410
410
 
411
- <li class="covered" data-hits="3" data-linenumber="54">
412
- <span class="hits">3</span>
411
+ <li class="covered" data-hits="4" data-linenumber="54">
412
+ <span class="hits">4</span>
413
413
 
414
414
  <code class="ruby"> if content_type and content_type.match(mime_type(:json))</code>
415
415
  </li>
416
416
 
417
- <li class="covered" data-hits="3" data-linenumber="55">
418
- <span class="hits">3</span>
417
+ <li class="covered" data-hits="4" data-linenumber="55">
418
+ <span class="hits">4</span>
419
419
 
420
420
  <code class="ruby"> error = {message: error, errors: {names =&gt; exception.message}}.to_json</code>
421
421
  </li>
@@ -432,8 +432,8 @@
432
432
  <code class="ruby"></code>
433
433
  </li>
434
434
 
435
- <li class="covered" data-hits="3" data-linenumber="58">
436
- <span class="hits">3</span>
435
+ <li class="covered" data-hits="4" data-linenumber="58">
436
+ <span class="hits">4</span>
437
437
 
438
438
  <code class="ruby"> halt 400, error</code>
439
439
  </li>
@@ -474,20 +474,20 @@
474
474
  <code class="ruby"> def coerce(param, type, options = {})</code>
475
475
  </li>
476
476
 
477
- <li class="covered" data-hits="84" data-linenumber="65">
478
- <span class="hits">84</span>
477
+ <li class="covered" data-hits="92" data-linenumber="65">
478
+ <span class="hits">92</span>
479
479
 
480
480
  <code class="ruby"> begin</code>
481
481
  </li>
482
482
 
483
- <li class="covered" data-hits="84" data-linenumber="66">
484
- <span class="hits">84</span>
483
+ <li class="covered" data-hits="92" data-linenumber="66">
484
+ <span class="hits">92</span>
485
485
 
486
486
  <code class="ruby"> return nil if param.nil?</code>
487
487
  </li>
488
488
 
489
- <li class="covered" data-hits="77" data-linenumber="67">
490
- <span class="hits">77</span>
489
+ <li class="covered" data-hits="85" data-linenumber="67">
490
+ <span class="hits">85</span>
491
491
 
492
492
  <code class="ruby"> return param if (param.is_a?(type) rescue false)</code>
493
493
  </li>
@@ -588,8 +588,8 @@
588
588
  <code class="ruby"> def validate!(param, options)</code>
589
589
  </li>
590
590
 
591
- <li class="covered" data-hits="79" data-linenumber="84">
592
- <span class="hits">79</span>
591
+ <li class="covered" data-hits="87" data-linenumber="84">
592
+ <span class="hits">87</span>
593
593
 
594
594
  <code class="ruby"> options.each do |key, value|</code>
595
595
  </li>
@@ -816,8 +816,8 @@
816
816
  <code class="ruby"> def validate_one_of!(params, names, options)</code>
817
817
  </li>
818
818
 
819
- <li class="covered" data-hits="32" data-linenumber="122">
820
- <span class="hits">32</span>
819
+ <li class="covered" data-hits="47" data-linenumber="122">
820
+ <span class="hits">47</span>
821
821
 
822
822
  <code class="ruby"> raise InvalidParameterError, &quot;Parameters #{names.join(&#39;, &#39;)} are mutually exclusive&quot; if names.count{|name| present?(params[name])} &gt; 1</code>
823
823
  </li>
@@ -846,8 +846,8 @@
846
846
  <code class="ruby"> def present?(object)</code>
847
847
  </li>
848
848
 
849
- <li class="covered" data-hits="24" data-linenumber="127">
850
- <span class="hits">24</span>
849
+ <li class="covered" data-hits="34" data-linenumber="127">
850
+ <span class="hits">34</span>
851
851
 
852
852
  <code class="ruby"> !blank?(object)</code>
853
853
  </li>
@@ -870,8 +870,8 @@
870
870
  <code class="ruby"> def blank?(object)</code>
871
871
  </li>
872
872
 
873
- <li class="covered" data-hits="24" data-linenumber="131">
874
- <span class="hits">24</span>
873
+ <li class="covered" data-hits="34" data-linenumber="131">
874
+ <span class="hits">34</span>
875
875
 
876
876
  <code class="ruby"> object.respond_to?(:empty?) ? object.empty? : !object</code>
877
877
  </li>
@@ -40,7 +40,7 @@ module Sinatra
40
40
  options = args.last.is_a?(Hash) ? args.pop : {}
41
41
  names = args.collect(&:to_s)
42
42
 
43
- return unless names.length > 2
43
+ return unless names.length >= 2
44
44
 
45
45
  begin
46
46
  validate_one_of!(params, names, options)
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Param
3
- VERSION = '1.3.0'
3
+ VERSION = '1.3.1'
4
4
  end
5
5
  end
Binary file
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.summary = "Parameter Validation & Type Coercion for Sinatra."
13
13
  s.description = "sinatra-param allows you to declare, validate, and transform endpoint parameters as you would in frameworks like ActiveModel or DataMapper."
14
14
 
15
- s.add_dependency "sinatra", "~> 1.3"
15
+ s.add_dependency "sinatra", "~> 1.3"
16
16
 
17
17
  s.add_development_dependency "rake"
18
18
  s.add_development_dependency "rspec"
@@ -185,7 +185,31 @@ class App < Sinatra::Base
185
185
  params.to_json
186
186
  end
187
187
 
188
- get '/choice' do
188
+ get '/choice/1' do
189
+ param :a, String
190
+ param :b, String
191
+ param :c, String
192
+
193
+ one_of :a
194
+
195
+ {
196
+ message: 'OK'
197
+ }.to_json
198
+ end
199
+
200
+ get '/choice/2' do
201
+ param :a, String
202
+ param :b, String
203
+ param :c, String
204
+
205
+ one_of :a, :b
206
+
207
+ {
208
+ message: 'OK'
209
+ }.to_json
210
+ end
211
+
212
+ get '/choice/3' do
189
213
  param :a, String
190
214
  param :b, String
191
215
  param :c, String
@@ -202,7 +226,7 @@ class App < Sinatra::Base
202
226
  params.to_json
203
227
  end
204
228
 
205
- get '/raise/choice' do
229
+ get '/raise/choice/3' do
206
230
  param :a, String
207
231
  param :b, String
208
232
  param :c, String
@@ -10,13 +10,22 @@ describe 'Parameter Sets' do
10
10
  ]
11
11
 
12
12
  params.each do |param|
13
- get('/choice', param) do |response|
13
+ get('/choice/3', param) do |response|
14
14
  expect(response.status).to eql 400
15
15
  expect(JSON.parse(response.body)['message']).to match(/mutually exclusive/)
16
16
  end
17
17
  end
18
18
  end
19
19
 
20
+ it 'returns 400 on requests that contain more than one mutually exclusive parameter' do
21
+ params = {a: 1, b: 2}
22
+
23
+ get('/choice/2', params) do |response|
24
+ expect(response.status).to eql 400
25
+ expect(JSON.parse(response.body)['message']).to match(/mutually exclusive/)
26
+ end
27
+ end
28
+
20
29
  it 'returns successfully for requests that have one parameter' do
21
30
  params = [
22
31
  {a: 1},
@@ -24,18 +33,22 @@ describe 'Parameter Sets' do
24
33
  {c: 3}
25
34
  ]
26
35
 
27
- params.each do |param|
28
- get('/choice', param) do |response|
29
- expect(response.status).to eql 200
30
- expect(JSON.parse(response.body)['message']).to match(/OK/)
36
+ (1..3).each do |n|
37
+ params.each do |param|
38
+ get("/choice/#{n}", param) do |response|
39
+ expect(response.status).to eql 200
40
+ expect(JSON.parse(response.body)['message']).to match(/OK/)
41
+ end
31
42
  end
32
43
  end
33
44
  end
34
45
 
35
46
  it 'returns successfully for requests that have no parameter' do
36
- get('/choice') do |response|
37
- expect(response.status).to eql 200
38
- expect(JSON.parse(response.body)['message']).to match(/OK/)
47
+ (1..3).each do |n|
48
+ get("/choice/#{n}") do |response|
49
+ expect(response.status).to eql 200
50
+ expect(JSON.parse(response.body)['message']).to match(/OK/)
51
+ end
39
52
  end
40
53
  end
41
54
  end
@@ -12,7 +12,7 @@ describe 'Exception' do
12
12
  it 'should raise error when more than one parameter is specified' do
13
13
  params = {a: 1, b: 2, c: 3}
14
14
  expect {
15
- get('/raise/choice', params)
15
+ get('/raise/choice/3', params)
16
16
  }.to raise_error
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-param
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattt Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -140,6 +140,7 @@ files:
140
140
  - ./LICENSE
141
141
  - ./Rakefile
142
142
  - ./README.md
143
+ - ./sinatra-param-1.3.0.gem
143
144
  - ./sinatra-param.gemspec
144
145
  - spec/dummy/app.rb
145
146
  - spec/parameter_exclusivity_spec.rb