sinatra-param 1.1.1 → 1.1.2

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: 02fe2998b85c6052f32119c3e1e72e760e0bf538
4
- data.tar.gz: 313e3983abc73ddf696f75f3a566fdaf5a1b6680
3
+ metadata.gz: ed6bc853522acf081f09e12f5c27bdaba38100c9
4
+ data.tar.gz: 319a7c7ef04009d6f709a9faf9209623d831f93f
5
5
  SHA512:
6
- metadata.gz: 008d02adbb3f7aaeaea103da5ee486f72ac56fe05054dc713f74a5ed9e6ccdc82d5198c16c8c0803c93efadcbba5a779fcb30aee100614d9d88c22ae9c63907a
7
- data.tar.gz: c980ebcc718992765de9a4b847c5ce90878ecc8854a6035ad6a9e036ad1452b2eca295f4f89116cc9e571f717fa0fc19ddbd25c9cda690a55bedc651349d5075
6
+ metadata.gz: 13ba305e660dec0f8173b474a1ae79e19d570fe977594d91878dacdccb003a636d39abe641aa4911c860fad866908af5cada37bad9da0ce8083dbd8ad858ab88
7
+ data.tar.gz: 6dc4d1d351e0261bacd12d2dc5873b82b04f105d3c2e25a64d280c6fb932da41c131bb9ccece3c0cd218caddaa4a1329051c292d7d3bbf2b9ae8c9dbcd93d1e9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-param (1.1.1)
4
+ sinatra-param (1.1.2)
5
5
  sinatra (~> 1.3)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Param
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.2'
4
4
  end
5
5
  end
data/lib/sinatra/param.rb CHANGED
@@ -56,18 +56,22 @@ module Sinatra
56
56
  private
57
57
 
58
58
  def coerce(param, type, options = {})
59
- return nil if param.nil?
60
- return param if (param.is_a?(type) rescue false)
61
- return Integer(param) if type == Integer
62
- return Float(param) if type == Float
63
- return String(param) if type == String
64
- return Time.parse(param) if type == Time
65
- return Date.parse(param) if type == Date
66
- return DateTime.parse(param) if type == DateTime
67
- return Array(param.split(options[:delimiter] || ",")) if type == Array
68
- return Hash[param.split(options[:delimiter] || ",").map{|c| c.split(options[:separator] || ":")}] if type == Hash
69
- return (/(false|f|no|n|0)$/i === param.to_s ? false : (/(true|t|yes|y|1)$/i === param.to_s ? true : nil)) if type == TrueClass || type == FalseClass || type == Boolean
70
- return nil
59
+ begin
60
+ return nil if param.nil?
61
+ return param if (param.is_a?(type) rescue false)
62
+ return Integer(param) if type == Integer
63
+ return Float(param) if type == Float
64
+ return String(param) if type == String
65
+ return Time.parse(param) if type == Time
66
+ return Date.parse(param) if type == Date
67
+ return DateTime.parse(param) if type == DateTime
68
+ return Array(param.split(options[:delimiter] || ",")) if type == Array
69
+ return Hash[param.split(options[:delimiter] || ",").map{|c| c.split(options[:separator] || ":")}] if type == Hash
70
+ return (/(false|f|no|n|0)$/i === param.to_s ? false : (/(true|t|yes|y|1)$/i === param.to_s ? true : nil)) if type == TrueClass || type == FalseClass || type == Boolean
71
+ return nil
72
+ rescue ArgumentError
73
+ raise InvalidParameterError, "'#{param}' is not a valid #{type}"
74
+ end
71
75
  end
72
76
 
73
77
  def validate!(param, options)
Binary file
@@ -17,6 +17,13 @@ describe 'Parameter Types' do
17
17
  JSON.parse(response.body)['arg'].should eq(1234)
18
18
  end
19
19
  end
20
+
21
+ it 'returns 400 on requests when integer is invalid' do
22
+ get('/coerce/integer', arg: '123abc') do |response|
23
+ response.status.should == 400
24
+ JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
25
+ end
26
+ end
20
27
  end
21
28
 
22
29
  describe 'Float' do
@@ -26,6 +33,13 @@ describe 'Parameter Types' do
26
33
  JSON.parse(response.body)['arg'].should eq(1234.0)
27
34
  end
28
35
  end
36
+
37
+ it 'returns 400 on requests when float is invalid' do
38
+ get('/coerce/float', arg: '123abc') do |response|
39
+ response.status.should == 400
40
+ JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
41
+ end
42
+ end
29
43
  end
30
44
 
31
45
  describe 'Time' do
@@ -35,6 +49,13 @@ describe 'Parameter Types' do
35
49
  JSON.parse(response.body)['arg'].should match(/2013-01-17 00:00:00/)
36
50
  end
37
51
  end
52
+
53
+ it 'returns 400 on requests when time is invalid' do
54
+ get('/coerce/time', arg: '123abc') do |response|
55
+ response.status.should == 400
56
+ JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
57
+ end
58
+ end
38
59
  end
39
60
 
40
61
  describe 'Date' do
@@ -44,6 +65,13 @@ describe 'Parameter Types' do
44
65
  JSON.parse(response.body)['arg'].should eq('2013-01-17')
45
66
  end
46
67
  end
68
+
69
+ it 'returns 400 on requests when date is invalid' do
70
+ get('/coerce/date', arg: 'abc') do |response|
71
+ response.status.should == 400
72
+ JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
73
+ end
74
+ end
47
75
  end
48
76
 
49
77
  describe 'DateTime' do
@@ -53,6 +81,13 @@ describe 'Parameter Types' do
53
81
  JSON.parse(response.body)['arg'].should eq('2013-01-17T00:00:00+00:00')
54
82
  end
55
83
  end
84
+
85
+ it 'returns 400 on requests when datetime is invalid' do
86
+ get('/coerce/datetime', arg: 'abc') do |response|
87
+ response.status.should == 400
88
+ JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
89
+ end
90
+ end
56
91
  end
57
92
 
58
93
  describe 'Array' do
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.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattt Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -141,6 +141,7 @@ files:
141
141
  - ./Rakefile
142
142
  - ./README.md
143
143
  - ./sinatra-param-1.1.0.gem
144
+ - ./sinatra-param-1.1.1.gem
144
145
  - ./sinatra-param.gemspec
145
146
  - spec/dummy/app.rb
146
147
  - spec/parameter_sets_spec.rb