sinatra-param 1.0.2 → 1.0.3
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/Gemfile.lock +1 -1
- data/coverage/index.html +475 -491
- data/lib/sinatra/param.rb +2 -1
- data/lib/sinatra/param/version.rb +1 -1
- data/spec/dummy/app.rb +10 -2
- data/spec/parameter_type_coercion_spec.rb +29 -0
- metadata +2 -4
- data/sinatra-param-1.0.0.gem +0 -0
- data/sinatra-param-1.0.1.gem +0 -0
data/lib/sinatra/param.rb
CHANGED
@@ -15,7 +15,8 @@ module Sinatra
|
|
15
15
|
return unless params.member?(name) or present?(options[:default]) or options[:required]
|
16
16
|
|
17
17
|
begin
|
18
|
-
params[name] = coerce(params[name], type, options)
|
18
|
+
params[name] = coerce(params[name], type, options)
|
19
|
+
params[name] = options[:default] if params[name].nil? and options[:default]
|
19
20
|
params[name] = options[:transform].to_proc.call(params[name]) if options[:transform]
|
20
21
|
validate!(params[name], options)
|
21
22
|
rescue
|
data/spec/dummy/app.rb
CHANGED
@@ -71,18 +71,26 @@ class App < Sinatra::Base
|
|
71
71
|
params.to_json
|
72
72
|
end
|
73
73
|
|
74
|
-
# transformations
|
75
74
|
get '/default' do
|
76
75
|
param :sort, String, default: "title"
|
77
76
|
params.to_json
|
78
77
|
end
|
79
78
|
|
79
|
+
get '/default/boolean/true' do
|
80
|
+
param :arg, Boolean, default: true
|
81
|
+
params.to_json
|
82
|
+
end
|
83
|
+
|
84
|
+
get '/default/boolean/false' do
|
85
|
+
param :arg, Boolean, default: false
|
86
|
+
params.to_json
|
87
|
+
end
|
88
|
+
|
80
89
|
get '/transform' do
|
81
90
|
param :order, String, transform: :upcase
|
82
91
|
params.to_json
|
83
92
|
end
|
84
93
|
|
85
|
-
# validations
|
86
94
|
get '/validation/required' do
|
87
95
|
param :arg, String, required: true
|
88
96
|
params.to_json
|
@@ -86,5 +86,34 @@ describe 'Parameter Types' do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
89
|
+
|
90
|
+
it 'coerces falsey booleans to false' do
|
91
|
+
%w(0 false f no n).each do |bool|
|
92
|
+
get('/coerce/boolean', arg: bool) do |response|
|
93
|
+
response.status.should == 200
|
94
|
+
JSON.parse(response.body)['arg'].should be_false
|
95
|
+
JSON.parse(response.body)['arg'].should_not be_nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'coerces truthy booleans to true when default is false' do
|
101
|
+
%w(1 true t yes y).each do |bool|
|
102
|
+
get('/default/boolean/false', arg: bool) do |response|
|
103
|
+
response.status.should == 200
|
104
|
+
JSON.parse(response.body)['arg'].should be_true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'coerces falsey booleans to false when default is true' do
|
110
|
+
%w(0 false f no n).each do |bool|
|
111
|
+
get('/default/boolean/true', arg: bool) do |response|
|
112
|
+
response.status.should == 200
|
113
|
+
JSON.parse(response.body)['arg'].should be_false
|
114
|
+
JSON.parse(response.body)['arg'].should_not be_nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
89
118
|
end
|
90
119
|
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.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattt Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -140,8 +140,6 @@ files:
|
|
140
140
|
- ./LICENSE
|
141
141
|
- ./Rakefile
|
142
142
|
- ./README.md
|
143
|
-
- ./sinatra-param-1.0.0.gem
|
144
|
-
- ./sinatra-param-1.0.1.gem
|
145
143
|
- ./sinatra-param.gemspec
|
146
144
|
- spec/dummy/app.rb
|
147
145
|
- spec/parameter_sets_spec.rb
|
data/sinatra-param-1.0.0.gem
DELETED
Binary file
|
data/sinatra-param-1.0.1.gem
DELETED
Binary file
|